cucumber-attic / gherkin2

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

PrettyFormatter options #331

Open muhqu opened 9 years ago

muhqu commented 9 years ago

This PR adds 3 optional formatting options to the PrettyFormatter. All options default to false to not change the formatting result unless explicitly enabled.

right-align numeric values in tables

formatter.setRightAlignNumericValues(true);
  Scenario: Format beautifully right-aligned numbers in a data table
    When I have this table:
      | name                          | value  |
      | barel of extra long cucumbers | 129.95 |
      | extra long cucumber           |  10.95 |
      | tiny cucumber                 |   2.95 |

center-align step keywords

formatter.setCenterSteps(true);
  Scenario: Format beautifully center-aligned steps
    Given there are 12 cucumbers
     When I eat 3 cucumbers
      And I throw 2 cucumbers into the trash can
     Then I should have 7 cucumbers

preserve a single blank line between steps

formatter.setPreserveBlankLineBetweenSteps(true);
  Scenario: Repetitive when.. then..
    Given there are 12 cucumbers
    When I eat 3 cucumbers
    Then I should have 9 cucumbers

    When I eat 2 cucumbers
    Then I should have 7 cucumbers

    When I eat 1 cucumbers
    Then I should have 6 cucumbers
muhqu commented 9 years ago

@aslakhellesoy any chance to get this one merged?

It would be great to get this into a release so I don't have to make a copy of the PrettyFormatter.java in https://github.com/cucumber/cucumber-eclipse/issues/107.

aslakhellesoy commented 9 years ago

Probably not I'm afraid. We're focussing on Gherkin 3 now: https://groups.google.com/d/msg/cukes/YLKsqbBMBoI/KR_Zq6DBgJwJ

We'll move the formatting to Cucumber - I'll keep this in mind when we get there. I've been wanting the same thing myself!

muhqu commented 9 years ago

@aslakhellesoy oh, hm k. …maybe I can contribute to Gherkin 3 as well. I've written a gherkin parser in golang.

aslakhellesoy commented 9 years ago

@muhqu oh that would be fantastic! Let me know if anything is missing from the contribution guide!