diff options
author | robot-piglet <[email protected]> | 2025-09-11 19:12:15 +0300 |
---|---|---|
committer | robot-piglet <[email protected]> | 2025-09-11 19:43:09 +0300 |
commit | 91708f49a58e3c0a1a3cf0a60c268c2d5b474a3e (patch) | |
tree | 9dbcd5cd1811b171ca7636600287d72327ef98ec /contrib/python/prompt-toolkit/py3/tests | |
parent | f4413504c29db8e1e7cce3a2103e89ecb4073271 (diff) |
Intermediate changes
commit_hash:87ab6d7772f084decaa30c0cb439a3e0c000406e
Diffstat (limited to 'contrib/python/prompt-toolkit/py3/tests')
4 files changed, 76 insertions, 0 deletions
diff --git a/contrib/python/prompt-toolkit/py3/tests/test_formatted_text.py b/contrib/python/prompt-toolkit/py3/tests/test_formatted_text.py index 60f9cdf459b..a111a7f20b2 100644 --- a/contrib/python/prompt-toolkit/py3/tests/test_formatted_text.py +++ b/contrib/python/prompt-toolkit/py3/tests/test_formatted_text.py @@ -89,6 +89,46 @@ def test_ansi_formatting(): assert isinstance(to_formatted_text(value), FormattedText) +def test_ansi_dim(): + # Test dim formatting + value = ANSI("\x1b[2mhello\x1b[0m") + + assert to_formatted_text(value) == [ + ("dim", "h"), + ("dim", "e"), + ("dim", "l"), + ("dim", "l"), + ("dim", "o"), + ] + + # Test dim with other attributes + value = ANSI("\x1b[1;2;31mhello\x1b[0m") + + assert to_formatted_text(value) == [ + ("ansired bold dim", "h"), + ("ansired bold dim", "e"), + ("ansired bold dim", "l"), + ("ansired bold dim", "l"), + ("ansired bold dim", "o"), + ] + + # Test dim reset with code 22 + value = ANSI("\x1b[1;2mhello\x1b[22mworld\x1b[0m") + + assert to_formatted_text(value) == [ + ("bold dim", "h"), + ("bold dim", "e"), + ("bold dim", "l"), + ("bold dim", "l"), + ("bold dim", "o"), + ("", "w"), + ("", "o"), + ("", "r"), + ("", "l"), + ("", "d"), + ] + + def test_ansi_256_color(): assert to_formatted_text(ANSI("\x1b[38;5;124mtest")) == [ ("#af0000", "t"), diff --git a/contrib/python/prompt-toolkit/py3/tests/test_print_formatted_text.py b/contrib/python/prompt-toolkit/py3/tests/test_print_formatted_text.py index 7d0e99a3350..3c692440143 100644 --- a/contrib/python/prompt-toolkit/py3/tests/test_print_formatted_text.py +++ b/contrib/python/prompt-toolkit/py3/tests/test_print_formatted_text.py @@ -91,3 +91,22 @@ def test_html_with_style(): f.data == "\x1b[0m\x1b[?7h\x1b[0;32mhello\x1b[0m \x1b[0;1mworld\x1b[0m\r\n\x1b[0m" ) + + [email protected](is_windows(), reason="Doesn't run on Windows yet.") +def test_print_formatted_text_with_dim(): + """ + Test that dim formatting works correctly. + """ + f = _Capture() + style = Style.from_dict( + { + "dimtext": "dim", + } + ) + tokens = FormattedText([("class:dimtext", "dim text")]) + + pt_print(tokens, style=style, file=f, color_depth=ColorDepth.DEFAULT) + + # Check that the ANSI dim escape code (ESC[2m) is in the output + assert "\x1b[0;2m" in f.data or "\x1b[2m" in f.data diff --git a/contrib/python/prompt-toolkit/py3/tests/test_style.py b/contrib/python/prompt-toolkit/py3/tests/test_style.py index d0a4790b8a8..ad9b90eaba6 100644 --- a/contrib/python/prompt-toolkit/py3/tests/test_style.py +++ b/contrib/python/prompt-toolkit/py3/tests/test_style.py @@ -22,6 +22,7 @@ def test_style_from_dict(): blink=False, reverse=False, hidden=False, + dim=False, ) assert style.get_attrs_for_style_str("class:a") == expected @@ -36,6 +37,7 @@ def test_style_from_dict(): blink=True, reverse=True, hidden=False, + dim=False, ) assert style.get_attrs_for_style_str("class:b") == expected @@ -50,6 +52,7 @@ def test_style_from_dict(): blink=False, reverse=False, hidden=False, + dim=False, ) assert style.get_attrs_for_style_str("#ff0000") == expected @@ -64,6 +67,7 @@ def test_style_from_dict(): blink=False, reverse=False, hidden=False, + dim=False, ) assert style.get_attrs_for_style_str("class:a #00ff00") == expected @@ -77,6 +81,7 @@ def test_style_from_dict(): blink=False, reverse=False, hidden=False, + dim=False, ) assert style.get_attrs_for_style_str("#00ff00 class:a") == expected @@ -101,6 +106,7 @@ def test_class_combinations_1(): blink=False, reverse=False, hidden=False, + dim=False, ) assert style.get_attrs_for_style_str("class:a class:b") == expected assert style.get_attrs_for_style_str("class:a,b") == expected @@ -131,6 +137,7 @@ def test_class_combinations_2(): blink=False, reverse=False, hidden=False, + dim=False, ) assert style.get_attrs_for_style_str("class:a class:b") == expected assert style.get_attrs_for_style_str("class:a,b") == expected @@ -147,6 +154,7 @@ def test_class_combinations_2(): blink=False, reverse=False, hidden=False, + dim=False, ) assert style.get_attrs_for_style_str("class:b class:a") == expected assert style.get_attrs_for_style_str("class:b,a") == expected @@ -173,6 +181,7 @@ def test_substyles(): blink=False, reverse=False, hidden=False, + dim=False, ) assert style.get_attrs_for_style_str("class:a") == expected @@ -186,6 +195,7 @@ def test_substyles(): blink=False, reverse=False, hidden=False, + dim=False, ) assert style.get_attrs_for_style_str("class:a.b") == expected assert style.get_attrs_for_style_str("class:a.b.c") == expected @@ -201,6 +211,7 @@ def test_substyles(): blink=False, reverse=False, hidden=False, + dim=False, ) assert style.get_attrs_for_style_str("class:b") == expected assert style.get_attrs_for_style_str("class:b.a") == expected @@ -215,6 +226,7 @@ def test_substyles(): blink=False, reverse=False, hidden=False, + dim=False, ) assert style.get_attrs_for_style_str("class:b.c") == expected assert style.get_attrs_for_style_str("class:b.c.d") == expected @@ -234,6 +246,7 @@ def test_swap_light_and_dark_style_transformation(): blink=False, reverse=False, hidden=False, + dim=False, ) after = Attrs( color="ffbbbb", @@ -245,6 +258,7 @@ def test_swap_light_and_dark_style_transformation(): blink=False, reverse=False, hidden=False, + dim=False, ) assert transformation.transform_attrs(before) == after @@ -260,6 +274,7 @@ def test_swap_light_and_dark_style_transformation(): blink=False, reverse=False, hidden=False, + dim=False, ) after = Attrs( color="ansibrightred", @@ -271,6 +286,7 @@ def test_swap_light_and_dark_style_transformation(): blink=False, reverse=False, hidden=False, + dim=False, ) assert transformation.transform_attrs(before) == after diff --git a/contrib/python/prompt-toolkit/py3/tests/test_style_transformation.py b/contrib/python/prompt-toolkit/py3/tests/test_style_transformation.py index e4eee7c7b1c..0651e7fa8b8 100644 --- a/contrib/python/prompt-toolkit/py3/tests/test_style_transformation.py +++ b/contrib/python/prompt-toolkit/py3/tests/test_style_transformation.py @@ -17,6 +17,7 @@ def default_attrs(): blink=False, reverse=False, hidden=False, + dim=False, ) |