working on improving component loading
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import pytest
|
||||
|
||||
from myfasthtml.core.utils import flatten, make_html_id
|
||||
from myfasthtml.core.utils import flatten, make_html_id, pascal_to_snake, snake_to_pascal
|
||||
|
||||
|
||||
@pytest.mark.parametrize("input_args,expected,test_description", [
|
||||
@@ -64,3 +64,46 @@ def test_i_can_flatten(input_args, expected, test_description):
|
||||
])
|
||||
def test_i_can_have_valid_html_id(string, expected):
|
||||
assert make_html_id(string) == expected
|
||||
|
||||
|
||||
@pytest.mark.parametrize("input_str, expected, test_description", [
|
||||
("MyClass", "my_class", "simple PascalCase"),
|
||||
("myVariable", "my_variable", "camelCase"),
|
||||
("HTTPServer", "http_server", "short uppercase sequence"),
|
||||
("XMLHttpRequest", "xml_http_request", "long uppercase sequence"),
|
||||
("A", "a", "single letter"),
|
||||
("already_snake", "already_snake", "already snake_case"),
|
||||
("MyClass123", "my_class123", "with numbers"),
|
||||
("MyLongClassName", "my_long_class_name", "long class name"),
|
||||
(" MyClass ", "my_class", "with spaces to trim"),
|
||||
("iPhone", "i_phone", "starts lowercase then uppercase"),
|
||||
(None, None, "None input"),
|
||||
("", "", "empty string"),
|
||||
(" ", "", "only spaces"),
|
||||
])
|
||||
def test_i_can_convert_pascal_to_snake(input_str, expected, test_description):
|
||||
"""Test that pascal_to_snake correctly converts PascalCase/camelCase to snake_case."""
|
||||
result = pascal_to_snake(input_str)
|
||||
assert result == expected, f"Failed for test case: {test_description}"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("input_str, expected, test_description", [
|
||||
("my_class", "MyClass", "simple snake_case"),
|
||||
("my_long_class_name", "MyLongClassName", "long class name"),
|
||||
("a", "A", "single letter"),
|
||||
("myclass", "Myclass", "no underscore"),
|
||||
(" my_class ", "MyClass", "with spaces to trim"),
|
||||
("my__class", "MyClass", "multiple consecutive underscores"),
|
||||
("_my_class", "MyClass", "starts with underscore"),
|
||||
("my_class_", "MyClass", "ends with underscore"),
|
||||
("_my_class_", "MyClass", "starts and ends with underscore"),
|
||||
("my_class_123", "MyClass123", "with numbers"),
|
||||
(None, None, "None input"),
|
||||
("", "", "empty string"),
|
||||
(" ", "", "only spaces"),
|
||||
("___", "", "only underscores"),
|
||||
])
|
||||
def test_i_can_convert_snake_to_pascal(input_str, expected, test_description):
|
||||
"""Test that snake_to_pascal correctly converts snake_case to PascalCase."""
|
||||
result = snake_to_pascal(input_str)
|
||||
assert result == expected, f"Failed for test case: {test_description}"
|
||||
|
||||
Reference in New Issue
Block a user