runnables.scm

 1; Functions names start with `Test`
 2(
 3  [
 4    (function_declaration name: (_) @run
 5      (#match? @run "^Test.*"))
 6    (method_declaration
 7      receiver: (parameter_list
 8        (parameter_declaration
 9          name: (identifier) @_receiver_name
10          type: [
11            (pointer_type (type_identifier) @_receiver_type)
12            (type_identifier) @_receiver_type
13          ]
14        )
15      )
16      name: (field_identifier) @run @_method_name
17      (#match? @_method_name "^Test.*"))
18  ] @_
19  (#set! tag go-test)
20)
21
22; `go:generate` comments
23(
24    ((comment) @_comment @run
25    (#match? @_comment "^//go:generate"))
26    (#set! tag go-generate)
27)
28
29; `t.Run`
30(
31  (
32    (call_expression
33      function: (
34        selector_expression
35        field: _ @run @_name
36        (#eq? @_name "Run")
37      )
38      arguments: (
39        argument_list
40        .
41        [
42          (interpreted_string_literal)
43          (raw_string_literal)
44        ] @_subtest_name
45        .
46        (func_literal
47          parameters: (
48            parameter_list
49            (parameter_declaration
50              name: (identifier) @_param_name
51              type: (pointer_type
52                (qualified_type
53                  package: (package_identifier) @_pkg
54                  name: (type_identifier) @_type
55                  (#eq? @_pkg "testing")
56                  (#eq? @_type "T")
57                )
58              )
59            )
60          )
61        ) @_second_argument
62      )
63    )
64  ) @_
65  (#set! tag go-subtest)
66)
67
68; Functions names start with `Benchmark`
69(
70  (
71    (function_declaration name: (_) @run @_name
72      (#match? @_name "^Benchmark.*"))
73  ) @_
74  (#set! tag go-benchmark)
75)
76
77; Functions names start with `Fuzz`
78(
79  (
80    (function_declaration name: (_) @run @_name
81      (#match? @_name "^Fuzz"))
82  ) @_
83  (#set! tag go-fuzz)
84)
85
86; go run
87(
88  (
89    (function_declaration name: (_) @run
90      (#eq? @run "main"))
91  ) @_
92  (#set! tag go-main)
93)