|
11 | 11 |
|
12 | 12 |
|
13 | 13 | @pytest.mark.parametrize( |
14 | | - ("width", "expected"), |
| 14 | + ("text", "width", "suffix", "expected"), |
15 | 15 | [ |
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, "...", ""), |
25 | 32 | ], |
26 | 33 | ) |
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: |
28 | 37 | if isinstance(expected, str): |
29 | | - assert shorten("foobar", width) == expected |
| 38 | + assert shorten(text, width, suffix=suffix) == expected |
30 | 39 | else: |
31 | 40 | with pytest.raises(expected): |
32 | | - shorten("foobar", width) |
| 41 | + shorten(text, width, suffix=suffix) |
33 | 42 |
|
34 | 43 |
|
35 | 44 | @pytest.mark.parametrize( |
@@ -71,6 +80,12 @@ def test_shorten(width: int, expected: str | type[Exception]) -> None: |
71 | 80 | False, |
72 | 81 | [""sometext" & "moretext""], |
73 | 82 | ), |
| 83 | + ( |
| 84 | + r"(?P<extract>\d+)", |
| 85 | + "no digits here", |
| 86 | + True, |
| 87 | + [], |
| 88 | + ), |
74 | 89 | ], |
75 | 90 | ) |
76 | 91 | def test_extract_regex( |
|
0 commit comments