1; Functions names start with `Test`
  2(
  3  (
  4    (function_declaration name: (_) @run
  5      (#match? @run "^Test.*"))
  6  ) @_
  7  (#set! tag go-test)
  8)
  9
 10; Suite test methods (testify/suite)
 11(
 12    (method_declaration
 13      receiver: (parameter_list
 14        (parameter_declaration
 15            type: [
 16                (pointer_type (type_identifier) @_suite_name)
 17                (type_identifier) @_suite_name
 18            ]
 19        )
 20      )
 21      name: (field_identifier) @run @_subtest_name
 22      (#match? @_subtest_name "^Test.*")
 23      (#match? @_suite_name ".*Suite")
 24    ) @_
 25    (#set! tag go-testify-suite)
 26)
 27
 28; `go:generate` comments
 29(
 30    ((comment) @_comment @run
 31    (#match? @_comment "^//go:generate"))
 32    (#set! tag go-generate)
 33)
 34
 35; `t.Run`
 36(
 37  (
 38    (call_expression
 39      function: (
 40        selector_expression
 41        field: _ @run @_name
 42        (#eq? @_name "Run")
 43      )
 44      arguments: (
 45        argument_list
 46        .
 47        [
 48          (interpreted_string_literal)
 49          (raw_string_literal)
 50        ] @_subtest_name
 51        .
 52        (func_literal
 53          parameters: (
 54            parameter_list
 55            (parameter_declaration
 56              name: (identifier) @_param_name
 57              type: (pointer_type
 58                (qualified_type
 59                  package: (package_identifier) @_pkg
 60                  name: (type_identifier) @_type
 61                  (#eq? @_pkg "testing")
 62                  (#eq? @_type "T")
 63                )
 64              )
 65            )
 66          )
 67        ) @_second_argument
 68      )
 69    )
 70  ) @_
 71  (#set! tag go-subtest)
 72)
 73
 74; Functions names start with `Example`
 75(
 76  (
 77    (function_declaration name: (_) @run @_name
 78      (#match? @_name "^Example.*"))
 79  ) @_
 80  (#set! tag go-example)
 81)
 82
 83; Functions names start with `Benchmark`
 84(
 85  (
 86    (function_declaration name: (_) @run @_name
 87      (#match? @_name "^Benchmark.*"))
 88  ) @_
 89  (#set! tag go-benchmark)
 90)
 91
 92; Functions names start with `Fuzz`
 93(
 94  (
 95    (function_declaration name: (_) @run @_name
 96      (#match? @_name "^Fuzz"))
 97  ) @_
 98  (#set! tag go-fuzz)
 99)
100
101; go run
102(
103  (
104    (function_declaration name: (_) @run
105      (#eq? @run "main"))
106  ) @_
107  (#set! tag go-main)
108)
109
110; Table test cases - slice and map
111(
112  (short_var_declaration
113    left: (expression_list (identifier) @_collection_var)
114    right: (expression_list
115      (composite_literal
116        type: [
117          (slice_type)
118          (map_type
119            key: (type_identifier) @_key_type
120            (#eq? @_key_type "string")
121          )
122        ]
123        body: (literal_value
124          [
125            (literal_element
126              (literal_value
127                (keyed_element
128                  (literal_element
129                    (identifier) @_field_name
130                  )
131                  (literal_element
132                    [
133                      (interpreted_string_literal) @run @_table_test_case_name
134                      (raw_string_literal) @run @_table_test_case_name
135                    ]
136                  )
137                )
138              )
139            )
140            (keyed_element
141              (literal_element
142                [
143                  (interpreted_string_literal) @run @_table_test_case_name
144                  (raw_string_literal) @run @_table_test_case_name
145                ]
146              )
147            )
148          ]
149        )
150      )
151    )
152  )
153  (for_statement
154    (range_clause
155      left: (expression_list
156        [
157          (
158            (identifier)
159            (identifier) @_loop_var_inner
160          )
161          (identifier) @_loop_var_outer
162        ]
163      )
164      right: (identifier) @_range_var
165      (#eq? @_range_var @_collection_var)
166    )
167    body: (block
168      (expression_statement
169        (call_expression
170          function: (selector_expression
171            operand: (identifier)
172            field: (field_identifier) @_run_method
173            (#eq? @_run_method "Run")
174          )
175          arguments: (argument_list
176            .
177            [
178              (selector_expression
179                operand: (identifier) @_tc_var
180                (#eq? @_tc_var @_loop_var_inner)
181                field: (field_identifier) @_field_check
182                (#eq? @_field_check @_field_name)
183              )
184              (identifier) @_arg_var
185              (#eq? @_arg_var @_loop_var_outer)
186            ]
187            .
188            (func_literal
189              parameters: (parameter_list
190                (parameter_declaration
191                  type: (pointer_type
192                    (qualified_type
193                      package: (package_identifier) @_pkg
194                      name: (type_identifier) @_type
195                      (#eq? @_pkg "testing")
196                      (#eq? @_type "T")
197                    )
198                  )
199                )
200              )
201            )
202          )
203        )
204      )
205    )
206  ) @_
207  (#set! tag go-table-test-case)
208)