简体   繁体   English

带有 cucumber 的正则表达式与字符串不匹配

[英]Regular expression with cucumber doesn't match the string

I'm writing in Java and using cucumber with Eclipse to search for specific words.我正在写 Java 并使用 cucumber 和 Eclipse 来搜索特定的单词。 The requirements are as below:要求如下:

// Pattern distinguished. // 模式区分。
// Should match the string starting with:test_splitter arg // 应该匹配以 test_splitter arg 开头的字符串
// Where should match the following positive examples // 哪里应该匹配下面的正例
// and not negative examples. // 而不是负面的例子。 Note: any string not in the注意:任何不在
// positive or negative examples can be accepted or rejected. // 正面或负面的例子可以被接受或拒绝。

The positive words are (spill, Sponge, tap, rebuild) and negative ones are (si, egregious, Foul, Test, top, ta)积极的词是 (spill, Sponge, tap, rebuild),消极的词是 (si, egregious, Foul, Test, top, ta)

by writing the regular expression in the Stepdefs.java file, this is what I wrote通过在 Stepdefs.java 文件中编写正则表达式,这就是我写的

@When("^test_splitter (?=.*?\bspill\b)(?=.*?\bSponge\b)(?=.*?\btap\b)(?=.*?\brebuilld\b)((?!si|egregious|Foul|Test|ta).)*$")
public void test_splitter(String match) throws Throwable {
    System.out.println("test_splitter true for: " + match);
}

now when I write tests (in Gherkin language) for this method in the Test.feature file the tests fail, which should all pass )现在,当我在 Test.feature 文件中为这个方法编写测试(用小黄瓜语言)时,测试失败了,应该都通过了)

Scenario: test regular expressions that should pass
  When test_splitter spill
  When test_splitter Sponge
  When test_splitter tap
  When test_splitter rebuild
  When test_splitter2 spill
  When test_splitter2 Sponge
  When test_splitter2 tap
  When test_splitter2 rebuild

What is the problem with my regex?我的正则表达式有什么问题? How can I write the regex in a better way?如何以更好的方式编写正则表达式?

i think the test_splitter tap and test_splitter2 tap are failing.我认为 test_splitter tap 和 test_splitter2 tap 失败了。 At the end of your regular expression change "ta" to "top".在正则表达式的末尾,将“ta”更改为“top”。 Then all your tests should pass and failed scenarios will fail.然后你所有的测试都应该通过,失败的场景将失败。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM