/* First go to the last child. */
while (ts_tree_cursor_goto_next_sibling (cursor));
- if (!named)
+ if (!named || (named && ts_node_is_named (ts_tree_cursor_current_node(cursor))))
return true;
- /* Else named... */
+ /* Else named is required and last child is not named node */
if (treesit_traverse_sibling_helper(cursor, false, true))
return true;
else
treesit--ert-defun-navigation-python-program
treesit--ert-defun-navigation-top-level-master)))
+(ert-deftest treesit-search-subtree-forward-1 ()
+ "Test search subtree forward."
+ (skip-unless (treesit-language-available-p 'python))
+ (require 'python)
+ (python-ts-mode)
+ (insert "Temp(1, 2)")
+ (goto-char (point-min))
+ (let ((node (treesit-search-subtree
+ (treesit--thing-at (point) "call")
+ (lambda (n) (equal (treesit-node-type n ) "integer")))))
+
+ (should node)
+ (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)
+ (python-ts-mode)
+ (insert "Temp(1, 2)")
+ (goto-char (point-min))
+ (let ((node (treesit-search-subtree
+ (treesit--thing-at (point) "call")
+ (lambda (n) (equal (treesit-node-type n ) "integer"))
+ t)))
+
+ (should node)
+ (should (equal (treesit-node-text node) "2"))))
+
+
;; TODO
;; - Functions in treesit.el
;; - treesit-load-name-override-list