-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add support for go - Support for Godog 'Given', 'When', 'Then' and 'Step' step definition keywords - Support for 'interpreted_string_literal' and 'raw_string_literal' expressions - Godog snippet implementation --------- Co-authored-by: Aslak Hellesøy <1000+aslakhellesoy@users.noreply.github.com> Co-authored-by: Kieran Ryan <kierankilkenny@gmail.com>
- Loading branch information
1 parent
5af1b59
commit 9c4cec5
Showing
14 changed files
with
2,472 additions
and
8,952 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { StringOrRegExp } from '@cucumber/cucumber-expressions' | ||
|
||
import { unsupportedOperation } from './helpers.js' | ||
import { Language, TreeSitterSyntaxNode } from './types.js' | ||
|
||
export const goLanguage: Language = { | ||
toParameterTypeName: unsupportedOperation, | ||
toParameterTypeRegExps: unsupportedOperation, | ||
toStepDefinitionExpression(node: TreeSitterSyntaxNode): StringOrRegExp { | ||
const text = stringLiteral(node) | ||
const hasRegExpAnchors = text[0] == '^' || text[text.length - 1] == '$' | ||
return hasRegExpAnchors ? new RegExp(text) : text | ||
}, | ||
// Empty array as Godog does not support Cucumber Expressions | ||
defineParameterTypeQueries: [], | ||
defineStepDefinitionQueries: [ | ||
`(function_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 | ||
`, | ||
`(function_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' }, | ||
float: { type: 'float', name: 'f' }, | ||
word: { type: 'string' }, | ||
string: { type: 'string', name: 's' }, | ||
double: { type: 'float', name: 'd' }, | ||
bigdecimal: { type: 'float64', name: 'bigDecimal' }, | ||
byte: { type: 'rune', name: 'b' }, | ||
short: { type: 'int32', name: 's' }, | ||
long: { type: 'int64', name: 'l' }, | ||
biginteger: { type: 'int64', name: 'bigInteger' }, | ||
'': { type: 'string', name: 'arg' }, | ||
}, | ||
defaultSnippetTemplate: ` | ||
// Generated with Cucumber Expressions syntax, which are not supported by Godog. Convert to Regular Expressions. | ||
ctx.{{ keyword }}(\`{{ expression }}\`, <stepFunc>) | ||
`, | ||
} | ||
|
||
export function stringLiteral(node: TreeSitterSyntaxNode | null): string { | ||
if (node === null) throw new Error('node cannot be null') | ||
return node.text.slice(1, -1) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import assert from 'assert' | ||
|
||
import { stringLiteral } from '../../src/language/goLanguage.js' | ||
import { TreeSitterSyntaxNode } from '../../src/language/types.js' | ||
|
||
describe('goLanguage', () => { | ||
it('should remove enclosing string quotations and backticks', () => { | ||
const cases = ['`^I eat (d+)$`', '"^I eat (d+)$"'] | ||
|
||
cases.forEach((expression) => { | ||
const node: TreeSitterSyntaxNode = { | ||
type: 'raw_string_literal', | ||
text: expression, | ||
startPosition: { row: 1, column: 19 }, | ||
endPosition: { row: 1, column: 19 + expression.length }, | ||
children: [], | ||
} | ||
const result = stringLiteral(node) | ||
assert.deepStrictEqual(result, '^I eat (d+)$') | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/cucumber/godog" | ||
) | ||
|
||
func a_regexp() {} | ||
|
||
func InitializeScenario(ctx *godog.ScenarioContext) { | ||
ctx.Given(`^a regexp$`, a_regexp) | ||
} |