Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added feature to detect custom parameter types for cucumber expressions. #103

Merged
merged 2 commits into from
Jul 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion gserver/src/steps.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export default class StepsHandler {

getRegTextForStep(step: string): string {

//Ruby interpolation (like `#{Something}` )should be replaced with `.*`
//Ruby interpolation (like `#{Something}` ) should be replaced with `.*`
//https://github.com/alexkrechik/VSCucumberAutoComplete/issues/65
step = step.replace(/#{(.*?)}/g, '.*');

Expand All @@ -133,6 +133,12 @@ export default class StepsHandler {
step = step.replace(/{int}/g, '-?\\d+');
step = step.replace(/{stringInDoubleQuotes}/g, '"[^"]+"');

//Handle Cucumber Expressions (like `{Something}`) should be replaced with `.*`
//https://github.com/alexkrechik/VSCucumberAutoComplete/issues/99
//Cucumber Expressions Custom Parameter Type Documentation
//https://docs.cucumber.io/cucumber-expressions/#custom-parameters
step = step.replace(/(?!{[\d|,]){(.*?)}/g, '.*');

//Escape all the regex symbols to avoid errors
step = escapeRegExp(step);

Expand Down
12 changes: 12 additions & 0 deletions gserver/test/steps.handler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,18 @@ describe('getRegTextForStep', () => {
expect(s.getRegTextForStep(d[0])).to.be.equal(d[1]);
});
});
it('should correctly handle cucumber expressions', () => {
let data = [
['Test multiples: { cuke expression 1 } { cuke-expression-2 }', 'Test multiples: .* .*'],
['Test regex - braces: {.*}', 'Test regex - braces: .*'],
['Test regex - misc: (.*){3,4} (.*){,5}', 'Test regex - misc: (.*){3,4} (.*){,5}'],
['Test order: {first} {.*} (.*){6,7} (.*) (.*){,5} {last}', 'Test order: .* .* (.*){6,7} (.*) (.*){,5} .*'],
['I use \{ some backslashed thing \}', 'I use \{ some backslashed thing \}']
];
data.forEach(d => {
expect(s.getRegTextForStep(d[0])).to.be.equal(d[1]);
});
});
});

describe('constructor', () => {
Expand Down