diff options
| author | Yuan Fu | 2022-11-11 20:04:38 -0800 |
|---|---|---|
| committer | Yuan Fu | 2022-11-11 20:04:38 -0800 |
| commit | 5cd3db73bed06e394ea8e7b0e332b1b1e5bd9571 (patch) | |
| tree | 959a84f4a86cc39784ab5e0964bb21b80c5a9770 /test/src | |
| parent | 4489450f37deafb013b1f0fc00c89f0973fda14a (diff) | |
| download | emacs-5cd3db73bed06e394ea8e7b0e332b1b1e5bd9571.tar.gz 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')
| -rw-r--r-- | test/src/treesit-tests.el | 31 |
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.)" | |||
| 474 | ;; `treesit-search-forward-goto' | 474 | ;; `treesit-search-forward-goto' |
| 475 | )) | 475 | )) |
| 476 | 476 | ||
| 477 | (ert-deftest treesit-node-at () | ||
| 478 | "Test `treesit-node-at'." | ||
| 479 | (skip-unless (treesit-language-available-p 'json)) | ||
| 480 | (let (parser root-node) | ||
| 481 | (progn | ||
| 482 | (insert "[1, 2, 3,4] ") | ||
| 483 | (setq parser (treesit-parser-create 'json)) | ||
| 484 | (setq root-node (treesit-parser-root-node | ||
| 485 | parser))) | ||
| 486 | ;; Point at ",", should return ",". | ||
| 487 | (goto-char (point-min)) | ||
| 488 | (search-forward "1") | ||
| 489 | (should (equal (treesit-node-text | ||
| 490 | (treesit-node-at (point))) | ||
| 491 | ",")) | ||
| 492 | ;; Point behind ",", should still return the ",". | ||
| 493 | (search-forward ",") | ||
| 494 | (should (equal (treesit-node-text | ||
| 495 | (treesit-node-at (point))) | ||
| 496 | ",")) | ||
| 497 | ;; Point between "," and "2", should return 2. | ||
| 498 | (forward-char) | ||
| 499 | (should (equal (treesit-node-text | ||
| 500 | (treesit-node-at (point))) | ||
| 501 | "2")) | ||
| 502 | ;; EOF, should return the last leaf node "]". | ||
| 503 | (goto-char (point-max)) | ||
| 504 | (should (equal (treesit-node-text | ||
| 505 | (treesit-node-at (point))) | ||
| 506 | "]")))) | ||
| 507 | |||
| 477 | (ert-deftest treesit-misc () | 508 | (ert-deftest treesit-misc () |
| 478 | "Misc helper functions." | 509 | "Misc helper functions." |
| 479 | (let ((settings '((t 0 t) | 510 | (let ((settings '((t 0 t) |