From b29daadfee18229d153e2a5fc82596ea6471ac6e Mon Sep 17 00:00:00 2001 From: delameter <0.delameter@gmail.com> Date: Mon, 6 Nov 2023 07:55:57 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9E=20FIX:=20`pt.fit('N',=201)`=20unex?= =?UTF-8?q?pected=20results?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pytermor/_version.py | 4 ++-- pytermor/common.py | 3 ++- tests/test_common.py | 16 ++++++++++++---- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/pytermor/_version.py b/pytermor/_version.py index 31f07e11..852791de 100644 --- a/pytermor/_version.py +++ b/pytermor/_version.py @@ -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" diff --git a/pytermor/common.py b/pytermor/common.py index 878ac331..a157ac7d 100644 --- a/pytermor/common.py +++ b/pytermor/common.py @@ -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: diff --git a/tests/test_common.py b/tests/test_common.py index 10cebe16..a2f57f89 100644 --- a/tests/test_common.py +++ b/tests/test_common.py @@ -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"), @@ -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,