Skip to content

Commit 612e605

Browse files
Add tests for extract_regex and shorten edge cases (#332)
1 parent 0cb0e85 commit 612e605

File tree

1 file changed

+28
-13
lines changed

1 file changed

+28
-13
lines changed

tests/test_utils.py

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,34 @@
1111

1212

1313
@pytest.mark.parametrize(
14-
("width", "expected"),
14+
("text", "width", "suffix", "expected"),
1515
[
16-
(-1, ValueError),
17-
(0, ""),
18-
(1, "."),
19-
(2, ".."),
20-
(3, "..."),
21-
(4, "f..."),
22-
(5, "fo..."),
23-
(6, "foobar"),
24-
(7, "foobar"),
16+
("foobar", -1, "...", ValueError),
17+
("foobar", 0, "...", ""),
18+
("foobar", 1, "...", "."),
19+
("foobar", 2, "...", ".."),
20+
("foobar", 3, "...", "..."),
21+
("foobar", 4, "...", "f..."),
22+
("foobar", 5, "...", "fo..."),
23+
("foobar", 6, "...", "foobar"),
24+
("foobar", 7, "...", "foobar"),
25+
("hello", 3, "…", "he…"),
26+
("hello", 4, "…", "hel…"),
27+
("test", 2, "->", "->"),
28+
("test", 3, "->", "t->"),
29+
("test", 4, "->", "test"),
30+
("", 0, "...", ""),
31+
("", 3, "...", ""),
2532
],
2633
)
27-
def test_shorten(width: int, expected: str | type[Exception]) -> None:
34+
def test_shorten(
35+
text: str, width: int, suffix: str, expected: str | type[Exception]
36+
) -> None:
2837
if isinstance(expected, str):
29-
assert shorten("foobar", width) == expected
38+
assert shorten(text, width, suffix=suffix) == expected
3039
else:
3140
with pytest.raises(expected):
32-
shorten("foobar", width)
41+
shorten(text, width, suffix=suffix)
3342

3443

3544
@pytest.mark.parametrize(
@@ -71,6 +80,12 @@ def test_shorten(width: int, expected: str | type[Exception]) -> None:
7180
False,
7281
[""sometext" & "moretext""],
7382
),
83+
(
84+
r"(?P<extract>\d+)",
85+
"no digits here",
86+
True,
87+
[],
88+
),
7489
],
7590
)
7691
def test_extract_regex(

0 commit comments

Comments
 (0)