Created
December 17, 2022 14:01
-
-
Save sergii4/7b3207a73ebd6fdef9d4797cb0201be3 to your computer and use it in GitHub Desktop.
Golang test tree-sitter query
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"net/http" | |
"testing" | |
) | |
func TestSomeTest(t *testing.T) { | |
tt := []struct { | |
name string | |
method string | |
url string | |
apiKey string | |
status int | |
}{ | |
{name: "1", method: http.MethodGet, url: "/api/nothing", apiKey: "lalala", status: http.StatusForbidden}, | |
{name: "2", method: http.MethodGet, url: "/api/nothing", apiKey: "lalala", status: http.StatusForbidden}, | |
{name: "3", method: http.MethodGet, url: "/api/nothing", apiKey: "lalala", status: http.StatusForbidden}, | |
{name: "4", method: http.MethodGet, url: "/api/nothing", apiKey: "lalala", status: http.StatusForbidden}, | |
{name: "5", method: http.MethodGet, url: "/api/nothing", apiKey: "lalala", status: http.StatusForbidden}, | |
{name: "6", method: http.MethodGet, url: "/api/nothing", apiKey: "lalala", status: http.StatusForbidden}, | |
{name: "7", method: http.MethodGet, url: "/api/nothing", apiKey: "lalala", status: http.StatusForbidden}, | |
{name: "8", method: http.MethodGet, url: "/api/nothing", apiKey: "lalala", status: http.StatusForbidden}, | |
{name: "9", method: http.MethodGet, url: "/api/nothing", apiKey: "lalala", status: http.StatusForbidden}, | |
{name: "10", method: http.MethodGet, url: "/api/nothing", apiKey: "lalala", status: http.StatusForbidden}, | |
{name: "11", method: http.MethodGet, url: "/api/nothing", apiKey: "lalala", status: http.StatusForbidden}, | |
{name: "12", method: http.MethodGet, url: "/api/nothing", apiKey: "lalala", status: http.StatusForbidden}, | |
{name: "13", method: http.MethodGet, url: "/api/nothing", apiKey: "lalala", status: http.StatusForbidden}, | |
{name: "14", method: http.MethodGet, url: "/api/nothing", apiKey: "lalala", status: http.StatusForbidden}, | |
{name: "15", method: http.MethodGet, url: "/api/nothing", apiKey: "lalala", status: http.StatusForbidden}, | |
{name: "16", method: http.MethodGet, url: "/api/nothing", apiKey: "lalala", status: http.StatusForbidden}, | |
{name: "17", method: http.MethodGet, url: "/api/nothing", apiKey: "lalala", status: http.StatusForbidden}, | |
{name: "18", method: http.MethodGet, url: "/api/nothing", apiKey: "lalala", status: http.StatusForbidden}, | |
{name: "19", method: http.MethodGet, url: "/api/nothing", apiKey: "lalala", status: http.StatusForbidden}, | |
{name: "20", method: http.MethodGet, url: "/api/nothing", apiKey: "lalala", status: http.StatusForbidden}, | |
} | |
for _, tc := range tt { | |
tc := tc | |
t.Run(tc.name, func(_ *testing.T) { | |
fmt.Println(tc.name, tc.method, tc.url, tc.apiKey, tc.status) | |
}) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;query | |
((function_declaration | |
name: (identifier) @test.name) | |
(#match? @test.name "^(Test|Example)")) | |
@test.definition | |
(method_declaration | |
name: (field_identifier) @test.name | |
(#match? @test.name "^(Test|Example)")) @test.definition | |
(call_expression | |
function: (selector_expression | |
field: (field_identifier) @test.method) | |
(#match? @test.method "^Run$") | |
arguments: (argument_list . (interpreted_string_literal) @test.name)) | |
@test.definition | |
;; query | |
(block | |
(short_var_declaration | |
left: (expression_list | |
(identifier) @test.cases) | |
right: (expression_list | |
(composite_literal | |
body: (literal_value | |
(literal_element | |
(literal_value | |
(keyed_element | |
(literal_element | |
(identifier) @test.field.name1 | |
) | |
(literal_element | |
(interpreted_string_literal) @test.name | |
) | |
) | |
) | |
) @test.definition | |
)))) | |
(for_statement | |
(range_clause | |
left: (expression_list | |
(identifier) @test.case) | |
right: (identifier) @test.cases1 | |
(#eq? @test.cases @test.cases1)) | |
body: (block | |
(call_expression | |
function: (selector_expression | |
field: (field_identifier) @test.method) | |
(#match? @test.method "^Run$") | |
arguments: (argument_list | |
(selector_expression | |
operand: (identifier) @test.case1 | |
(#eq? @test.case @test.case1) | |
field: (field_identifier) @test.field.name2 | |
(#eq? @test.field.name1 @test.field.name2) | |
) | |
) | |
) | |
) | |
) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment