Skip to content

Commit

Permalink
Fix: Find godog step definitions within method_declaration (#215)
Browse files Browse the repository at this point in the history
* add support for golang methods

* update changelog

* test godog definition within method_declaration

---------

Co-authored-by: Kieran Ryan <kierankilkenny@gmail.com>
  • Loading branch information
tigh-latte and kieran-ryan committed Jul 4, 2024
1 parent c7cdd0a commit 0d28333
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- (Ruby) Support `And` and `But` step definition annotations ([#211](https://github.com/cucumber/language-service/pull/211))
- (Python) Title variants of Behave's decorators (`Step`, `Given`, `When`, `Then`) ([#213](https://github.com/cucumber/language-service/pull/213))
- (PHP) Scoped query to match annotations only (`@Given`) ([#214](https://github.com/cucumber/language-service/pull/214))
- (Go) Find godog step definitions within `method_declaration` ([#215](https://github.com/cucumber/language-service/pull/215))

## [1.6.0] - 2024-05-12
### Added
Expand Down
28 changes: 28 additions & 0 deletions src/language/goLanguage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,34 @@ export const goLanguage: Language = {
)
(#match? @annotation-name "Given|When|Then|Step")))))@root
`,
`(method_declaration
body: (block
(expression_statement
(call_expression
function: (selector_expression
field: (field_identifier) @annotation-name
)
arguments: (argument_list
[
(raw_string_literal) @expression
]
)
(#match? @annotation-name "Given|When|Then|Step")))))@root
`,
`(method_declaration
body: (block
(expression_statement
(call_expression
function: (selector_expression
field: (field_identifier) @annotation-name
)
arguments: (argument_list
[
(interpreted_string_literal) @expression
]
)
(#match? @annotation-name "Given|When|Then|Step")))))@root
`,
],
snippetParameters: {
int: { type: 'int', name: 'i' },
Expand Down
2 changes: 1 addition & 1 deletion test/language/ExpressionBuilder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ Please register a ParameterType for 'undefined-parameter'`,
}
assert(matched, 'The generated expressions did not match parameter type {date}')
} else {
assert.deepStrictEqual(expressions, [/^a regexp$/])
assert.deepStrictEqual(expressions, [/^a regexp$/, /^I test this change$/])
assert.deepStrictEqual(errors, ['There is already a parameter type with name int'])
}
})
Expand Down
4 changes: 4 additions & 0 deletions test/language/testdata/go/StepDefinitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ func a_regexp() {}
func InitializeScenario(ctx *godog.ScenarioContext) {
ctx.Given(`^a regexp$`, a_regexp)
}

func (s suite) Steps(sc *godog.ScenarioContext) {
sc.Given(`^I test this change$`, a_regexp)
}
9 changes: 8 additions & 1 deletion test/language/testdata/php/StepDefinitions.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,12 @@ public function regexp()
{
// Given
}
}

/**
* @Given ^I test this change$
*/
public function test_changes()
{
// Given
}
}

0 comments on commit 0d28333

Please sign in to comment.