diff options
author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2020-04-09 16:37:46 -0400 |
---|---|---|
committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2020-04-09 16:37:46 -0400 |
commit | d815d2cd19a24bac89bd19416fb2b7cd0dadfe03 (patch) | |
tree | 2570d13b2561822911b000b36519be742ec89345 /tests/test_utils.py | |
parent | 0d4be64b6ec76fcf5f87933293dbc7c134a32cf0 (diff) | |
download | cmd2-git-d815d2cd19a24bac89bd19416fb2b7cd0dadfe03.tar.gz |
Initial commit of table creation API
Diffstat (limited to 'tests/test_utils.py')
-rw-r--r-- | tests/test_utils.py | 45 |
1 files changed, 40 insertions, 5 deletions
diff --git a/tests/test_utils.py b/tests/test_utils.py index 7546184e..27bf4743 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -368,14 +368,49 @@ def test_align_text_fill_char_is_tab(): aligned = cu.align_text(text, cu.TextAlignment.LEFT, fill_char=fill_char, width=width) assert aligned == text + ' ' -def test_align_text_fill_char_has_color(): +def test_align_text_with_style(): from cmd2 import ansi - text = 'foo' - fill_char = ansi.fg.bright_yellow + '-' + ansi.fg.reset - width = 5 + # Single line with only left fill + text = ansi.style('line1', fg=ansi.fg.bright_blue) + fill_char = ansi.style('-', fg=ansi.fg.bright_yellow) + width = 6 + + aligned = cu.align_text(text, cu.TextAlignment.RIGHT, fill_char=fill_char, width=width) + + left_fill = ansi.RESET_ALL + fill_char + ansi.RESET_ALL + right_fill = ansi.RESET_ALL + line_1_text = ansi.fg.bright_blue + 'line1' + ansi.FG_RESET + + assert aligned == (left_fill + line_1_text + right_fill) + + # Single line with only right fill + text = ansi.style('line1', fg=ansi.fg.bright_blue) + fill_char = ansi.style('-', fg=ansi.fg.bright_yellow) + width = 6 + aligned = cu.align_text(text, cu.TextAlignment.LEFT, fill_char=fill_char, width=width) - assert aligned == text + fill_char * 2 + + left_fill = ansi.RESET_ALL + right_fill = ansi.RESET_ALL + fill_char + ansi.RESET_ALL + line_1_text = ansi.fg.bright_blue + 'line1' + ansi.FG_RESET + + assert aligned == (left_fill + line_1_text + right_fill) + + # Multiple lines to show that style is preserved across all lines. Also has left and right fill. + text = ansi.style('line1\nline2', fg=ansi.fg.bright_blue) + fill_char = ansi.style('-', fg=ansi.fg.bright_yellow) + width = 7 + + aligned = cu.align_text(text, cu.TextAlignment.CENTER, fill_char=fill_char, width=width) + + left_fill = ansi.RESET_ALL + fill_char + ansi.RESET_ALL + right_fill = ansi.RESET_ALL + fill_char + ansi.RESET_ALL + line_1_text = ansi.fg.bright_blue + 'line1' + line_2_text = ansi.fg.bright_blue + 'line2' + ansi.FG_RESET + + assert aligned == (left_fill + line_1_text + right_fill + '\n' + + left_fill + line_2_text + right_fill) def test_align_text_width_is_too_small(): text = 'foo' |