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

Only suggest parameter types when text is surrounded by whitespace #657

Closed
aslakhellesoy opened this issue Jul 18, 2019 · 2 comments
Closed
Assignees
Labels
🐛 bug Defect / Bug

Comments

@aslakhellesoy
Copy link
Contributor

aslakhellesoy commented Jul 18, 2019

Imagine the following parameter type is defined:

ParameterType(
  name: 'direction',
  regexp: /(up|down)/,
  transformer: ->(s) { s }
)

This could be used with the following step definition:

When("the sun goes {direction}") do |direction|
end

However, if we add two new undefined Gherkin steps:

Given the sun has gone down
When Aslak downloads a picture

That should suggest:

Given("the sun has gone {direction}") do |direction|
end

But it should not suggest:

When("Aslak {direction}loads a picture") do |direction|
end

Instead, it should simply suggest:

When("Aslak downloads a picture") do |direction|
end

Parameters should only be suggested when the text is surrounded by whitespace, or when it's at the beginning or end of the step. That's what users would expect.

@aslakhellesoy aslakhellesoy added the 🐛 bug Defect / Bug label Jul 18, 2019
@aslakhellesoy aslakhellesoy changed the title Generated Cucumber Expressions should not suggest parameter types surrounded by whitespace Only suggest parameter types when text is surrounded by whitespace Jul 18, 2019
vincent-psarga added a commit that referenced this issue Jul 22, 2019
aslakhellesoy added a commit that referenced this issue Aug 4, 2019
aslakhellesoy pushed a commit that referenced this issue Aug 4, 2019
* Add tests describing issue #657

* Force ParameterTypeMatcher to match full words

* Enable choosing it custom ParameterType must match a full word or not

 - default is true
 - default parameters do not force matching a word (to be discussed)
 - updated some tests so they keep passing

* Take into account punctuation when suggesting parameters

* Java: Don't suggest parameter unless at beginning/end or surrounded by space/punctuation

Also: Remove an obsolete test, update other tests and improve float/double matching

* Remove "force_full_word" parameter when creating ParameterType

Also use \p{P} instead of [[:punct]] to have the same implementation across multiple languages
Update tests so they still reflect expected behavior even with word matching

* Port tests from cucumber-expressions/ruby to reflect issue #657

* Only propose full words as parameters in cucumber-expressions/javascript

Also adapt tests so they reflect those changes

* Fixed rspec organization so the test name make sense

* Port tests from cucumber-expressions/ruby to cucumber-expressions/go to reflect issue #657

* Do not suggest in-word parameters in cucumber-expressions/go

Also update test to reflect the changes

* Apply @luke-hill review for a more ruby-ish code

* Undo changes unrelated to matching words

* Extract groupMatchesFullWord method for clarity
@sebrose
Copy link
Member

sebrose commented Jan 6, 2020

Perhaps an unintended consequence, but now numerical parameters with units are not recognised by the snippet generator:
Given Sean is 15m from Lucy -> "Sean is 15m from Lucy", but should be "Sean is {int}m from Lucy"

@sebrose sebrose reopened this Jan 6, 2020
@sebrose sebrose closed this as completed Jan 6, 2020
@vincent-psarga
Copy link
Contributor

vincent-psarga commented Jan 6, 2020

Maybe it could be interesting to have some built-in "units" type (\d+(d|h|m|s, \d+(m|km), \d+(ft|'|") (I don't know what the classical short version for other imperial units is)) but I think it would be pretty hard to have something easily translatable/portable for multiple languages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Defect / Bug
Projects
None yet
Development

No branches or pull requests

3 participants