我正在写一个小 cucumber 特征文件,例如
Given the following # data
And I open the page
Then all fields are correct
我不想要
#
在上面被解释为注释,这将删除 data
之后。逃离
#
的官方小 cucumber 方式是什么?符号,如果有?我看过 official documentation ,还有这个 guide似乎都没有回答我的问题。我试过使用发明的 HTML 实体
&hash;
在我的解析器中,它可以工作并且很容易为其编写正则表达式。如果我使用官方 HTML 实体 #
或使用反斜杠转义(例如 \#
)任一选项本身都会包含 #
符号并使解析更加困难。然而,最终,如果可能的话,我宁愿使用官方方法,即使它有点难以实现。提前致谢!
最佳答案
ruby 和 java 实现中使用的语法可以在这里找到:https://github.com/cucumber/gherkin/blob/master/ragel/lexer_common.rl.erb
看起来似乎没有为注释定义任何转义,但是由于小 cucumber 是基于行的语法,我不希望在一个步骤后实际内联识别注释。与语法高亮相反
Given the following # data
When I open the page
我希望该步骤的内容包含所有内容,包括“#data”部分。
这也是我对 https://github.com/cucumber/cucumber/wiki/Gherkin#gherkin-syntax 处描述的解释
Comment lines are allowed anywhere in the file. They begin with zero or more spaces, followed by a hash sign (#) and some amount of text.
关于regex - 在 Gherkin/Cucumber 中转义注释 (#) 的官方方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26676543/