Skip to content

Commit

Permalink
fix: match directive in testify query (#286)
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikaverpil authored Feb 7, 2025
1 parent 78a0a1c commit 247ffd9
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions lua/neotest-golang/features/testify/query.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,38 @@ M.namespace_query = [[
; func (suite *testSuite) TestSomething() { // @namespace.name
; // test code
; }
(method_declaration
(method_declaration
receiver: (parameter_list
(parameter_declaration
; name: (identifier)
type: (pointer_type
(type_identifier) @namespace.name )))) @namespace.definition
name: (field_identifier) @test_function (#match? @test_function "^(Test|Example)") (#not-match? @test.name "^TestMain$")
(type_identifier) @namespace.name
)
)
)
) @namespace.definition
name: (field_identifier) @test_function (#match? @test_function "^(Test|Example)") (#not-match? @test.name "^TestMain$")
]]

M.test_method_query = [[
; query for test method
(method_declaration
name: (field_identifier) @test.name (#match? @test.name "^(Test|Example)") (#not-match? @test.name "^TestMain$")
) @test.definition
]]

M.subtest_query = [[
; query for subtest, like s.Run(), suite.Run()
(call_expression
function: (selector_expression
operand: (identifier) @test.operand (#match? @test.operand "^(s|suite)$")
field: (field_identifier) @test.method) (#match? @test.method "^Run$")
arguments: (argument_list . (interpreted_string_literal) @test.name))
@test.definition
field: (field_identifier) @test.method (#match? @test.method "^Run$")
)
arguments: (argument_list
. (interpreted_string_literal) @test.name
)
) @test.definition
]]

M.test_method_query = [[
; query for test method
(method_declaration
name: (field_identifier) @test.name (#match? @test.name "^(Test|Example)") (#not-match? @test.name "^TestMain$")) @test.definition
]]

--- Run a TreeSitter query on a file and return the matches.
--- @param filepath string The path to the file to query
--- @param query_string string The TreeSitter query string
Expand Down

0 comments on commit 247ffd9

Please sign in to comment.