From 247ffd9de9f8b86bd426b7bd6686902ae500b506 Mon Sep 17 00:00:00 2001 From: Fredrik Averpil Date: Fri, 7 Feb 2025 09:13:54 +0100 Subject: [PATCH] fix: match directive in testify query (#286) --- lua/neotest-golang/features/testify/query.lua | 33 +++++++++++-------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/lua/neotest-golang/features/testify/query.lua b/lua/neotest-golang/features/testify/query.lua index 3302fd29..44dd43c1 100644 --- a/lua/neotest-golang/features/testify/query.lua +++ b/lua/neotest-golang/features/testify/query.lua @@ -10,13 +10,23 @@ 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 = [[ @@ -24,17 +34,14 @@ M.subtest_query = [[ (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