Skip to content

Commit

Permalink
🐞 FIX: pt.fit('N', 1) unexpected results
Browse files Browse the repository at this point in the history
  • Loading branch information
delameter committed Nov 6, 2023
1 parent 4606372 commit b29daad
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
4 changes: 2 additions & 2 deletions pytermor/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
# (c) 2022-2023. A. Shavykin <0.delameter@gmail.com>
# Licensed under GNU Lesser General Public License v3.0
# -----------------------------------------------------------------------------
__version__ = '2.106.4.dev0'
__updated__ = "2023-10-22 07:10:13+03:00"
__version__ = '2.106.5.dev0'
__updated__ = "2023-11-06 07:55:41+03:00"
3 changes: 2 additions & 1 deletion pytermor/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ def fit(
raise ValueError("Fill cannot be an empty string")

max_len = max(0, max_len)
if max_len <= (ov_len := len(overflow)):
ov_len = len(overflow)
if max_len <= ov_len and max_len < len(s):
return fit("", max_len, align, overflow="", fill=overflow)

if (fill_len := max_len - len(s)) >= 0:
Expand Down
16 changes: 12 additions & 4 deletions tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ class TestCutAndFit:
("1234567890", 1, None, "‥", " ", "‥"),
("1234567890", 0, None, "‥", " ", ""),
("", 0, None, "", " ", ""),
("1", 1, Align.LEFT, "‥", " ", "1"),
("12", 2, Align.LEFT, "‥", " ", "12"),
("123", 3, Align.LEFT, "‥", " ", "123"),
("1234", 3, Align.LEFT, "‥", " ", "12‥"),
("123", 4, Align.LEFT, "‥", " ", "123 "),
("1234567890", 12, Align.CENTER, "‥", " ", " 1234567890 "),
("1234567890", 10, Align.CENTER, "‥", " ", "1234567890"),
("1234567890", 9, Align.CENTER, "‥", " ", "1234‥7890"),
Expand Down Expand Up @@ -167,10 +172,13 @@ class TestCutAndFit:
("@", 6, Align.LEFT, "", "|¯|_", "@|¯|_|"),
("@", 6, Align.RIGHT, "", "|¯|_", "_|¯|_@"),
("@", 6, Align.CENTER, "", "|¯|_", "|¯@¯|_"),
("@", 2, Align.LEFT, "<|>", " ", "<|"),
("@", 2, Align.RIGHT, "<|>", " ", "|>"),
("@", 2, Align.CENTER, "<|>", " ", "<>"),
("@", 3, Align.CENTER, "<|>", " ", "<|>"),
("@", 2, Align.LEFT, "<|>", " ", "@ "),
("@@", 1, Align.LEFT, "<|>", " ", "<"),
("@@", 2, Align.LEFT, "<|>", " ", "@@"),
("@@@", 2, Align.LEFT, "<|>", " ", "<|"),
("@@@", 2, Align.RIGHT, "<|>", " ", "|>"),
("@@@", 2, Align.CENTER, "<|>", " ", "<>"),
("@@@@", 3, Align.CENTER, "<|>", " ", "<|>"),
("|", 7, Align.CENTER, "", "<>", "<><|><>"),
],
ids=format_test_params,
Expand Down

0 comments on commit b29daad

Please sign in to comment.