rlogiacco / Natural

Natural is a collection of Eclipse plugins to enable rich smart editing of acceptance tests using natural language definition files. It currently supports Cucumber and JBehave syntax.
Eclipse Public License 1.0
75 stars 37 forks source link

Reformat should (conditionally) align DataTables #39

Open genthaler opened 9 years ago

genthaler commented 9 years ago
Feature: Autoformat of DataTables 
    In order to improve readability of Features
    As a Feature author
    I want the Natural plugin to automatically align column delimiters in DataTables
Scenario: Formatting a feature file with one or more DataTables 
    should align the pipe symbols.
    # This should work similarly to the ruby cucumber --autoformat argument;
    # notwithstanding the feature is being removed from there.
    Given a feature file 
        '''
        Feature: feature description
            In order to do something
            As someone
            I want something else to happen

        Scenario: scenario description
            Given something
                |Lorem|ipsum|dolor|sit|amet|
                |consectetur|adipiscing|elit|
            When an action is performed
                |sed|do|eiusmod|tempor|incididunt|ut|labore|et|dolore|magna|aliqua|
                |Ut|enim|ad|minim|veniam|
            Then something should be asserted
                |quis|nostrud|exercitation|ullamco|laboris|nisi|ut|aliquip|ex|ea|commodo|consequat|
                |Duis|aute|irure|dolor|in|reprehenderit|in|voluptate|velit|esse|cillum|dolore|eu|fugiat|nulla|pariatur|

        Scenario Outline: scenario description
            Given something with <param_1>
            And something with <param_2>
            Then check <param_3> is the output
            Examples:
                |Excepteur|sint|occaecat|cupidatat|non|proident|
                |sunt|in|culpa|qui|officia|deserunt|
        '''
    When I invoke the format function on the file 
    Then the feature file should look like this 
        '''
        Feature: feature description
            In order to do something
            As someone
            I want something else to happen

        Scenario: scenario description
            Given something
                | Lorem       | ipsum      | dolor | sit | amet |
                | consectetur | adipiscing | elit  |
            When an action is performed
                | sed | do   | eiusmod | tempor | incididunt | ut | labore | et | dolore | magna | aliqua |
                | Ut  | enim | ad      | minim  | veniam     |
            Then something should be asserted
                | quis | nostrud | exercitation | ullamco | laboris | nisi          | ut | aliquip   | ex    | ea   | commodo | consequat |
                | Duis | aute    | irure        | dolor   | in      | reprehenderit | in | voluptate | velit | esse | cillum  | dolore    | eu | fugiat | nulla | pariatur |

        Scenario Outline: scenario description
            Given something with <param_1>
            And something with <param_2>
            Then check <param_3> is the output
            Examples:
                | Excepteur | sint | occaecat | cupidatat | non     | proident |
                | sunt      | in   | culpa    | qui       | officia | deserunt |
        '''

rlogiacco commented 9 years ago

I agree this feature will bring extra value to the plugin: can you implement it?

Basically we'll have to determine the length of the longest element in each column then go back and the necessary padding to each row for each element in that column and repeat the whole process for each column.

Care should be taken to consider non rectangular tables, but we can leave that for a future improvement.

The source code hook for this should be CucumberFormatter.java file, though I'm not sure how the code can be linked to the formatter: some reasearch on the API is needed.

genthaler commented 9 years ago

I tried setting up Eclipse to build the project, but had all sorts of problems. Could you please add some info to the Contribute page on what versions of Eclipse, plugins, JVM etc are working for you?

rlogiacco commented 9 years ago

Hi Gunter, I just downloaded the latest and greatest Xtext bundle and, apart for a trivial error on one little missing bundle, everything worked fine... I'm currently using Eclipse Luna 64bit on a Window 7 64bit machine running a JDK 7 64bit, but I've succesfully built the project on a Linux 64bit and on a Windows XP 32bit machine in the past with no modifications and much older Eclipse and Xtext versions...

Can you please describe the errors you are getting?

On Wed, Apr 22, 2015 at 3:14 AM, Günther Enthaler notifications@github.com wrote:

I tried setting up Eclipse to build the project, but had all sorts of problems. Could you please add some info to the Contribute https://github.com/rlogiacco/Natural/wiki/Contribute page on what versions of Eclipse, plugins, JVM etc are working for you?

— Reply to this email directly or view it on GitHub https://github.com/rlogiacco/Natural/issues/39#issuecomment-94990976.

drkstr101 commented 4 years ago

An example of how this can be done may be found here: https://de.slideshare.net/meysholdt/xtexts-new-formatter-api

Unfortunately, it will involve some semi-complicated AST updates, so this will probably not make it into next. It is totally doable when we are ready for a major AST overhaul however.

drkstr101 commented 4 years ago

The capability now exits in next to do this, but the custom formatting rules need to be implemented. No change needed on Issue status.

github-actions[bot] commented 4 years ago

This issue has not been updated for a while: marking it as stale.