commit 50b47f5f2222b8ec849a4002fd1389f157f4c95f
Author: Alex Lehmann <[email protected]>
AuthorDate: Tue Jan 24 21:08:33 2012 +0100
Commit: Alex Lehmann <[email protected]>
CommitDate: Tue Jan 24 21:08:33 2012 +0100
JBEHAVE-711 empty lines in example tables should be ignored
add check for empty line as test case
diff --git
a/jbehave-core/src/main/java/org/jbehave/core/model/ExamplesTable.java
b/jbehave-core/src/main/java/org/jbehave/core/model/ExamplesTable.java
index 30a0921..784165e 100755
--- a/jbehave-core/src/main/java/org/jbehave/core/model/ExamplesTable.java
+++ b/jbehave-core/src/main/java/org/jbehave/core/model/ExamplesTable.java
@@ -153,8 +153,8 @@ public class ExamplesTable {
String[] rows = splitInRows(stripProperties(tableAsString.trim()));
for (int row = 0; row < rows.length; row++) {
String rowAsString = rows[row];
- if (rowAsString.startsWith(ignorableSeparator)) {
- // skip rows that start with ignorable separator
+ if (rowAsString.startsWith(ignorableSeparator) ||
rowAsString.length()==0) {
+ // skip empty lines and rows that start with ignorable
separator
continue;
} else if (row == 0) {
List<String> columns = columnsFor(rowAsString,
headerSeparator);
@@ -196,7 +196,7 @@ public class ExamplesTable {
private List<String> columnsFor(String row, String separator) {
List<String> columns = new ArrayList<String>();
- // use split limit -1 to ensure that empty strings will not be
discarted
+ // use split limit -1 to ensure that empty strings will not be
discarded
for (String column : row.split(buildRegex(separator), -1)) {
columns.add(valueOf(column));
}
diff --git
a/jbehave-core/src/test/java/org/jbehave/core/model/ExamplesTableBehaviour.java
b/jbehave-core/src/test/java/org/jbehave/core/model/ExamplesTableBehaviour.java
index d5450fc..c3a7037 100755
---
a/jbehave-core/src/test/java/org/jbehave/core/model/ExamplesTableBehaviour.java
+++
b/jbehave-core/src/test/java/org/jbehave/core/model/ExamplesTableBehaviour.java
@@ -352,6 +352,15 @@ public class ExamplesTableBehaviour {
assertThat(out.toString(), equalTo(tableAsString));
}
+ @Test
+ public void shouldIgnoreEmptyLines() throws Exception {
+ // ignore blank line
+ String tableWithEmptyLine = "|one|two|\n|a|b|\n\n|c|d|\n";
+ ExamplesTable table = new ExamplesTable(tableWithEmptyLine);
+ assertThat(table.getRowCount(), equalTo(2));
+ assertThat(table.asString(), equalTo("|one|two|\n|a|b|\n|c|d|\n"));
+ }
+
public Date convertDate(String value) throws ParseException {
return new SimpleDateFormat("dd/MM/yyyy").parse(value);
}