Skip to content

Commit

Permalink
Fixes cucumber-attic#175. PrettyFormatter should not modify table, bu…
Browse files Browse the repository at this point in the history
…t safely work with it instead
  • Loading branch information
os97673 committed Apr 4, 2013
1 parent 279b083 commit 7e7ed34
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
23 changes: 11 additions & 12 deletions java/src/main/java/gherkin/formatter/PrettyFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ public void table(List<? extends Row> rows) {

private void prepareTable(List<? extends Row> rows) {
this.rows = rows;

// find the largest row
int columnCount = 0;
for (Row row : rows) {
Expand All @@ -295,22 +295,21 @@ private void prepareTable(List<? extends Row> rows) {
maxLengths = new int[columnCount];
for (int rowIndex = 0; rowIndex < rows.size(); rowIndex++) {
Row row = rows.get(rowIndex);
List<String> cells = row.getCells();
final List<String> cells = row.getCells();
for (int colIndex = 0; colIndex < columnCount; colIndex++) {

// check missing cells
if (colIndex >= cells.size()) {
cells.add("");
}
String cell = cells.get(colIndex);
int length = escapeCell(cell).length();
final String cell = getCellSafely(cells, colIndex);
final int length = escapeCell(cell).length();
cellLengths[rowIndex][colIndex] = length;
maxLengths[colIndex] = Math.max(maxLengths[colIndex], length);
}
}
rowIndex = 0;
}

private String getCellSafely(final List<String> cells, final int colIndex) {
return (colIndex < cells.size()) ? cells.get(colIndex) : "";
}

public void row(List<CellResult> cellResults) {
Row row = rows.get(rowIndex);
if (rowsAbove) {
Expand All @@ -337,11 +336,11 @@ public void row(List<CellResult> cellResults) {
break;
}
for (int colIndex = 0; colIndex < maxLengths.length; colIndex++) {
String cellText = escapeCell(row.getCells().get(colIndex));
String cellText = escapeCell(getCellSafely(row.getCells(), colIndex));
String status = null;
switch (row.getDiffType()) {
case NONE:
status = cellResults.get(colIndex).getStatus();
status = cellResults.size() < colIndex ? cellResults.get(colIndex).getStatus() : "skipped";
break;
case DELETE:
status = "skipped";
Expand Down Expand Up @@ -471,4 +470,4 @@ private static String indent(String s, String indentation) {
private static String escapeTripleQuotes(String s) {
return TRIPLE_QUOTES.matcher(s).replaceAll(ESCAPED_TRIPLE_QUOTES);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -171,5 +171,5 @@ private List<String> doFormatter(String feature) throws IOException {
return lines;

}

}

0 comments on commit 7e7ed34

Please sign in to comment.