diff --git a/pyls/_utils.py b/pyls/_utils.py index fa7d6cd5..1980b28f 100644 --- a/pyls/_utils.py +++ b/pyls/_utils.py @@ -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() diff --git a/test/test_utils.py b/test/test_utils.py index bf48920d..f8ece3a3 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -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'