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

Regex with single char output throws exception #1405

Closed
manish7-thakur opened this issue Mar 5, 2021 · 6 comments
Closed

Regex with single char output throws exception #1405

manish7-thakur opened this issue Mar 5, 2021 · 6 comments
Assignees
Labels

Comments

@manish7-thakur
Copy link

manish7-thakur commented Mar 5, 2021

Summary

Regex which matches a single character (e.g "^ User ([ABZ])$") leads to a CucumberExpressionException because BuiltInParameterTransformer in cucumber-expressions-java doesn't have a character transformer even though type is deciphered as char shown in the screenshot attached.

Expected Behavior

If the type is deciphered as char, BuiltInParameterTransformer should return it as char.

Given("""^User ([ABZ])$""") {
     (user: Char) =>
       setCriteria { sc =>
         sc.copy(experiments = user))
       }
   }

Current Behavior

Currently it simply throws the exception: io.cucumber.cucumberexpressions.CucumberExpressionException: ParameterType {anonymous} failed to transform [B] to char

Possible Solution

We can have a transformer for character type in BuiltInParameterTransformer

  if (Character.class.equals(toValueClass) || char.class.equals(toValueClass)) {
              return fromValue.toCharArray()[0];
          }

Steps to Reproduce (for bugs)

A simple step with Regex which matches single char can reproduce it.

Given("""^User ([ABZ])$""")

Context & Motivation

I updated cucumber version to 6.10.0 and it broke my existing test cases.

Your Environment

  • Version used: cucumber-java-6.10.0
  • Operating System and version: mac - bigSur
  • Link to your project:
    Screen Shot 2021-03-05 at 14 58 46
@manish7-thakur
Copy link
Author

manish7-thakur commented Mar 5, 2021

Raised a PR to fix the issue in cucmber-expressions-java. If the changes looks good, I can port the changes to Ruby, JavaScript, Go, .NET and would log the change as well.

@luke-hill
Copy link
Contributor

This doesn't feel a bug in Ruby, because in ruby we just use the string type for all strings of arbitrary length. I suppose we could add it for standardisation, but it would rarely get used, because {string} and {word} are just more encompassing.

All 3 would have the same return type String class also.

I do understand the need in java for this, because (From my limited knowledge), the char type and the String type are fundamentally different taking up different amounts of memory.

Thoughts @mpkorstanje ?? Do we want to add this to other languages for standardisation? Where else would this be "active" (i.e. is Ruby the normal or the exception)

@mpkorstanje
Copy link
Contributor

I don't think this affects anything but Java and Go.

@luke-hill
Copy link
Contributor

Given that then, I'd err on the side of only adding it to Java and Go. As it's a reasonably small change and it's ok to have slight differences.

But then again these default ones we promote to our docs. I dunno I'm kinda on the fence as you can guess.

@mpkorstanje
Copy link
Contributor

These are not parameter types. The BuiltInParameterTransformer handles conversion in the absence of a cucumber expression parameter type using the Java Types from the step definition methods parameters instead.

@aslakhellesoy
Copy link
Contributor

Fixed in v12.0.1

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

No branches or pull requests

4 participants