101101 (tsc-test-tree-sexp '(source_file (ERROR)))
102102 (insert " foo() {}" )
103103 (tsc-test-tree-sexp '(source_file
104- (function_item
105- name: (identifier)
106- parameters: (parameters)
107- body: (block ))))
104+ (function_item
105+ name: (identifier)
106+ parameters: (parameters)
107+ body: (block ))))
108108 (kill-region (point-min ) (point-max ))
109109 (tsc-test-tree-sexp '(source_file))))
110110
@@ -266,27 +266,46 @@ source_file (1 . 20)
266266 (tsc-test-render-node type named-p start-byte end-byte field depth)))))))))
267267
268268(ert-deftest cursor::traverse:single-property ()
269- (tsc-test-with rust parser
270- (let* ((code " fn foo(x: usize) {}" )
271- (tree (tsc-parse-string parser code)))
272- (ert-info (" " )
273- (let (mapc-result
274- do-result
275- iter-result)
276- (ert-info (" Callback-based traversal should work with single property" )
277- (tsc-traverse-mapc
278- (lambda (type )
279- (cl-callf append mapc-result (list type)))
280- tree :type ))
281- (ert-info (" Iterator-based traversal should work with single property" )
282- (setq iter-result (cl-loop for type
283- iter-by (tsc-traverse-iter tree :type )
284- collect type)))
285- (tsc-traverse-do ([type] tree)
286- (cl-callf append do-result (list type)))
287- (ert-info (" All traversal methods should return the same result" )
288- (should (equal do-result mapc-result))
289- (should (equal do-result iter-result))))))))
269+ (tsc-test-lang-with-file rust " data/types.rs"
270+ (let ((tree tree-sitter-tree)
271+ mapc-result
272+ do-result
273+ iter-result)
274+ (ert-info (" Callback-based traversal should work with single property" )
275+ (tsc-traverse-mapc
276+ (lambda (type )
277+ (push type mapc-result))
278+ tree :type ))
279+ (ert-info (" Iterator-based traversal should work with single property" )
280+ (cl-loop for type
281+ iter-by (tsc-traverse-iter tree :type )
282+ do (push type iter-result)))
283+ (tsc-traverse-do ([type] tree)
284+ (push type do-result))
285+ (ert-info (" All traversal methods should return the same result" )
286+ (should (equal do-result mapc-result))
287+ (should (equal do-result iter-result))))))
288+
289+ (ert-deftest cursor::traverse:node ()
290+ (tsc-test-lang-with-file rust " data/types.rs"
291+ (let ((tree tree-sitter-tree)
292+ mapc-result
293+ do-result
294+ iter-result)
295+ (ert-info (" Callback-based traversal should work with nodes" )
296+ (tsc-traverse-mapc
297+ (lambda (node )
298+ (push (tsc-node-type node) mapc-result))
299+ tree))
300+ (ert-info (" Iterator-based traversal should work with nodes" )
301+ (cl-loop for node
302+ iter-by (tsc-traverse-iter tree)
303+ do (push (tsc-node-type node) iter-result)))
304+ (tsc-traverse-do ([type] tree)
305+ (push type do-result))
306+ (ert-info (" All traversal methods should return the same result" )
307+ (should (equal do-result mapc-result))
308+ (should (equal do-result iter-result))))))
290309
291310(ert-deftest conversion::position<->tsc-point ()
292311 (tsc-test-with-file " tree-sitter-tests.el"
@@ -325,7 +344,7 @@ source_file (1 . 20)
325344 (ert-info (" Should work on vector" )
326345 (should (= (tsc-query-count-patterns
327346 (tsc-make-query rust [(function_item (identifier) @function)
328- (macro_definition (identifier) @macro)]))
347+ (macro_definition (identifier) @macro)]))
329348 2 )))))
330349
331350(ert-deftest query::basic ()
@@ -341,8 +360,8 @@ source_file (1 . 20)
341360 (tsc-node-text node)))
342361 captures))
343362 (capture-tags (mapcar (lambda (capture )
344- (pcase-let ((`(, tag . _) capture)) tag))
345- captures)))
363+ (pcase-let ((`(, tag . _) capture)) tag))
364+ captures)))
346365 (ert-info (" Should match specified functions and not more" )
347366 (should (member " _make_query" node-texts))
348367 (should (member " make_query_cursor" node-texts))
@@ -355,10 +374,10 @@ source_file (1 . 20)
355374 (tsc-test-lang-with-file c " data/range-restriction-and-early-termination.c"
356375 (let ((cursor (tsc-make-query-cursor))
357376 (query (tsc-make-query tree-sitter-language
358- [(call_expression
359- function: (identifier) @function
360- arguments: (argument_list (string_literal) @string.arg))
361- (string_literal) @string]))
377+ [(call_expression
378+ function: (identifier) @function
379+ arguments: (argument_list (string_literal) @string.arg))
380+ (string_literal) @string]))
362381 (root-node (tsc-root-node tree-sitter-tree))
363382 (capture-names '(function string.arg string)))
364383 (ert-info (" Querying without range restriction" )
@@ -469,13 +488,13 @@ source_file (1 . 20)
469488We know it should since it is the `source_file' node."
470489 (tsc-test-lang-with-file rust " data/types.rs"
471490 (let ((buf-name (buffer-name )))
472- (setq tree-sitter-debug-jump-buttons t )
473- (tree-sitter-debug-mode)
474- (goto-char (point-max ))
475- (should (> (point ) 0 )) ; Test if worthless if the file is empty
476- (switch-to-buffer tree-sitter-debug--tree-buffer nil t )
477- (tree-sitter-debug--button-node-lookup (button-at 1 ))
478- (should (= (point ) (point-min ))))))
491+ (setq tree-sitter-debug-jump-buttons t )
492+ (tree-sitter-debug-mode)
493+ (goto-char (point-max ))
494+ (should (> (point ) 0 )) ; Test if worthless if the file is empty
495+ (switch-to-buffer tree-sitter-debug--tree-buffer nil t )
496+ (tree-sitter-debug--button-node-lookup (button-at 1 ))
497+ (should (= (point ) (point-min ))))))
479498
480499; ; Local Variables:
481500; ; no-byte-compile: t
0 commit comments