Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Provide support for Data Tables with headings along the side #382

Closed
restagner opened this Issue Aug 30, 2012 · 7 comments

Comments

Projects
None yet
3 participants

Similar to classic Cucumber (Ruby version), Cucumber-JVM should support data tables with headings placed along the side. For example

Then the monetary amounts are:
| project total          | $1,000.00 |
| proposed project total | $3,000.00 |
| proposed subtotal      | $2,000.00 |
Owner

aslakhellesoy commented Oct 12, 2012

I'll accept a pull request for this. Suggestions:

  • Tell Cucumber to transpose the table with a @Transpose annotation before transforming it to List<Something>
  • Add a transpose() method to DataTable

I just needed this feature: if it's still on the radar I'll try to contribute it in, at least the DataTable.transpose() method implementation.

Owner

aslakhellesoy commented Nov 20, 2013

@rlogiacco sure, go for it! Please do it on s branch.

@aslakhellesoy sorry, what do you mean by s branch? I thought I had to fork and then submit a pull request...

Owner

aslakhellesoy commented Nov 20, 2013

@rlogiacco sorry I meant separate branch :-)
Yes, in your fork.

This is the transpose method idea, just to check if it meets general requirements

public DataTable transpose() {
    List<List<String>> transposed = new ArrayList<List<String>>();
        for (int i = 0; i < gherkinRows.size(); i++) {
        Row gherkinRow = gherkinRows.get(i);
        for (int j = 0; j < gherkinRow.getCells().size(); j++) {
            List<String> row = null;
            if (j < transposed.size()) {
                row = transposed.get(j);
            }
            if (row == null) {
                row = new ArrayList<String>();
                transposed.add(row);
            }
            // fixes non rectangular tables
            while (i > row.size()) {
                row.add(new String());
            }
            row.add(gherkinRow.getCells().get(j));
        }
    }
    return DataTable.create(transposed);
}

The idea here is to maintain the DataTable immutability and just change the raw representation. On the other hand it might be necessary to change the internally used constructor to accept an additional parameter reporting the table reading direction: that parameter should be in turn get linked to @Transposed to have the internal representation directly created 90 CCW rotated... That should provide the necessary support for vertically described entities, but I need some additional investigation/test.

Please note the necessity to fix non rectangular tables by adding leading empty cells whenever necessary: I hope this is the expected behavior, but I never used the Ruby version so I need some confirmation on that.

Any comment is very welcome :-D

I had to change a few things here and there adding a private constructor to DataTable and overloading a couple of methods to propagate the annotation value.

I've added some unit tests, I didn't try to cover the whole DataTable feature set after transposal as I believe my changes shouldn't impact existing features other than rotating the table itself CCW 90 degrees.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment