cucumber-attic / gherkin2

A fast Gherkin parser in Ragel (The parser behind Cucumber)
MIT License
382 stars 221 forks source link

Pretty formatter cannot handle comments in feature correctly #347

Open xuanzhaopeng opened 8 years ago

xuanzhaopeng commented 8 years ago

Description:

When there are several comments in feature file, which contains one scenario outline, the pretty formatter cannot handle it correctly.

Stack Trace:

java.lang.StringIndexOutOfBoundsException: String index out of range: -2
    at java.lang.String.substring(String.java:1954)
    at gherkin.formatter.StepPrinter.writeStep(StepPrinter.java:11)
    at gherkin.formatter.PrettyFormatter.printStep(PrettyFormatter.java:259)
    at gherkin.formatter.PrettyFormatter.printSteps(PrettyFormatter.java:130)
    at gherkin.formatter.PrettyFormatter.replay(PrettyFormatter.java:121)
    at gherkin.formatter.PrettyFormatter.scenario(PrettyFormatter.java:98)

How to reproduce :

Feature : My feature

comments 1

comments 2

Scenario Outline : My scenaroi called Given I do sth1

comment

 When I do sth2
#  comment
 Then I do sth3

Examples:

comment here

|  Arg1  |  Name |
#  comment here
#  comment here
|  Val1   |  Val2   |
# comment here

Guess :

I follow the step from Cucumber-jvm to gherkin2, I found the problems seems could be located in PrettyFormatter.replay() , maybe in more detail, it is located in PrettyFormatter.addAnyOrphanMatch()

If I get deep debug information, I will let u all know