Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

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 · 8 comments
Closed

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

restagner opened this issue Aug 30, 2012 · 8 comments

Comments

@restagner
Copy link

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 |
@aslakhellesoy
Copy link
Contributor

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

@rlogiacco
Copy link

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.

@aslakhellesoy
Copy link
Contributor

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

@rlogiacco
Copy link

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

@aslakhellesoy
Copy link
Contributor

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

@rlogiacco
Copy link

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

@rlogiacco
Copy link

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.

@lock
Copy link

lock bot commented Oct 25, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Oct 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants