diff options
author | Martin Matusiak <numerodix@gmail.com> | 2014-03-08 13:53:06 +0100 |
---|---|---|
committer | Martin Matusiak <numerodix@gmail.com> | 2014-03-08 13:53:06 +0100 |
commit | 8c338d2570fdb942cbed066ff816a1921a36a1b6 (patch) | |
tree | 9029ea2caed81f18f79377eff96e39c019db4fbf /tests | |
parent | c1aee16c57031ddbc86fd41010a32f67dd96212d (diff) | |
download | ansicolor-8c338d2570fdb942cbed066ff816a1921a36a1b6.tar.gz |
add more color tests
Diffstat (limited to 'tests')
-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") |