Skip to content

Commit 332e7a7

Browse files
committed
✨ Enhance ShortTruncatedStr tests to cover additional edge cases for string length and whitespace handling
1 parent 7713f06 commit 332e7a7

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

packages/models-library/tests/test_basic_types.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,24 @@ def test_short_truncated_string():
8181
assert (
8282
TypeAdapter(ShortTruncatedStr).validate_python("X" * curtail_length)
8383
== "X" * curtail_length
84-
)
84+
), "Max length string should remain intact"
8585

8686
assert (
8787
TypeAdapter(ShortTruncatedStr).validate_python("X" * (curtail_length + 1))
8888
== "X" * curtail_length
89-
)
89+
), "Overlong string should be truncated exactly to max length"
90+
91+
assert (
92+
TypeAdapter(ShortTruncatedStr).validate_python("X" * (curtail_length + 100))
93+
== "X" * curtail_length
94+
), "Much longer string should still truncate to exact max length"
95+
96+
# below limit
97+
assert TypeAdapter(ShortTruncatedStr).validate_python(
98+
"X" * (curtail_length - 1)
99+
) == "X" * (curtail_length - 1), "Under-length string should not be modified"
100+
101+
# spaces are trimmed
102+
assert (
103+
TypeAdapter(ShortTruncatedStr).validate_python(" " * (curtail_length + 1)) == ""
104+
), "Only-whitespace string should become empty string"

0 commit comments

Comments
 (0)