Skip to content

Commit

Permalink
Fix RenameTestCases renaming words starting with numbers and special …
Browse files Browse the repository at this point in the history
…chars (#546)

Fix RenameTestCases renaming words starting with numbers and special chars
  • Loading branch information
bhirsz authored Jun 28, 2023
1 parent 5ba1c66 commit 8743872
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 2 deletions.
30 changes: 30 additions & 0 deletions docs/releasenotes/4.4.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,33 @@ RenameKeywords does not remove whitespace after variable (#538)
will be transformed to::

Embedded ${variable} And Removed Underscores

RenameTestCases does not rename character in the middle of string (#545)
------------------------------------------------------------------------

Previous fix made it possible to capitalize words inside brackets (with ``capitalize_each_word=True``).
However it also applied to words with numbers and special characters::

*** Test Cases ***
Select 3rd Option
No Operation

With 1200x950
No Operation

Open 3-dot Menu
No Operation

would be transformed to::

*** Test Cases ***
Select 3Rd Option
No Operation

With 1200X950
No Operation

Open 3-Dot Menu
No Operation

Now ``RenameTestCases`` should only capitalize words after bracket and exclamation characters: "(", "[", "{", "!", "?".
9 changes: 7 additions & 2 deletions robotidy/transformers/RenameTestCases.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from robotidy.exceptions import InvalidParameterValueError
from robotidy.transformers import Transformer

IGNORE_CHARS = {"(", "[", "{", "!", "?"}


def cap_string_until_succeed(word: str):
"""
Expand All @@ -16,9 +18,12 @@ def cap_string_until_succeed(word: str):
capitalize = True
for char in word:
if capitalize:
char = char.upper()
if char.isupper():
# chars like numbers, -, dots, commas etc. will not change case, and we should not capitalize further
if char == char.upper() and char not in IGNORE_CHARS:
capitalize = False
else:
char = char.upper()
capitalize = not char.isupper()
yield char


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,12 @@ Remove special chars: ?$@

Capitalize words (after !special that's
No operation

Select 3rd Option
No Operation

With 1200x950
No Operation

Open 3-dot Menu
No Operation
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,12 @@ Remove special chars: ?$@

Capitalize words (after !special that's
No operation

Select 3rd Option
No Operation

With 1200x950
No Operation

Open 3-dot Menu
No Operation
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,12 @@ Remove special chars

Capitalize words (after !special that's
No operation

Select 3rd Option
No Operation

With 1200x950
No Operation

Open 3-dot Menu
No Operation
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,12 @@ Remove special chars: ?$@

Capitalize words (after !special that's
No operation

Select 3rd Option
No Operation

With 1200x950
No Operation

Open 3-dot Menu
No Operation
9 changes: 9 additions & 0 deletions tests/atest/transformers/RenameTestCases/expected/test.robot
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,12 @@ Remove special chars: ?$@

Capitalize words (after !special that's
No operation

Select 3rd Option
No Operation

With 1200x950
No Operation

Open 3-dot Menu
No Operation
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,12 @@ Remove Special Chars: ?$@

Capitalize Words (After !Special That's
No operation

Select 3rd Option
No Operation

With 1200x950
No Operation

Open 3-dot Menu
No Operation
9 changes: 9 additions & 0 deletions tests/atest/transformers/RenameTestCases/source/test.robot
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,12 @@ Remove special chars: ?$@

Capitalize words (after !special that's
No operation

Select 3rd Option
No Operation

With 1200x950
No Operation

Open 3-dot Menu
No Operation

0 comments on commit 8743872

Please sign in to comment.