Skip to content

Commit c183a48

Browse files
committed
TextFrame(feat[__post_init__]): Add dimension and fill_char validation
why: Prevent invalid TextFrame instances from being created with zero/negative dimensions or multi-character fill strings. what: - Add __post_init__ to validate content_width > 0 - Add __post_init__ to validate content_height > 0 - Add __post_init__ to validate fill_char is single character
1 parent 96d1823 commit c183a48

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

tests/textframe/core.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,24 @@ class TextFrame:
5959
fill_char: str = " "
6060
content: list[str] = field(default_factory=list)
6161

62+
def __post_init__(self) -> None:
63+
"""Validate frame dimensions and fill character.
64+
65+
Raises
66+
------
67+
ValueError
68+
If dimensions are not positive or fill_char is not a single character.
69+
"""
70+
if self.content_width <= 0:
71+
msg = "content_width must be positive"
72+
raise ValueError(msg)
73+
if self.content_height <= 0:
74+
msg = "content_height must be positive"
75+
raise ValueError(msg)
76+
if len(self.fill_char) != 1:
77+
msg = "fill_char must be a single character"
78+
raise ValueError(msg)
79+
6280
def set_content(self, lines: Sequence[str]) -> None:
6381
"""Set content, applying validation logic.
6482

0 commit comments

Comments
 (0)