mirror of
git://git.sv.gnu.org/emacs.git
synced 2025-12-06 06:20:55 -08:00
Use the first parser from 'treesit-parser-list' to fix tests.
* lisp/treesit.el (treesit-parsers-at): Add treesit-primary-parser only when it's non-nil. When the result list is still empty, add the first parser from 'treesit-parser-list'. https://lists.gnu.org/archive/html/emacs-devel/2025-04/msg00627.html * test/src/treesit-tests.el (treesit-node-supplemental) (treesit-node-at, treesit-node-check) (treesit-search-subtree-forward-1) (treesit-search-subtree-backward-1): Wrap test body in 'with-temp-buffer'.
This commit is contained in:
parent
2925ff6c53
commit
ee46b6c4e6
2 changed files with 121 additions and 114 deletions
|
|
@ -873,8 +873,10 @@ If ONLY contains the symbol `primary', include the primary parser."
|
|||
(and (memq 'global only)
|
||||
(not (overlay-get ov 'treesit-parser-local-p))))))
|
||||
(push (if with-host (cons parser host-parser) parser) res)))
|
||||
(when (or (null only) (memq 'primary only))
|
||||
(setq res (cons treesit-primary-parser res)))
|
||||
(when (and treesit-primary-parser (or (null only) (memq 'primary only)))
|
||||
(push treesit-primary-parser res))
|
||||
(unless res
|
||||
(push (car (treesit-parser-list)) res))
|
||||
(seq-sort-by (lambda (p)
|
||||
(treesit-parser-embed-level
|
||||
(or (car-safe p) p)))
|
||||
|
|
|
|||
|
|
@ -835,6 +835,7 @@ visible_end.)"
|
|||
(ert-deftest treesit-node-supplemental ()
|
||||
"Supplemental node functions."
|
||||
(skip-unless (treesit-language-available-p 'json))
|
||||
(with-temp-buffer
|
||||
(let (parser root-node doc-node)
|
||||
(progn
|
||||
(insert "[1,2,{\"name\": \"Bob\"},3]")
|
||||
|
|
@ -880,11 +881,12 @@ visible_end.)"
|
|||
;; `treesit-node-children'
|
||||
;; `treesit-node-field-name'
|
||||
;; `treesit-search-forward-goto'
|
||||
))
|
||||
)))
|
||||
|
||||
(ert-deftest treesit-node-at ()
|
||||
"Test `treesit-node-at'."
|
||||
(skip-unless (treesit-language-available-p 'json))
|
||||
(with-temp-buffer
|
||||
(let (parser)
|
||||
(progn
|
||||
(insert "[1, 2, 3,4] ")
|
||||
|
|
@ -910,11 +912,12 @@ visible_end.)"
|
|||
(goto-char (point-max))
|
||||
(should (equal (treesit-node-text
|
||||
(treesit-node-at (point)))
|
||||
"]"))))
|
||||
"]")))))
|
||||
|
||||
(ert-deftest treesit-node-check ()
|
||||
"Test `treesit-node-check'."
|
||||
(skip-unless (treesit-language-available-p 'json))
|
||||
(with-temp-buffer
|
||||
(let (parser root-node array-node comment-node)
|
||||
(progn
|
||||
(insert "/* comment */ [1, 2, 3,4 ")
|
||||
|
|
@ -932,7 +935,7 @@ visible_end.)"
|
|||
(goto-char (point-max))
|
||||
(insert "]")
|
||||
(treesit-parser-root-node parser)
|
||||
(should (treesit-node-check array-node 'outdated))))
|
||||
(should (treesit-node-check array-node 'outdated)))))
|
||||
|
||||
;;; Defun navigation
|
||||
;;
|
||||
|
|
@ -1262,6 +1265,7 @@ This tests bug#60355."
|
|||
"Test search subtree forward."
|
||||
(skip-unless (treesit-language-available-p 'python))
|
||||
(require 'python)
|
||||
(with-temp-buffer
|
||||
(python-ts-mode)
|
||||
(insert "Temp(1, 2)")
|
||||
(goto-char (point-min))
|
||||
|
|
@ -1273,12 +1277,13 @@ This tests bug#60355."
|
|||
(lambda (n) (equal (treesit-node-type n) "integer")))))
|
||||
|
||||
(should node)
|
||||
(should (equal (treesit-node-text node) "1"))))
|
||||
(should (equal (treesit-node-text node) "1")))))
|
||||
|
||||
(ert-deftest treesit-search-subtree-backward-1 ()
|
||||
"Test search subtree with backward=t."
|
||||
(skip-unless (treesit-language-available-p 'python))
|
||||
(require 'python)
|
||||
(with-temp-buffer
|
||||
(python-ts-mode)
|
||||
(insert "Temp(1, 2)")
|
||||
(goto-char (point-min))
|
||||
|
|
@ -1291,7 +1296,7 @@ This tests bug#60355."
|
|||
t)))
|
||||
|
||||
(should node)
|
||||
(should (equal (treesit-node-text node) "2"))))
|
||||
(should (equal (treesit-node-text node) "2")))))
|
||||
|
||||
;;; Imenu
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue