如何阻止 JBehave 修剪多行参数?
How to stop JBehave from trimming multiline parameters?
我有一个步骤需要检查某些消息。我使用了多行参数:
Then I see welcome message: 'Welcome to our site!
Some more text
Even more text'
问题是消息在第一行和第二行的末尾应该有空格(IDK 为什么,但它应该)。 JBehave 每行有 trims 个空格。所以测试失败。
如何设置不为trim这个参数?
我试过写 \n
而不是实际的换行符,但它并没有被换行符
还尝试在参数的开头添加 {trim=false},但它会将其读取为参数的一部分。
用引号做了一些实验(用",',none),也没用...
我已经测试过了,似乎 JBehave 实际上在测试结束时截断了空格:
When some step with multitline parameter:first line has 10 spaces at the end
Second line has 6 spaces at the end
Third line has no spaces at the end, but fourth line has 8 spaces
Fifth line has 3 spaces, and Sixth line has only 7 spaces
@When("some step with multitline parameter:$lines")
public void stepWithMultilneString(String s) {
String lines [] = s.split("\r?\n");
for(int i = 0; i < lines.length; i++) {
System.out.format("Line %d is: >>%s<<\n", i+1, lines[i]);
}
}
Line 1 is: >>first line has 10 spaces at the end <<
Line 2 is: >>Second line has 6 spaces at the end <<
Line 3 is: >>Third line has no spaces at the end, but fourth line has 8 spaces<<
Line 4 is: >> <<
Line 5 is: >>Fifth line has 3 spaces, and Sixth line has only 7 spaces<<
When some step with multitline parameter:first line has 10 spaces at the end
Second line has 6 spaces at the end
Third line has no spaces at the end, but fourth line has 8 spaces
Fifth line has 3 spaces, and Sixth line has only 7 spaces
我建议绕过 - 在文本的开头和结尾使用分隔符 !
的步骤:
When step with multitline parameter surrounded by !:!first line has 10 spaces at the end
Second line has 6 spaces at the end
Third line has no spaces at the end, but fourth line has 8 spaces
Fifth line has 3 spaces, and Sixth line has only 7 spaces
!
@When("step with multitline parameter surrounded by !:$string")
public void stepWithMultilneStringVersion2(String s) {
if( s.startsWith("!")) {
s = s.substring(1);
}
if( s.endsWith("!")) {
s = s.substring(0, s.length()-1);
}
String lines [] = s.split("\r?\n");
for(int i = 0; i < lines.length; i++) {
System.out.format("Line %d is: >>%s<<\n", i+1, lines[i]);
}
}
Line 1 is: >>first line has 10 spaces at the end <<
Line 2 is: >>Second line has 6 spaces at the end <<
Line 3 is: >>Third line has no spaces at the end, but fourth line has 8 spaces<<
Line 4 is: >> <<
Line 5 is: >>Fifth line has 3 spaces, and Sixth line has only 7 spaces <<
Line 6 is: >> <<
When step with multitline parameter surrounded by !:!first line has 10 spaces at the end
Second line has 6 spaces at the end
Third line has no spaces at the end, but fourth line has 8 spaces
Fifth line has 3 spaces, and Sixth line has only 7 spaces
!
我有一个步骤需要检查某些消息。我使用了多行参数:
Then I see welcome message: 'Welcome to our site!
Some more text
Even more text'
问题是消息在第一行和第二行的末尾应该有空格(IDK 为什么,但它应该)。 JBehave 每行有 trims 个空格。所以测试失败。
如何设置不为trim这个参数?
我试过写 \n
而不是实际的换行符,但它并没有被换行符
还尝试在参数的开头添加 {trim=false},但它会将其读取为参数的一部分。
用引号做了一些实验(用",',none),也没用...
我已经测试过了,似乎 JBehave 实际上在测试结束时截断了空格:
When some step with multitline parameter:first line has 10 spaces at the end
Second line has 6 spaces at the end
Third line has no spaces at the end, but fourth line has 8 spaces
Fifth line has 3 spaces, and Sixth line has only 7 spaces
@When("some step with multitline parameter:$lines")
public void stepWithMultilneString(String s) {
String lines [] = s.split("\r?\n");
for(int i = 0; i < lines.length; i++) {
System.out.format("Line %d is: >>%s<<\n", i+1, lines[i]);
}
}
Line 1 is: >>first line has 10 spaces at the end <<
Line 2 is: >>Second line has 6 spaces at the end <<
Line 3 is: >>Third line has no spaces at the end, but fourth line has 8 spaces<<
Line 4 is: >> <<
Line 5 is: >>Fifth line has 3 spaces, and Sixth line has only 7 spaces<<
When some step with multitline parameter:first line has 10 spaces at the end
Second line has 6 spaces at the end
Third line has no spaces at the end, but fourth line has 8 spaces
Fifth line has 3 spaces, and Sixth line has only 7 spaces
我建议绕过 - 在文本的开头和结尾使用分隔符 !
的步骤:
When step with multitline parameter surrounded by !:!first line has 10 spaces at the end
Second line has 6 spaces at the end
Third line has no spaces at the end, but fourth line has 8 spaces
Fifth line has 3 spaces, and Sixth line has only 7 spaces
!
@When("step with multitline parameter surrounded by !:$string")
public void stepWithMultilneStringVersion2(String s) {
if( s.startsWith("!")) {
s = s.substring(1);
}
if( s.endsWith("!")) {
s = s.substring(0, s.length()-1);
}
String lines [] = s.split("\r?\n");
for(int i = 0; i < lines.length; i++) {
System.out.format("Line %d is: >>%s<<\n", i+1, lines[i]);
}
}
Line 1 is: >>first line has 10 spaces at the end <<
Line 2 is: >>Second line has 6 spaces at the end <<
Line 3 is: >>Third line has no spaces at the end, but fourth line has 8 spaces<<
Line 4 is: >> <<
Line 5 is: >>Fifth line has 3 spaces, and Sixth line has only 7 spaces <<
Line 6 is: >> <<
When step with multitline parameter surrounded by !:!first line has 10 spaces at the end
Second line has 6 spaces at the end
Third line has no spaces at the end, but fourth line has 8 spaces
Fifth line has 3 spaces, and Sixth line has only 7 spaces
!