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

Unable to match pattern with line continuation and no further characters on second line #319

Open
kieran-ryan opened this issue Jan 15, 2024 · 4 comments
Assignees
Labels
enhancement Improvement of existing features or bugfix help wanted Extra attention is needed k::UI/UX UI (user interface) and UX (user experience) changes
Milestone

Comments

@kieran-ryan
Copy link

What did you observe?

Integrating support for line continuations in step definition patterns into the official cucumber VSCode extension (cucumber/vscode#179). Was unsure how to handle a line continuation no further characters on the following line. No error thrown, and was unable to find a matching gherkin step.

With the below example, I would have assumed the gherkin text (which includes a trailing space) would have matched the pattern.

#[given("a line continuation \
")]
fn hungry_cat(world: &mut AnimalWorld) {
    world.cat.hungry = true;
}
Given a line continuation 

For a working example, having a character on the second line would match as follows:

#[given("a line continuation \
!")]
fn hungry_cat(world: &mut AnimalWorld) {
    world.cat.hungry = true;
}
Given a line continuation !

Where are you looking for help?

Is there a gherkin step text example that matches the above pattern?

Version information

  • rustc 1.75.0
  • cucumber 0.20.2
@tyranron tyranron added bug Something isn't working k::api Related to API (application interface) labels Jan 16, 2024
@tyranron tyranron self-assigned this Jan 16, 2024
@tyranron
Copy link
Member

@kieran-ryan thanks! I'll look into this.

@tyranron
Copy link
Member

tyranron commented Jan 16, 2024

@kieran-ryan I've looked into this, and it seems to be a correct behavior of Gherkin parser.

I run the test on the official reference inplementation:

Feature: foo
  Scenario: bar
    Given a line continuation 
    Then failure
$ npm install --save-dev @cucumber/cucumber
$ node_modules/.bin/gherkin-javascript test.feature | jq
{
  "source": {
    "data": "Feature: foo\n  Scenario: bar\n    Given a line continuation \n    Then failure\n",
    "uri": "test.feature",
    "mediaType": "text/x.cucumber.gherkin+plain"
  }
}
{
  "gherkinDocument": {
    "feature": {
      "tags": [],
      "location": {
        "line": 1,
        "column": 1
      },
      "language": "en",
      "keyword": "Feature",
      "name": "foo",
      "description": "",
      "children": [
        {
          "scenario": {
            "id": "ff6d7cc4-677a-4f0a-9c2c-8fdff4d0aef0",
            "tags": [],
            "location": {
              "line": 2,
              "column": 3
            },
            "keyword": "Scenario",
            "name": "bar",
            "description": "",
            "steps": [
              {
                "id": "833488c0-2611-4d0c-b567-bcf1b51d7dff",
                "location": {
                  "line": 3,
                  "column": 5
                },
                "keyword": "Given ",
                "keywordType": "Context",
                "text": "a line continuation"
              },
              {
                "id": "e186eb36-780c-4735-bc6a-17642089c1f8",
                "location": {
                  "line": 4,
                  "column": 5
                },
                "keyword": "Then ",
                "keywordType": "Outcome",
                "text": "failure"
              }
            ],
            "examples": []
          }
        }
      ]
    },
    "comments": [],
    "uri": "test.feature"
  }
}
{
  "pickle": {
    "id": "5f22b53d-0764-4ba4-8760-19f97bddf6c0",
    "uri": "test.feature",
    "astNodeIds": [
      "ff6d7cc4-677a-4f0a-9c2c-8fdff4d0aef0"
    ],
    "tags": [],
    "name": "bar",
    "language": "en",
    "steps": [
      {
        "id": "039d6e5f-0029-401f-86d1-a967d0aa2066",
        "text": "a line continuation",
        "type": "Context",
        "astNodeIds": [
          "833488c0-2611-4d0c-b567-bcf1b51d7dff"
        ]
      },
      {
        "id": "d4e8534d-47fc-4f30-bcfd-ea9f5abe0179",
        "text": "failure",
        "type": "Outcome",
        "astNodeIds": [
          "e186eb36-780c-4735-bc6a-17642089c1f8"
        ]
      }
    ]
  }
}

We can clearly see the trailing whitespace in the source.data, however, the parsed text of the step doesn't contain it.

I doubt we should deviate from the official reference implementation in this detail, since Gherkin doesn't expose any concrete formal grammar. And thus, unfortunately for you, you should consider in your tests that trailing spaces are omitted.

@tyranron tyranron added invalid This doesn't seem right wontfix This will not be worked on labels Jan 16, 2024
@tyranron tyranron added this to the 0.21.0 milestone Jan 16, 2024
@kieran-ryan
Copy link
Author

kieran-ryan commented Jan 16, 2024

Super, thank you for the immediate follow-up! That validates my assumption: no gherkin step will match a step definition pattern with trailing whitespace.

Thus, I would suggest a change request for cucumber-rs to provide a specific error message if a pattern contains trailing whitespace, that is invalid; making the failure explicit, rather than a soft failure where the step is considered unmatched and the user must figure out that trailing whitespace cannot be included in a step definition pattern. Only a suggestion though.

Thanks for the awesome support! 🙌

@tyranron tyranron added enhancement Improvement of existing features or bugfix k::UI/UX UI (user interface) and UX (user experience) changes and removed bug Something isn't working invalid This doesn't seem right wontfix This will not be worked on k::api Related to API (application interface) labels Jan 16, 2024
@tyranron
Copy link
Member

@kieran-ryan

Thus, I would suggest a change request for cucumber-rs to provide a specific error message if a pattern contains trailing whitespace, that is invalid; making the failure explicit, rather than a soft failure where the step is considered unmatched and the user must figure out that trailing whitespace cannot be included in a step definition pattern. Only a suggestion though.

Makes sense. Would love to see a PR.

@tyranron tyranron reopened this Jan 16, 2024
@tyranron tyranron added the help wanted Extra attention is needed label Jan 16, 2024
@tyranron tyranron modified the milestones: 0.21.0, 0.22.0 Apr 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improvement of existing features or bugfix help wanted Extra attention is needed k::UI/UX UI (user interface) and UX (user experience) changes
Projects
None yet
Development

No branches or pull requests

2 participants