Skip to content

Commit

Permalink
fix camel_to_underscore
Browse files Browse the repository at this point in the history
  • Loading branch information
youben11 committed Nov 12, 2019
1 parent 061f0cc commit e9996f7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pyls/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,5 @@ def is_process_alive(pid):


def camel_to_underscore(camelcase):
return re.sub('([A-Z]+)', r'_\1', camelcase).lower()
s1 = re.sub('([^_])([A-Z][a-z]+)', r'\1_\2', camelcase)
return re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1).lower()
6 changes: 6 additions & 0 deletions test/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,9 @@ def test_camel_to_underscore():
assert _utils.camel_to_underscore('camelCase') == 'camel_case'
assert _utils.camel_to_underscore('hangClosing') == 'hang_closing'
assert _utils.camel_to_underscore('ignore') == 'ignore'
assert _utils.camel_to_underscore('CamelCase') == 'camel_case'
assert _utils.camel_to_underscore('SomeLongCamelCase') == 'some_long_camel_case'
assert _utils.camel_to_underscore('already_using_underscore') == 'already_using_underscore'
assert _utils.camel_to_underscore('Using_only_someUnderscore') == 'using_only_some_underscore'
assert _utils.camel_to_underscore('Using_Only_Some_underscore') == 'using_only_some_underscore'
assert _utils.camel_to_underscore('ALL_UPPER_CASE') == 'all_upper_case'

0 comments on commit e9996f7

Please sign in to comment.