Skip to content

Commit 0d28333

Browse files
Fix: Find godog step definitions within method_declaration (#215)
* add support for golang methods * update changelog * test godog definition within method_declaration --------- Co-authored-by: Kieran Ryan <[email protected]>
1 parent c7cdd0a commit 0d28333

File tree

5 files changed

+42
-2
lines changed

5 files changed

+42
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1010
- (Ruby) Support `And` and `But` step definition annotations ([#211](https://github.com/cucumber/language-service/pull/211))
1111
- (Python) Title variants of Behave's decorators (`Step`, `Given`, `When`, `Then`) ([#213](https://github.com/cucumber/language-service/pull/213))
1212
- (PHP) Scoped query to match annotations only (`@Given`) ([#214](https://github.com/cucumber/language-service/pull/214))
13+
- (Go) Find godog step definitions within `method_declaration` ([#215](https://github.com/cucumber/language-service/pull/215))
1314

1415
## [1.6.0] - 2024-05-12
1516
### Added

src/language/goLanguage.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,34 @@ export const goLanguage: Language = {
4242
)
4343
(#match? @annotation-name "Given|When|Then|Step")))))@root
4444
`,
45+
`(method_declaration
46+
body: (block
47+
(expression_statement
48+
(call_expression
49+
function: (selector_expression
50+
field: (field_identifier) @annotation-name
51+
)
52+
arguments: (argument_list
53+
[
54+
(raw_string_literal) @expression
55+
]
56+
)
57+
(#match? @annotation-name "Given|When|Then|Step")))))@root
58+
`,
59+
`(method_declaration
60+
body: (block
61+
(expression_statement
62+
(call_expression
63+
function: (selector_expression
64+
field: (field_identifier) @annotation-name
65+
)
66+
arguments: (argument_list
67+
[
68+
(interpreted_string_literal) @expression
69+
]
70+
)
71+
(#match? @annotation-name "Given|When|Then|Step")))))@root
72+
`,
4573
],
4674
snippetParameters: {
4775
int: { type: 'int', name: 'i' },

test/language/ExpressionBuilder.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ Please register a ParameterType for 'undefined-parameter'`,
109109
}
110110
assert(matched, 'The generated expressions did not match parameter type {date}')
111111
} else {
112-
assert.deepStrictEqual(expressions, [/^a regexp$/])
112+
assert.deepStrictEqual(expressions, [/^a regexp$/, /^I test this change$/])
113113
assert.deepStrictEqual(errors, ['There is already a parameter type with name int'])
114114
}
115115
})

test/language/testdata/go/StepDefinitions.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,7 @@ func a_regexp() {}
99
func InitializeScenario(ctx *godog.ScenarioContext) {
1010
ctx.Given(`^a regexp$`, a_regexp)
1111
}
12+
13+
func (s suite) Steps(sc *godog.ScenarioContext) {
14+
sc.Given(`^I test this change$`, a_regexp)
15+
}

test/language/testdata/php/StepDefinitions.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,12 @@ public function regexp()
1111
{
1212
// Given
1313
}
14-
}
1514

15+
/**
16+
* @Given ^I test this change$
17+
*/
18+
public function test_changes()
19+
{
20+
// Given
21+
}
22+
}

0 commit comments

Comments
 (0)