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

Cannot round-trip Gherkin files where a blank line following a scenario description has trailing whitespace #62

Open
rayjolt opened this issue Oct 10, 2022 · 1 comment

Comments

@rayjolt
Copy link
Contributor

rayjolt commented Oct 10, 2022

Describe the bug

When attempting to format a Gherkin file in which a scenario description is followed by a blank line with trailing whitespace, reformat-gherkin gives the error "INTERNAL ERROR: The new content produced is not equivalent to the source".

To Reproduce

Steps to reproduce the behaviour

  1. Save the following feature as test.feature
Feature: A feature
  Scenario: A scenario
    A scenario description. The following line has trailing whitespace.
    
    When I do something
    Then something happens

(Note that the line after the scenario description contains four spaces.)

  1. Run reformat-gherkin test.feature

Expected behaviour

The file is reformatted.

Actual behaviour

The following error occurs:

Error: cannot format /home/jtaylor/reformat-gherkin/test.feature: INTERNAL ERROR: The new content produced is not equivalent to the source.
Please report a bug on https://github.com/ducminh-phan/reformat-gherkin/issues.
This diff might be helpful: /tmp/rfmt-ghk_nt3vy6qf.log

All done! 💥 💔 💥
1 file failed to reformat.

The file /tmp/rfmt-ghk_nt3vy6qf.log contains the following:

--- src
+++ dst
@@ -1,4 +1,4 @@
-Feature(language='en', keyword='Feature', name='A feature', children=(FeatureChildren(background=None, scenario=Scenario(keyword='Scenario', name='A scenario', steps=(Step(keyword='When', text='I do something', data_table=None, doc_string=None), Step(keyword='Then', text='something happens', data_table=None, doc_string=None)), tags=(), description='A scenario description. The following line has trailing whitespace.\n', examples=()), rule=None),), tags=(), description='')
-Scenario(keyword='Scenario', name='A scenario', steps=(Step(keyword='When', text='I do something', data_table=None, doc_string=None), Step(keyword='Then', text='something happens', data_table=None, doc_string=None)), tags=(), description='A scenario description. The following line has trailing whitespace.\n', examples=())
+Feature(language='en', keyword='Feature', name='A feature', children=(FeatureChildren(background=None, scenario=Scenario(keyword='Scenario', name='A scenario', steps=(Step(keyword='When', text='I do something', data_table=None, doc_string=None), Step(keyword='Then', text='something happens', data_table=None, doc_string=None)), tags=(), description='A scenario description. The following line has trailing whitespace.', examples=()), rule=None),), tags=(), description='')
+Scenario(keyword='Scenario', name='A scenario', steps=(Step(keyword='When', text='I do something', data_table=None, doc_string=None), Step(keyword='Then', text='something happens', data_table=None, doc_string=None)), tags=(), description='A scenario description. The following line has trailing whitespace.', examples=())
 Step(keyword='When', text='I do something', data_table=None, doc_string=None)
 Step(keyword='Then', text='something happens', data_table=None, doc_string=None)

Environment

  • reformat-gherkin 3.0.1
  • Python 3.10.7
  • Ubuntu 22.04
@rayjolt rayjolt changed the title Cannot round-trip Gherkin files where lines following a scenario description contain trailing whitespace Cannot round-trip Gherkin files where a blank line following a scenario description has trailing whitespace Oct 11, 2022
@rayjolt
Copy link
Contributor Author

rayjolt commented Oct 11, 2022

The difference is whether there is a newline or not after the the scenario description. Before formatting, the scenario description is parsed as:

'A scenario description. The following line has trailing whitespace.\n'

After formatting, it is parsed as:

'A scenario description. The following line has trailing whitespace.'

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

No branches or pull requests

1 participant