commit d5cd4b7c8018c21a7c4d6532d62588b495dce4a7
Author: Mauro Talevi <[email protected]>
AuthorDate: Wed, 27 Nov 2013 16:40:51 +0000
Commit: Mauro Talevi <[email protected]>
CommitDate: Wed, 27 Nov 2013 16:40:51 +0000
JBEHAVE-962: Support trimming of values after comments are removed.
diff --git a/jbehave-core/src/main/java/org/jbehave/core/model/TableUtils.java
b/jbehave-core/src/main/java/org/jbehave/core/model/TableUtils.java
index 43fdb49..e12cbae 100644
--- a/jbehave-core/src/main/java/org/jbehave/core/model/TableUtils.java
+++ b/jbehave-core/src/main/java/org/jbehave/core/model/TableUtils.java
@@ -18,7 +18,8 @@ public class TableUtils {
}
List<String> values = new ArrayList<String>();
for ( String value : rowAsString.split(regex.toString(),-1) ){
- String trimmed = trimValues ? value.trim() : value;
+ String stripped = StringUtils.substringBefore(value,
commentSeparator);
+ String trimmed = trimValues ? stripped.trim() : stripped;
values.add(StringUtils.substringBefore(trimmed, commentSeparator));
}
// ignore a leading and a trailing empty value
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 7a7778f..9657a48 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
@@ -19,7 +19,6 @@ import java.util.Properties;
import org.apache.commons.io.output.ByteArrayOutputStream;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
-import org.hamcrest.Matchers;
import org.jbehave.core.annotations.AsParameters;
import org.jbehave.core.annotations.Parameter;
import org.jbehave.core.model.ExamplesTable.RowNotFound;
@@ -35,8 +34,10 @@ import static org.codehaus.plexus.util.StringUtils.isBlank;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.not;
public class ExamplesTableBehaviour {
@@ -99,13 +100,29 @@ public class ExamplesTableBehaviour {
Map<String, String> values = row.values();
assertThat(values.size(), equalTo(2));
for (String column : values.keySet()) {
- assertThat(values.get(column),
Matchers.not(Matchers.containsString("#comment")));
+ assertThat(values.get(column),
not(containsString("#comment")));
}
}
assertThat(table.asString(), equalTo("|one|two|\n|11|12|\n|21|22|\n"));
}
@Test
+ public void shouldParseTableWithUntrimmedCommentsInValues() {
+ String tableWithEmptyValues = "{commentSeparator=#, trim=false}\n|one
#comment|two|\n |11 #comment|12 #comment|\n |21|22|\n";
+ ExamplesTable table = new ExamplesTable(tableWithEmptyValues);
+ assertThat(table.getRowCount(), equalTo(2));
+ for (Parameters row : table.getRowsAsParameters()) {
+ Map<String, String> values = row.values();
+ assertThat(values.size(), equalTo(2));
+ for (String column : values.keySet()) {
+ assertThat(values.get(column),
not(containsString("#comment")));
+ }
+ }
+ assertThat(table.asString(), equalTo("|one |two|\n|11 |12
|\n|21|22|\n"));
+ }
+
+
+ @Test
public void shouldParseEmptyTable() {
String tableAsString = "";
ExamplesTable table = new ExamplesTable(tableAsString);