commit b7958982521edd01408c133724add04dc92dc5b2 Author: Mauro Talevi <mauro.tal...@aquilonia.org> AuthorDate: Fri Apr 27 13:31:34 2012 +0200 Commit: Mauro Talevi <mauro.tal...@aquilonia.org> CommitDate: Fri Apr 27 13:31:34 2012 +0200
JBEHAVE-722: Allow comments as first line of table. 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 101271e..a5cb508 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 @@ -110,8 +110,8 @@ import static java.util.regex.Pattern.compile; * </pre> * * The transformer needs to be registered by name via the - * {@link TableTransformers#useTransformer(String, TableTransformer)}. - * A few transformers are already registered by default in {@link TableTransformers}. + * {@link TableTransformers#useTransformer(String, TableTransformer)}. A few + * transformers are already registered by default in {@link TableTransformers}. * </p> * * <p> @@ -236,7 +236,7 @@ public class ExamplesTable { if (rowAsString.startsWith(properties.getProperty("ignorableSeparator")) || rowAsString.length() == 0) { // skip ignorable or empty lines continue; - } else if (row == 0) { + } else if (headers.isEmpty()) { headers.addAll(TableUtils.parseRow(rowAsString, properties.getProperty("headerSeparator"), trim)); } else { List<String> columns = TableUtils.parseRow(rowAsString, properties.getProperty("valueSeparator"), trim); 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 3bc07b5..f5c684b 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 @@ -43,7 +43,7 @@ public class ExamplesTableBehaviour { private String wikiTableAsString = "||one||two||\n" + "|11|12|\n" + "|21|22|\n"; - private String tableWithCommentsAsString = "|one|two|\n" + "|-- A comment --|\n" + "|11|12|\n" + private String tableWithCommentsAsString = "|---------|\n" + "|one|two|\n" + "|-- A comment --|\n" + "|11|12|\n" + "|-- Another comment --|\n" + "|21|22|\n"; @Test @@ -86,13 +86,6 @@ public class ExamplesTableBehaviour { } @Test - public void shouldParseTableWithCommentLines() { - ExamplesTable table = new ExamplesTable(tableWithCommentsAsString); - ensureColumnOrderIsPreserved(table); - assertThat(table.asString(), equalTo("|one|two|\n|11|12|\n|21|22|\n")); - } - - @Test public void shouldParseEmptyTable() { String tableAsString = ""; ExamplesTable table = new ExamplesTable(tableAsString); @@ -153,7 +146,8 @@ public class ExamplesTableBehaviour { @Test public void shouldParseTableWithSeparatorsSpecifiedViaProperties() { - String tableWithProperties = "{ignorableSeparator=!--,headerSeparator=!,valueSeparator=!}\n" + tableWithCommentsAsString.replace("|", "!"); + String tableWithProperties = "{ignorableSeparator=!--,headerSeparator=!,valueSeparator=!}\n" + + tableWithCommentsAsString.replace("|", "!"); ExamplesTable table = new ExamplesTable(tableWithProperties); Properties properties = table.getProperties(); assertThat(properties.size(), equalTo(3)); @@ -403,6 +397,14 @@ public class ExamplesTableBehaviour { } @Test + public void shouldIgnoreAllCommentLines() { + // ignore comment lines + ExamplesTable table = new ExamplesTable(tableWithCommentsAsString); + ensureColumnOrderIsPreserved(table); + assertThat(table.asString(), equalTo(tableAsString)); + } + + @Test public void shouldHandleWrongNumberOfColumns() { assertTableAsString("|a|b|\n|a|\n", "|a|b|\n|a||\n"); assertTableAsString("|a|b|\n|a|b|c|\n", "|a|b|\n|a|b|\n");