summaryrefslogtreecommitdiff
path: root/test/src/treesit-tests.el
diff options
context:
space:
mode:
authorYuan Fu <casouri@gmail.com>2022-11-11 20:04:38 -0800
committerYuan Fu <casouri@gmail.com>2022-11-11 20:04:38 -0800
commit5cd3db73bed06e394ea8e7b0e332b1b1e5bd9571 (patch)
tree959a84f4a86cc39784ab5e0964bb21b80c5a9770 /test/src/treesit-tests.el
parent4489450f37deafb013b1f0fc00c89f0973fda14a (diff)
downloademacs-5cd3db73bed06e394ea8e7b0e332b1b1e5bd9571.tar.gz
emacs-5cd3db73bed06e394ea8e7b0e332b1b1e5bd9571.tar.bz2
emacs-5cd3db73bed06e394ea8e7b0e332b1b1e5bd9571.zip
Improve treesit-node-at
* doc/lispref/parsing.texi (Retrieving Node): Update manual. * lisp/treesit.el (treesit-node-at): Change semantic. It tries to return the node that a user would expect in various circumstances. * test/src/treesit-tests.el (treesit-node-at): New test.
Diffstat (limited to 'test/src/treesit-tests.el')
-rw-r--r--test/src/treesit-tests.el31
1 files changed, 31 insertions, 0 deletions
diff --git a/test/src/treesit-tests.el b/test/src/treesit-tests.el
index 5e4aea3ad41..7fc810492bc 100644
--- a/test/src/treesit-tests.el
+++ b/test/src/treesit-tests.el
@@ -474,6 +474,37 @@ visible_end.)"
;; `treesit-search-forward-goto'
))
+(ert-deftest treesit-node-at ()
+ "Test `treesit-node-at'."
+ (skip-unless (treesit-language-available-p 'json))
+ (let (parser root-node)
+ (progn
+ (insert "[1, 2, 3,4] ")
+ (setq parser (treesit-parser-create 'json))
+ (setq root-node (treesit-parser-root-node
+ parser)))
+ ;; Point at ",", should return ",".
+ (goto-char (point-min))
+ (search-forward "1")
+ (should (equal (treesit-node-text
+ (treesit-node-at (point)))
+ ","))
+ ;; Point behind ",", should still return the ",".
+ (search-forward ",")
+ (should (equal (treesit-node-text
+ (treesit-node-at (point)))
+ ","))
+ ;; Point between "," and "2", should return 2.
+ (forward-char)
+ (should (equal (treesit-node-text
+ (treesit-node-at (point)))
+ "2"))
+ ;; EOF, should return the last leaf node "]".
+ (goto-char (point-max))
+ (should (equal (treesit-node-text
+ (treesit-node-at (point)))
+ "]"))))
+
(ert-deftest treesit-misc ()
"Misc helper functions."
(let ((settings '((t 0 t)