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

Gerkin: Paramater type {float} not matching 0 (zero). #600

Closed
alcarwk opened this issue Apr 25, 2019 · 5 comments
Closed

Gerkin: Paramater type {float} not matching 0 (zero). #600

alcarwk opened this issue Apr 25, 2019 · 5 comments
Labels
🐛 bug Defect / Bug

Comments

@alcarwk
Copy link

alcarwk commented Apr 25, 2019

Summary

The Gerkin parameter {float} does not match a simple 0 value. It seem to be treating this as an integer and thus looking for an integer step to match with. Any {float} steps are ignored as potential matches.

This is manly a problem as the Business stakeholders that are preparing Features and Scenarios do not understand that the difference between a 0 integer value and a 0.0 float value. They're mathematicians and consider 0 (integer) to belong to the domain of Real numbers and thus a valid value identical to the 0.0 (float) (likewise 1 is identical 1.0, and so on for all Integer values).

The Step where this is an issue has five parameters that are all likely float values yet are also possible Integer numbers. Supporting variations for all five possible matches would be somewhat cumbersome. (The other alternative of providing a custom type using a regular expression also isn't ideal.)

Expected Behavior

If matching on an Integer parameter and no {int} steps is found yet a matching {float} step exists then this will be used.

Current Behavior

If matching on an Integer and no {int} exist no matching takes place even if an acceptable {float} match is available.

Possible Solution

Accept that Integer values are acceptable subset of Real numbers and thus also acceptable matches for {float} parameter type iff no acceptable {int} step exists.

Context & Motivation

Features are intended to be prepared by domain experts that have no specialized understanding of computing environments. With this in mind interpretations of specific types of information provided in scenarios need to be aligned with the "common" understanding familiar to the domain experts.

@aslakhellesoy
Copy link
Contributor

Thanks for the detailed report @alcarwk!

@aslakhellesoy
Copy link
Contributor

aslakhellesoy commented Apr 28, 2019

This is a little tricky to implement, but not impossible.

The first step is to change FLOAT_REGEXPS / FLOAT_PATTERNS in ParameterTypeRegistry to -?\d*(?:[.,]\d+)?. That will recognise integers as floating points.

The tricky part is in the expression generation. We still want 0 in an undefined step to suggest {int} for the parameter. So we need to add some more smarts to the CucumberExpressionGenerator to make all tests pass.

Would you be interested in helping us with a PR for this?

@alcarwk
Copy link
Author

alcarwk commented Apr 28, 2019

Thanks for the response to this. At the moment I'm using a parameter type definition defined as {number} that matches both integer and float returning a Double.
This would provide a nice bases to work up a generalized (polymorphic) number matcher that works as suggested.

Time permitting I would like to help with adding this as a new feature.
There are a couple of other ideas based on what our Business experts are putting in features that might also be useful; i.e. lists in step definitions' "And applying adjustments 1, 1.32, 2.67, 3, 3.86, 4.2"

@stale
Copy link

stale bot commented Jun 27, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in a week if no further activity occurs.

@stale stale bot added the ⌛ stale Will soon be closed by stalebot unless there is activity label Jun 27, 2019
@aslakhellesoy
Copy link
Contributor

Give us more time stalebot!

@stale stale bot removed the ⌛ stale Will soon be closed by stalebot unless there is activity label Jun 28, 2019
aslakhellesoy added a commit that referenced this issue Jul 1, 2019
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

2 participants