Skip to content

Commit 53dd38a

Browse files
committed
Fixing utils.printable_name after tuning it earlier.
Changes done in revision 233d9a4 broke other tests. Fixed that and added related unit tests for printable_name itself.
1 parent 02870d2 commit 53dd38a

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/robot/utils/misc.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def printable_name(string, code_style=False):
6969
return ''
7070
if code_style and len(parts) == 1 \
7171
and not (string.isalpha() and string.islower()):
72-
parts = _camelCaseSplit(list(string))
72+
parts = _camelCaseSplit(list(parts[0]))
7373
return ' '.join(part[0].upper() + part[1:] for part in parts)
7474

7575

@@ -89,10 +89,8 @@ def _camelCaseSplit(chars):
8989
def _isCamelCaseBoundary(prev, char, next):
9090
if prev.isdigit():
9191
return not char.isdigit()
92-
if not prev.isalpha():
93-
return False
9492
if char.isupper():
95-
return not (prev.isupper() and (not next or next.isupper()))
93+
return next.islower() or prev.isalpha() and not prev.isupper()
9694
if char.isdigit():
9795
return not prev.isdigit()
9896
return False

utest/utils/test_misc.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ def test_printable_name(self):
7070
('ALLCAPS', 'ALLCAPS'),
7171
('name with spaces', 'Name With Spaces'),
7272
('more spaces', 'More Spaces'),
73+
(' leading and trailing ', 'Leading And Trailing'),
74+
(' 12number34 ', '12number34'),
7375
('Cases AND spaces', 'Cases AND Spaces'),
7476
('under_Score_name', 'Under_Score_name'),
7577
('camelCaseName', 'CamelCaseName'),
@@ -82,8 +84,12 @@ def test_printable_name(self):
8284
def test_printable_name_with_code_style(self):
8385
for inp, exp in [('simple', 'Simple'),
8486
('ALLCAPS', 'ALLCAPS'),
87+
('name with spaces', 'Name With Spaces'),
88+
(' more spaces ', 'More Spaces'),
8589
('under_score_name', 'Under Score Name'),
86-
('under_score and spaces', 'Under Score And Spaces'),
90+
('under__score and spaces', 'Under Score And Spaces'),
91+
('__leading and trailing_ __', 'Leading And Trailing'),
92+
('__12number34__', '12 Number 34'),
8793
('miXed_CAPS_nAMe', 'MiXed CAPS NAMe'),
8894
('with 89_numbers', 'With 89 Numbers'),
8995
('camelCaseName', 'Camel Case Name'),
@@ -93,6 +99,12 @@ def test_printable_name_with_code_style(self):
9399
('name42WithNumbers666', 'Name 42 With Numbers 666'),
94100
('name42WITHNumbers666', 'Name 42 WITH Numbers 666'),
95101
('12more34numbers', '12 More 34 Numbers'),
102+
('2KW', '2 KW'),
103+
('KW2', 'KW 2'),
104+
('xKW', 'X KW'),
105+
('KWx', 'K Wx'),
106+
(':KW', ':KW'),
107+
('KW:', 'KW:'),
96108
('foo-bar', 'Foo-bar'),
97109
('Foo-b:a;r!', 'Foo-b:a;r!'),
98110
('Foo-B:A;R!', 'Foo-B:A;R!'),

0 commit comments

Comments
 (0)