diff --git a/gherkin-utils/java/src/test/java/io/cucumber/gherkin/utils/pretty/PrettyTest.java b/gherkin-utils/java/src/test/java/io/cucumber/gherkin/utils/pretty/PrettyTest.java index 33d0c2f7790..3310f5b3325 100644 --- a/gherkin-utils/java/src/test/java/io/cucumber/gherkin/utils/pretty/PrettyTest.java +++ b/gherkin-utils/java/src/test/java/io/cucumber/gherkin/utils/pretty/PrettyTest.java @@ -316,6 +316,114 @@ public void commentAtStartAndEndOfFile() { prettyPrint(gherkinDocument, Syntax.gherkin)); } + @Test + void commentBeforeExamples() { + GherkinDocument gherkinDocument = parse("Feature: Comment before an Examples\n" + + "\n" + + " Scenario Outline: with examples\n" + + " Given the minimalism\n" + + " # then something happens\n" + + "\n" + + " Examples:\n" + + " | value |\n" + + " | 1 |\n" + + " | 2 |\n"); + assertEquals("Feature: Comment before an Examples\n" + + "\n" + + " Scenario Outline: with examples\n" + + " Given the minimalism\n" + + " # then something happens\n" + + "\n" + + " Examples:\n" + + " | value |\n" + + " | 1 |\n" + + " | 2 |\n", + prettyPrint(gherkinDocument, Syntax.gherkin)); + } + + @Test + + void commentsBeforeAndAfterKeywords(){ + GherkinDocument gherkinDocument = parse("# before Feature\n" + + "Feature: Comments everywhere\n" + + " # after Feature\n" + + "\n" + + " # before Background\n" + + " Background: foo\n" + + " # after Background\n" + + "\n" + + " # before Scenario\n" + + " Scenario: foo\n" + + " # after Scenario\n" + + " # before Given\n" + + " Given nothing\n" + + " # after Given\n" + + "\n" + + " #####\n" + + " # And spaced out\n" + + " ####\n" + + "\n" + + " # before Tag\n" + + " @foo\n" + + " # after Tag\n" + + " Scenario: Foo\n" + + " Given another\n" + + "\n" + + " # before Rule\n" + + " Rule:\n" + + " # after Rule\n" + + "\n" + + " # background comment\n" + + " Background: foo\n" + + "\n" + + " # middling comment\n" + + "\n" + + " # another middling comment\n" + + "\n" + + " # scenario comment\n" + + " Scenario: foo\n"); + assertEquals( "# before Feature\n" + +"Feature: Comments everywhere\n" + +" # after Feature\n" + +"\n" + +" # before Background\n" + +" Background: foo\n" + +" # after Background\n" + +"\n" + +" # before Scenario\n" + +" Scenario: foo\n" + +" # after Scenario\n" + +" # before Given\n" + +" Given nothing\n" + +" # after Given\n" + +"\n" + +" #####\n" + +" # And spaced out\n" + +" ####\n" + +"\n" + +" # before Tag\n" + +" @foo\n" + +" # after Tag\n" + +" Scenario: Foo\n" + +" Given another\n" + +"\n" + +" # before Rule\n" + +" Rule:\n" + +" # after Rule\n" + +"\n" + +" # background comment\n" + +" Background: foo\n" + +"\n" + +" # middling comment\n" + +"\n" + +" # another middling comment\n" + +"\n" + +" # scenario comment\n" + +" Scenario: foo\n", + prettyPrint(gherkinDocument, Syntax.gherkin)); + + } + private GherkinDocument parse(String gherkin) { GherkinParser parser = GherkinParser .builder()