diff options
-rw-r--r-- | tests/test_colors.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/test_colors.py b/tests/test_colors.py index 7365595..3cfedcb 100644 --- a/tests/test_colors.py +++ b/tests/test_colors.py @@ -1,7 +1,14 @@ +import string + from ansicolor import Colors +from ansicolor import blue +from ansicolor import colordiff from ansicolor import colorize from ansicolor import get_code from ansicolor import get_highlighter +from ansicolor import justify_formatted +from ansicolor import red +from ansicolor import strip_escapes from ansicolor import wrap_string @@ -29,6 +36,10 @@ def test_codes(): assert '\033[1;7;31m' == get_code(Colors.Red, bold=True, reverse=True) +def test_coloring(): + assert '\033[0;0;31m' + 'hi' + '\033[0;0m' == red('hi') + + def test_highlights(): # can I get a highlighter? assert Colors.Green == get_highlighter(0) @@ -50,3 +61,30 @@ def test_wrap_string(): + get_code(None) + "there" ) == wrap_string("Hi there", 3, Colors.Red) + + +def test_strip_escapes(): + assert "Hi there" == strip_escapes(wrap_string("Hi there", 3, Colors.Red)) + + assert strip_escapes( + colorize("Hi", None, bold=True) + + " there, " + + colorize("stranger", Colors.Green, bold=True) + ) == "Hi there, stranger" + + +def test_colordiff(): + x, y = colordiff("hi bob", "hi there", + color_x=Colors.Red, color_y=Colors.Blue) + + fx = lambda s: red(s, reverse=True) + fy = lambda s: blue(s, reverse=True) + + assert x == "hi " + fx("b") + fx("o") + fx("b") + assert y == "hi " + fy("t") + fy("h") + fy("e") + fy("r") + fy("e") + + +def test_justify_formatted(): + assert justify_formatted( + red("hi"), string.rjust, 10 + ) == " " + red("hi") |