Skip to content

Commit 13ebc1d

Browse files
codewizdaveclaude
andcommitted
Add tests for Template type
Add comprehensive tests for Template including: - Basic string concatenation - Using type variables - Single part - Empty string - Multiple parts forming paths Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 2025008 commit 13ebc1d

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

packages/typemap/tests/test_type_eval.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
Slice,
4949
SpecialFormEllipsis,
5050
StrConcat,
51+
Template,
5152
UpdateClass,
5253
Uppercase,
5354
)
@@ -2723,3 +2724,51 @@ class Child(Base):
27232724
Literal["name"],
27242725
]
27252726
)
2727+
2728+
2729+
##############
2730+
# Template tests
2731+
2732+
2733+
def test_template_basic():
2734+
"""Test Template concatenates string literals."""
2735+
2736+
result = eval_typing(Template[Literal["hello"], Literal["world"]])
2737+
assert result == Literal["helloworld"]
2738+
2739+
2740+
def test_template_with_variable():
2741+
"""Test Template with a type variable."""
2742+
2743+
Resource = Literal["users"]
2744+
result = eval_typing(Template[Literal["/"], Resource, Literal["/id"]])
2745+
assert result == Literal["/users/id"]
2746+
2747+
2748+
def test_template_single_part():
2749+
"""Test Template with a single part."""
2750+
2751+
result = eval_typing(Template[Literal["hello"]])
2752+
assert result == Literal["hello"]
2753+
2754+
2755+
def test_template_empty():
2756+
"""Test Template with empty string."""
2757+
2758+
result = eval_typing(Template[Literal[""], Literal["hello"]])
2759+
assert result == Literal["hello"]
2760+
2761+
2762+
def test_template_multiple_parts():
2763+
"""Test Template with multiple parts forming a path."""
2764+
2765+
result = eval_typing(
2766+
Template[
2767+
Literal["api"],
2768+
Literal["/"],
2769+
Literal["v1"],
2770+
Literal["/"],
2771+
Literal["users"],
2772+
]
2773+
)
2774+
assert result == Literal["api/v1/users"]

0 commit comments

Comments
 (0)