Przeglądaj źródła

fix to_snake_case and add tests (#2133)

Thomas Brandého 1 rok temu
rodzic
commit
c835ad0737
2 zmienionych plików z 3 dodań i 1 usunięć
  1. 1 1
      reflex/utils/format.py
  2. 2 0
      tests/utils/test_format.py

+ 1 - 1
reflex/utils/format.py

@@ -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:

+ 2 - 0
tests/utils/test_format.py

@@ -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):