Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bdd 如何阻止JBehave修剪多行参数?_Bdd_Jbehave - Fatal编程技术网

Bdd 如何阻止JBehave修剪多行参数?

Bdd 如何阻止JBehave修剪多行参数?,bdd,jbehave,Bdd,Jbehave,我有一个步骤需要检查某些消息。我使用了一个多行参数: Then I see welcome message: 'Welcome to our site! Some more text Even more text' 问题是消息的第一行和第二行末尾应该有空格(IDK why,但应该有)。JBehave会从每一行修剪空间。所以测试失败了 如何将其设置为不修剪此参数 我尝试过编写\n而不是实际的换行符,但没有换行符 还尝试在参数开头添加{trim=false},但它将其作为参数的一部分读取 做了

我有一个步骤需要检查某些消息。我使用了一个多行参数:

Then I see welcome message: 'Welcome to our site! 
Some more text 
Even more text'
问题是消息的第一行和第二行末尾应该有空格(IDK why,但应该有)。JBehave会从每一行修剪空间。所以测试失败了

如何将其设置为不修剪此参数

我尝试过编写
\n
而不是实际的换行符,但没有换行符

还尝试在参数开头添加{trim=false},但它将其作为参数的一部分读取


做了一些带引号的实验(使用“,”,无),这也没有帮助…

我已经测试过了,似乎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(“多行参数被!:$string包围的步骤”)
具有MultilnestringVersion2(字符串s)的公共无效步骤{
如果(s.以“!”开头){
s=s。子串(1);
}
如果(s.endsWith(“!”){
s=s.substring(0,s.length()-1);
}
字符串行[]=s.split(\\r?\\n”);
对于(int i=0;iSystem.out.format(“第%d行是:>>%s行,幸运的是最后一行在我的例子中没有空格。看起来行被IntelliJ截断了。我在每行的末尾添加了保护符号(
一些文本~\n
)”~,然后在步骤正文中被什么都没有替换。
    @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   

!