fix to_snake_case and add tests (#2133)

This commit is contained in:
Thomas Brandého 2023-11-06 21:13:28 +01:00 committed by GitHub
parent 61c9afd5a5
commit c835ad0737
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 1 deletions

View File

@ -122,7 +122,7 @@ def to_snake_case(text: str) -> str:
The snake case string.
"""
s1 = re.sub("(.)([A-Z][a-z]+)", r"\1_\2", text)
return re.sub("([a-z0-9])([A-Z])", r"\1_\2", s1).lower()
return re.sub("([a-z0-9])([A-Z])", r"\1_\2", s1).lower().replace("-", "_")
def to_camel_case(text: str) -> str:

View File

@ -117,6 +117,8 @@ def test_indent(text: str, indent_level: int, expected: str, windows_platform: b
("camelTwoHumps", "camel_two_humps"),
("_start_with_underscore", "_start_with_underscore"),
("__start_with_double_underscore", "__start_with_double_underscore"),
("kebab-case", "kebab_case"),
("double-kebab-case", "double_kebab_case"),
],
)
def test_to_snake_case(input: str, output: str):