Skip to content

Commit

Permalink
Fix multipart BDD prefixes. #4515
Browse files Browse the repository at this point in the history
  • Loading branch information
pekkaklarck committed Oct 20, 2022
1 parent 314f398 commit 886ffcf
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 15 deletions.
12 changes: 11 additions & 1 deletion atest/robot/keywords/optional_given_when_then.robot
Expand Up @@ -46,7 +46,7 @@ Keyword can be used with and without prefix
Should Be Equal ${tc.kws[5].name} Then we are in Berlin city
Should Be Equal ${tc.kws[6].name} we are in Berlin city

In user keyword name with normal arguments and localized prefixes
Localized prefixes
${tc} = Check Test Case ${TEST NAME}
Should Be Equal ${tc.kws[0].name} Oletetaan we don't drink too many beers
Should Be Equal ${tc.kws[1].name} Kun we are in
Expand All @@ -55,5 +55,15 @@ In user keyword name with normal arguments and localized prefixes
Should Be Equal ${tc.kws[4].name} Niin we get this feature ready today
Should Be Equal ${tc.kws[5].name} ja we don't drink too many beers

Prefix consisting of multiple words
${tc} = Check Test Case ${TEST NAME}
Should Be Equal ${tc.kws[0].name} Étant donné multipart prefixes didn't work with RF 6.0
Should Be Equal ${tc.kws[1].name} Zakładając, że multipart prefixes didn't work with RF 6.0
Should Be Equal ${tc.kws[2].name} Diyelim ki multipart prefixes didn't work with RF 6.0
Should Be Equal ${tc.kws[3].name} Eğer ki multipart prefixes didn't work with RF 6.0
Should Be Equal ${tc.kws[4].name} O zaman multipart prefixes didn't work with RF 6.0
Should Be Equal ${tc.kws[5].name} В случай че multipart prefixes didn't work with RF 6.0
Should Be Equal ${tc.kws[6].name} Fie ca multipart prefixes didn't work with RF 6.0

Prefix must be followed by space
Check Test Case ${TEST NAME}
21 changes: 19 additions & 2 deletions atest/testdata/keywords/optional_given_when_then.robot
@@ -1,3 +1,9 @@
Language: French
Language: Polish
Language: Turkish
Language: Bulgarian
Language: Romanian

*** Settings ***
Resource resources/optional_given_when_then.robot

Expand Down Expand Up @@ -42,21 +48,29 @@ Keyword can be used with and without prefix
Then we are in Berlin city
we are in Berlin city

In user keyword name with normal arguments and localized prefixes
Localized prefixes
Oletetaan we don't drink too many beers
Kun we are in museum cafe
mutta we don't drink too many beers
Ja time does not run out
Niin we get this feature ready today
ja we don't drink too many beers

Prefix consisting of multiple words
Étant donné multipart prefixes didn't work with RF 6.0
Zakładając, że multipart prefixes didn't work with RF 6.0
Diyelim ki multipart prefixes didn't work with RF 6.0
Eğer ki multipart prefixes didn't work with RF 6.0
O zaman multipart prefixes didn't work with RF 6.0
В случай че multipart prefixes didn't work with RF 6.0
Fie ca multipart prefixes didn't work with RF 6.0

Prefix must be followed by space
[Documentation] FAIL
... No keyword with name 'Givenwe don't drink too many beers' found. Did you mean:
... ${SPACE*4}We Don't Drink Too Many Beers
Givenwe don't drink too many beers


*** Keywords ***
We don't drink too many beers
No Operation
Expand All @@ -83,3 +97,6 @@ We ${x} This ${thing} Implemented

We Go To ${somewhere}
Should Be Equal ${somewhere} walking tour

Multipart prefixes didn't work with RF 6.0
No Operation
23 changes: 11 additions & 12 deletions src/robot/running/namespace.py
Expand Up @@ -295,20 +295,19 @@ def _get_runner(self, name):
if not runner:
runner = self._get_implicit_runner(name)
if not runner:
runner = self._get_bdd_style_runner(name)
runner = self._get_bdd_style_runner(name, self.languages.bdd_prefixes)
return runner

def _get_bdd_style_runner(self, name):
parts = name.split(maxsplit=1)
if len(parts) < 2:
return None
prefix, keyword = parts
if prefix.title() in self.languages.bdd_prefixes:
runner = self._get_runner(keyword)
if runner:
runner = copy.copy(runner)
runner.name = name
return runner
def _get_bdd_style_runner(self, name, prefixes):
parts = name.split()
for index in range(1, len(parts)):
prefix = ' '.join(parts[:index]).title()
if prefix in prefixes:
runner = self._get_runner(' '.join(parts[index:]))
if runner:
runner = copy.copy(runner)
runner.name = name
return runner
return None

def _get_implicit_runner(self, name):
Expand Down

0 comments on commit 886ffcf

Please sign in to comment.