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

DataTable.toTable( List<String[]> ) and/or DataTable.toTable( List<Map<String,String>> ) #433

Closed
nalbion opened this issue Dec 5, 2012 · 4 comments

Comments

@nalbion
Copy link

nalbion commented Dec 5, 2012

The ruby implementation of cucumber allows you to call

Then /^compare table:$/ do | expected_table |
  expected_table.diff!( generate_array_of_hashes() )
end

It doesn't seem to be possible to do this in cucumber-jvm:

@Then("compare table")
public void compare_table( DataTable expectedTable ) {
  expectedTable.diff( generateListArraysOfStrings() ); // List<String[]>
  // or
  expectedTable.diff( generateListOfMaps() );  // List<Map<String,String>>
}

List<String[]>

When the first row of the List contains the column names, DataTable.diff(List) extracts these correctly using topCells().

TableConverter.toTable() ends up with

writer: { columnNames:(as provided in element 0),
               fieldNames: ["string", "string", "string"...]
               fieldValues: [rowN[0], rowN[1]...] }

and then ComplexTypeWriter.getValues() calls

   int index = fieldNames.indexOf(converter.map(columnName));

where columnName is correct, but index is evaluated as -1, so getValues() returns [, , , ,...] so .diff() displays a table of empty strings.

List<Map<String,String>>

TableConverter.toTable() ends up with

writer: { columnNames:(as provided in element 0),
               fieldNames: ["entry", "entry", "entry"...]
               fieldValues: [colName0, row1Value0, colName1, row1Value1...] }

and then ComplexTypeWriter.getValues() calls

   int index = fieldNames.indexOf(converter.map(columnName));

where columnName is correct, but index is evaluated as -1, so getValues() returns [, , , ,...] so .diff() displays a table of empty strings.

nalbion pushed a commit to nalbion/cucumber-jvm that referenced this issue Dec 5, 2012
…ng[]> ),

toTable( List<Map<String,Object>> ).
Added ArrayOfSingleValueWriter and MapWriter.
@nalbion
Copy link
Author

nalbion commented Dec 5, 2012

Implemented: nalbion@bc5c6d9

...I'm not sure why assertEquals( personTable(), tc.toTable(...) throws an exception...

The ruby implementation also allows columns to be in different orders and allows you to specify whether surplus/missing rows/columns should be allowed.

@aslakhellesoy
Copy link
Contributor

Are you planning to send a pull request for this? If you do, please follow the conventions in DEVELOPERS.md

@aslakhellesoy
Copy link
Contributor

Never mind, just spotted it. Would still be nice if you fixed the formatting.

@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

2 participants