Tyler-Keith-Thompson / CucumberSwift

A lightweight swift Cucumber implementation
https://tyler-keith-thompson.github.io/CucumberSwift/documentation/cucumberswift/
MIT License
74 stars 19 forks source link

Quoted string works incorrect in scenario outline when there is a parameter #71

Closed Hsilgos closed 1 year ago

Hsilgos commented 1 year ago

When scenario outline parameter is in quotes it's not taken from examples table.

Consider the next example:

Scenario Outline: Test outline
    Given Something is done with "<parameter name>"

    Examples:
      | parameter name  | 
      | value                     |

And Swift implementation:

Given("^Something is done with \"(.*)\"$") { args, _ in
    XCTAssertEqual(args[1], "value")
}

And attempt to run fails with

XCTAssertEqual failed: ("\<parameter name>") is not equal to ("value")

This is inconsistent with known to me Cucumber behaviour in other languages.

Looking at Lexer.swift I see that text in quotes like "blah blah" is read as single token and I don't understand why? What is special about quoted string? I haven't found any special about quotes here https://cucumber.io/docs/gherkin/reference/ I would say that when it's clear that it's not Doc String it should not apply any special logic and concatenate everything to previous token?

Tyler-Keith-Thompson commented 1 year ago

Ahh, the lexer did that because it was trying to make it reasonable to generate step stubs with appropriate regular expressions. This was an oversight.

I'll add it to the backlog as a bug.

david1hyman commented 1 year ago

Plus 1 on this issue. I ran into it a few weeks ago - just before this bug was posted - and I've been tinkering off and on in the hope that it was an implementation error; yesterday I proved it was not. Glad to see I'm not alone. I discovered the issue when I started using Cucumber Studio; it exports features with the quotes included. @Tyler-Keith-Thompson over the next few days I might have a chance to try to fix this. If you have a solid idea of where the issue is you could point me to it. I'm sure I can track it down but I haven't looked yet at all.

In the meantime I made a run script that strips the quotes. I'd be happy to share if anyone is interested and willing to pardon my hacky bash.

Tyler-Keith-Thompson commented 1 year ago

So the trick here will be to remove the tokenization of string/Int from the lexer.

However, we should add a new lexer that tokenizes steps looking for string/Int for stub generation.

The implementation went the wrong direction when I tried to tokenize for stub generation and Gherkin simultaneously.

However, we now have consumers depending on the current implementation, so we should do another major version rev and either as part of this, or as a fast follow allow # to be escaped.

david1hyman commented 1 year ago

Based on your description the chances of me tackling this issue feel pretty slim. As much as I'd love to I don't think I have the time to gain the domain understanding to work through it in a reasonable way. I'll be watching for an update and we wil test when it's available.

Tyler-Keith-Thompson commented 1 year ago

I'll try and take a look at this in the near future. Things will finally have slowed down a bit for me by this weekend (unless the universe decides to punish me for predicting the future just there).

Tyler-Keith-Thompson commented 1 year ago

🎉 CucumberSwift v4.2.1 (running in the pipeline as I write this) should solve this problem. There are now 2 lexers, one that tokenizes for stub generation and one that parses Gherkin. The one that parses Gherkin no longer cares about integers or strings (but still cares about doc strings).