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

This fixes an issues where negative numbers were not passed correctly… #623

Merged
merged 5 commits into from
May 20, 2016

Conversation

samholder
Copy link
Contributor

… as arguments when using regexless methods. The underlyinh problem was that when using regexless parameters a regex is generated, and this regex was using '\W' between any words in the method name. this matches anything which is not a-zA-Z0-9_, which includes the '-' character which is part of the negative number. As I think that we are really matching gaps between words I have changed this to use '\s' which simply matches any whitespace characters. We could instead explictily use the non-word match and add the '-' character if we change it to '[^a-zA-Z0-9-]'. Both make the test pass, but the withspace one seems better to me. Any input appreciated.

This area does not contain any unit tests, but I have added an integration test which checks this, and based it on the scenario in the issue which this fixes, #246

I might be able to add some unit tests in the future, but this seems sufficient for now.

… as arguments when using regexless methods. The underlyinh problem was that when using regexless parameters a regex is generated, and this regex was using '\W' between any words in the method name. this matches anything which is not a-zA-Z0-9_, which includes the '-' character which is part of the negative number. As I think that we are really matching gaps between words I have changed this to use '\s' which simply matches any whitespace characters. We could instead explictily use the non-word match and add the '-' character if we change it to '[^a-zA-Z0-9-]'. Both make the test pass, but the withspace one seems better to me. Any input appreciated.

This area does not contain any unit tests, but I have added an integration test which checks this, and based it on the scenario in the issue which this fixes, SpecFlowOSS#246

I might be able to add some unit tests in the future, but this seems sufficient for now.
@samholder
Copy link
Contributor Author

bah, broke another test. Will investigate and fix.

@samholder
Copy link
Contributor Author

is this test a situation we should be supporting:

   When Joe does - something with:
                | table |

should bind to

[When]
public void When_WHO_does_WHAT_with(string who, string what, Table table)
{
    if (what != "something") throw new Exception("invalid parameter: " + what);
}

this feels like its wrong to me, like we are supporting allowing random punctuation to be included in the scenario definition for no apparent reason. Generating a regex which allows this but doesn't also consume the '-' character for negative numbers is going to be more tricky I expect

@samholder
Copy link
Contributor Author

Ah I've woken up understanding the use case for this test. its not a random bit of punctuation - its a sentence with a dash used as a separator, as I've just done.

I'll fix the generated regex to cope with this

…enerated Regex to be '\s+(?:-(?!\d)\s?)?' which copes with all the current test cases. This pattern basically says between the words we can have at least one white space character which can optionally be followed by a '-' (as long as that is not immediately followed by a number) which can optionally be followed by any number of which space characters.
@samholder
Copy link
Contributor Author

Ok I think I have modified the regex to make all the tests pass, but I'm wondering if there are sufficient test cases. It copes with the ' - ' used as a separator, but won't cope with other things like semi colons, colons, currency symbols etc. Ideally we want to say 'consume all non word characters unless its a dash followed by a number'. My regex isn't all that but I'll keep looking at this and see if I can come up with something better, and try and add a few more test cases around this to cope with currency values in particular

…s one or more non whitespace chars until it finds one which is a follwed by a number which is preceeded by a minus sign
@samholder
Copy link
Contributor Author

I think this is fixed now. All test cases pass now, including addtional ones for currency and negative numbers

@gasparnagy
Copy link
Contributor

Ok, thx!

@gasparnagy gasparnagy merged commit 07f52ad into SpecFlowOSS:master May 20, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants