1; Rust mod test
2(
3 (attribute_item (attribute
4 (
5 (identifier) @_attribute)
6 arguments: (
7 (token_tree (identifier) @_test)
8 (#eq? @_test "test")
9 )
10 )
11 (#eq? @_attribute "cfg")
12 )
13 .
14 (mod_item
15 name: (_) @run
16 )
17 (#set! tag rust-mod-test)
18)
19
20; Rust test
21(
22 (
23 (attribute_item (attribute
24 [((identifier) @_attribute)
25 (scoped_identifier (identifier) @_attribute)
26 ])
27 (#match? @_attribute "test")
28 ) @_start
29 .
30 (attribute_item) *
31 .
32 [(line_comment) (block_comment)] *
33 .
34 (function_item
35 name: (_) @run @_test_name
36 body: _
37 ) @_end
38 )
39 (#set! tag rust-test)
40)
41
42; Rust doc test
43(
44 (
45 (line_comment) *
46 (line_comment
47 doc: (_) @_comment_content
48 ) @_start @run
49 (#match? @_comment_content "```")
50 .
51 (line_comment) *
52 .
53 (line_comment
54 doc: (_) @_end_comment_content
55 ) @_end_code_block
56 (#match? @_end_comment_content "```")
57 .
58 (line_comment) *
59 (attribute_item) *
60 .
61 [(function_item
62 name: (_) @_doc_test_name
63 body: _
64 ) (function_signature_item
65 name: (_) @_doc_test_name
66 ) (struct_item
67 name: (_) @_doc_test_name
68 ) (enum_item
69 name: (_) @_doc_test_name
70 body: _
71 ) (
72 (attribute_item) ?
73 (macro_definition
74 name: (_) @_doc_test_name)
75 ) (mod_item
76 name: (_) @_doc_test_name
77 )] @_end
78 )
79 (#set! tag rust-doc-test)
80)
81
82; Rust main function
83(
84 (
85 (function_item
86 name: (_) @run
87 body: _
88 ) @_rust_main_function_end
89 (#eq? @run "main")
90 )
91 (#set! tag rust-main)
92)