ducminh-phan / reformat-gherkin

Formatter for Gherkin language
MIT License
24 stars 13 forks source link

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

Open rayjolt opened 2 years ago

rayjolt commented 2 years ago

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

rayjolt commented 2 years ago

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.'