Cannot round-trip Gherkin files where a blank line following a scenario description has trailing whitespace
rayjolt opened this issue ยท 1 comments
rayjolt commented
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
- 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.)
- 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 commented
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.'