Closed sergii4 closed 1 year ago
Yeah this is really annoying to debug with that formatting, but it should be obvious that there is an impossible pattern of having a call_expression as a child of a block
How do you format your queries? Any tool to suggest?
Why is it impossible if call_expression is literally inside block? It used to work as a charm
Yeah, I missed expression_statement
. Thanks, mate!
How do you format your queries? Any tool to suggest?
Why is it impossible if call_expression is literally inside block? It used to work as a charm
In the process of writing such a tool, but i recommend nesting each child on a newline with 2 spaces, also your formatting just didn't work as well which made it hard. But nice job on figuring it out
That query used to work and now it fails. Could somebody please take a look?
I run a command:
and error is:
Query
;;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 for list table tests (block (short_var_declaration left: (expression_list (identifier) @test.cases) right: (expression_list (composite_literal (literal_value (literal_element (literal_value (keyed_element (literal_element (identifier) @test.field.name) (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.name1 (#eq? @test.field.name @test.field.name1))))))) ;; query for map table tests (block (short_var_declaration left: (expression_list (identifier) @test.cases) right: (expression_list (composite_literal (literal_value (keyed_element (literal_element (interpreted_string_literal) @test.name) (literal_element (literal_value) @test.definition)))))) (for_statement (range_clause left: (expression_list ((identifier) @test.key.name) ((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 ((identifier) @test.key.name1 (#eq? @test.key.name @test.key.name1)))))))Go code
package main import ( "testing" "github.com/stretchr/testify/assert" ) //func TestSubtract(t *testing.T) { // testCases := []struct { // desc string // a int // b int // want int // }{ // { // desc: "test one", // a: 1, // b: 2, // want: 3, // }, // { // desc: "test two", // a: 1, // b: 2, // want: 7, // }, // } // for _, tC := range testCases { // t.Run(tC.desc, func(t *testing.T) { // assert.Equal(t, tC.want, subtract(tC.a, tC.b)) // }) // } //} func TestAdd(t *testing.T) { t.Run("test one", func(t *testing.T) { assert.Equal(t, 3, add(1, 2)) }) t.Run("test two", func(t *testing.T) { assert.Equal(t, 5, add(1, 2)) }) variable := "string" t.Run(variable, func(t *testing.T) { assert.Equal(t, 3, add(1, 2)) }) } func add(a, b int) int { return a + b } func subtract(a, b int) int { return a - b }Last commit: bbaa67a180cfe0c943e50c55130918be8efb20bd