fix to_snake_case and add tests (#2133)
This commit is contained in:
parent
61c9afd5a5
commit
c835ad0737
@ -122,7 +122,7 @@ def to_snake_case(text: str) -> str:
|
|||||||
The snake case string.
|
The snake case string.
|
||||||
"""
|
"""
|
||||||
s1 = re.sub("(.)([A-Z][a-z]+)", r"\1_\2", text)
|
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:
|
def to_camel_case(text: str) -> str:
|
||||||
|
@ -117,6 +117,8 @@ def test_indent(text: str, indent_level: int, expected: str, windows_platform: b
|
|||||||
("camelTwoHumps", "camel_two_humps"),
|
("camelTwoHumps", "camel_two_humps"),
|
||||||
("_start_with_underscore", "_start_with_underscore"),
|
("_start_with_underscore", "_start_with_underscore"),
|
||||||
("__start_with_double_underscore", "__start_with_double_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):
|
def test_to_snake_case(input: str, output: str):
|
||||||
|
Loading…
Reference in New Issue
Block a user