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

cucumber-expressions: Matching a literal open-parenthesis #333

Closed
jamis opened this issue Feb 9, 2018 · 4 comments
Closed

cucumber-expressions: Matching a literal open-parenthesis #333

jamis opened this issue Feb 9, 2018 · 4 comments

Comments

@jamis
Copy link
Contributor

jamis commented Feb 9, 2018

Summary

I'm using cucumber as a platform-agnostic way to describe an API in a book I'm writing, which is perhaps a bit out-of-the-ordinary for cucumber, but so far has worked great. Upgrading to 3.x has proven awkward, though, as many of my steps involve describing function calls, with parameters lists enclosed in parentheses, like so:

Scenario: Subtracting two vectors
  Given v1 := vector(3, 2, 1)
    And v2 := vector(5, 6, 7)
  Then v1 - v2 = vector(-2, -4, -6)

While I can represent this with a raw regex, the cucumber expressions are beautifully convenient. Sadly, given a step definition like this:

Given("{word} := vector({float}, {float}, {float})") do |var, x, y, z|
  # ...
end

The parentheses are being interpreted as optional groups. Is there already a way to escape those, so they can be interpreted literally?

Expected Behavior

I would expect there to be a way to escape parentheses in cucumber expressions, so that they can be interpreted literally.

Current Behavior

There does not currently appear to be a way to escape parentheses in cucumber expressions.

Possible Solution

Consider OPTIONAL_REGEXP, here:

https://github.com/cucumber/cucumber/blob/fc5308ff70378277cfbe6a56d102c5a8c42be69f/cucumber-expressions/ruby/lib/cucumber/cucumber_expressions/cucumber_expression.rb#L11

If this were made a bit more sophisticated, it could be made to ignore parentheses that are prefixed by an escape character (a backslash comes to mind, but maybe there's something else that is more idiomatic to Cucumber?)

Your Environment

  • Version used: 5.0.13 (Ruby)
  • Operating System and version: macOS 10.13.3
@aslakhellesoy
Copy link
Contributor

Hi @jamis!

This sounds like a dupe of #107, which we decided not to prioritise. Now, if you submit a PR that's a different story - I'd be happy to add it if you did! Using \ for escaping would be fine.

@jamis
Copy link
Contributor Author

jamis commented Feb 9, 2018

Ah, sorry I missed that ticket! I promise I did try to do my due-diligence before posting. :) PR is incoming, look for it in a few. Thanks!

@aslakhellesoy
Copy link
Contributor

Closed by 3c38076

@lock
Copy link

lock bot commented Feb 10, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Feb 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants