commit 914969eb7e7363fd61948ede6074589e9e903cc7
Author:     Mauro Talevi <mauro.tal...@aquilonia.org>
AuthorDate: Wed, 27 Nov 2013 16:40:51 +0000
Commit:     Mauro Talevi <mauro.tal...@aquilonia.org>
CommitDate: Wed, 27 Nov 2013 16:41:04 +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 563e4d5..3790996 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);



Reply via email to