I can add new columns

This commit is contained in:
2026-02-16 21:57:39 +01:00
parent f3e19743c8
commit 70915b2691
7 changed files with 142 additions and 78 deletions

View File

@@ -1,6 +1,6 @@
import pytest
from myfasthtml.core.utils import flatten, make_html_id, pascal_to_snake, snake_to_pascal
from myfasthtml.core.utils import flatten, make_html_id, pascal_to_snake, snake_to_pascal, make_unique_safe_id
@pytest.mark.parametrize("input_args,expected,test_description", [
@@ -57,6 +57,7 @@ def test_i_can_flatten(input_args, expected, test_description):
result = flatten(*input_args)
assert result == expected, f"Failed for test case: {test_description}"
@pytest.mark.parametrize("string, expected", [
("My Example String!", "My-Example-String_"),
("123 Bad ID", "id_123-Bad-ID"),
@@ -82,9 +83,9 @@ def test_i_can_have_valid_html_id(string, expected):
(" ", "", "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}"
"""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", [
@@ -104,6 +105,18 @@ def test_i_can_convert_pascal_to_snake(input_str, expected, test_description):
("___", "", "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}"
"""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}"
@pytest.mark.parametrize("name, existing_ids, expected", [
(None, [], None),
("MyClass", [], "myclass"),
("MyClass", ["myclass"], "myclass_1"),
("MyClass", ["myclass", "myclass_1"], "myclass_2"),
])
def test_make_unique_safe_id(name, existing_ids, expected):
assert make_unique_safe_id(name, existing_ids) == expected, (
f"Failed for name: {name}, existing_ids: {existing_ids}, expected: {expected}"
)