Skip to content

Commit f0008cf

Browse files
committed
tests(textframe): Add truncate behavior test cases
why: Verify the new overflow_behavior="truncate" mode works correctly for width, height, and combined overflow scenarios. what: - Add overflow_behavior field to Case NamedTuple with default "error" - Add truncate_width test case (clips horizontal overflow) - Add truncate_height test case (clips vertical overflow) - Add truncate_both test case (clips both dimensions) - Update test to pass overflow_behavior to TextFrame constructor - Add snapshot baselines for new test cases
1 parent 984192d commit f0008cf

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

tests/textframe/__snapshots__/test_core.ambr

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,29 @@
2929
+---------------------+
3030
'''
3131
# ---
32+
# name: test_frame_rendering[truncate_both]
33+
'''
34+
+-----+
35+
|hello|
36+
|foo b|
37+
+-----+
38+
'''
39+
# ---
40+
# name: test_frame_rendering[truncate_height]
41+
'''
42+
+----------+
43+
|row 1 |
44+
+----------+
45+
'''
46+
# ---
47+
# name: test_frame_rendering[truncate_width]
48+
'''
49+
+-----+
50+
|hello|
51+
|foo |
52+
+-----+
53+
'''
54+
# ---
3255
# name: test_nested_serialization
3356
list([
3457
'''

tests/textframe/test_core.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class Case(t.NamedTuple):
2222
height: int
2323
lines: Sequence[str]
2424
expected_exception: type[BaseException] | None
25+
overflow_behavior: t.Literal["error", "truncate"] = "error"
2526

2627

2728
CASES: tuple[Case, ...] = (
@@ -46,6 +47,30 @@ class Case(t.NamedTuple):
4647
lines=[],
4748
expected_exception=None,
4849
),
50+
Case(
51+
id="truncate_width",
52+
width=5,
53+
height=2,
54+
lines=["hello world", "foo"],
55+
expected_exception=None,
56+
overflow_behavior="truncate",
57+
),
58+
Case(
59+
id="truncate_height",
60+
width=10,
61+
height=1,
62+
lines=["row 1", "row 2", "row 3"],
63+
expected_exception=None,
64+
overflow_behavior="truncate",
65+
),
66+
Case(
67+
id="truncate_both",
68+
width=5,
69+
height=2,
70+
lines=["hello world", "foo bar baz", "extra row"],
71+
expected_exception=None,
72+
overflow_behavior="truncate",
73+
),
4974
)
5075

5176

@@ -60,7 +85,11 @@ def test_frame_rendering(case: Case, snapshot: SnapshotAssertion) -> None:
6085
snapshot : SnapshotAssertion
6186
Syrupy snapshot fixture configured with TextFrameExtension.
6287
"""
63-
frame = TextFrame(content_width=case.width, content_height=case.height)
88+
frame = TextFrame(
89+
content_width=case.width,
90+
content_height=case.height,
91+
overflow_behavior=case.overflow_behavior,
92+
)
6493

6594
ctx: t.Any = (
6695
pytest.raises(case.expected_exception)

0 commit comments

Comments
 (0)