机器人框架 : 内置库 : 应该匹配 : 如何正确传递模式参数?



给定以下代码:

*** Test Cases ***
Use "Should Match"
[Documentation]     Should Match    string, pattern, msg=None, values=True, ignore_case=False
...                 Fails if the given string does not match the given pattern.
...                 Pattern matching is similar as matching files in a shell with *, ? and [chars] acting as
...                 wildcards. See the Glob patterns section for more information.
Should Match        string=Can find me here   pattern=me   msg='The overwriting error'  # fails unexpectedly
Should Match        string='Will match with star'   pattern=*
Should Match        string='Will match this'        pattern=[atx]his      # fails unexpectedly
Should Match        string='Will match with keyword'    pattern=?eyword   # fails unexpectedly

目标是使测试用例中的所有语句都通过。 目前,第一个语句失败并显示错误:

">

覆盖错误":"可以在此处找到我"与"我"不匹配

使用 Should Match 时,模式需要匹配整个字符串,而不仅仅是字符串的一部分。如果您希望第一个模式通过,则需要将其更改为*me*。第一颗星星将匹配所有内容与"我"一词,第二颗星星将匹配之后的所有内容。

其他模式也是如此。如果要在较大的字符串中查找模式,则需要在模式的任一侧添加*以匹配所有其他字符。

*** Test Cases ***
Use "Should Match"
Should Match        Can find me here           pattern=*me*
Should Match        'Will match with star'     pattern=*
Should Match        'Will match this'          pattern=*[atx]his*
Should Match        'Will match with keyword'  pattern=*?eyword*

最新更新