diff options
| author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2021-03-02 13:49:28 -0500 |
|---|---|---|
| committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2021-03-02 13:49:28 -0500 |
| commit | 2ab91a81787aff9c0ecc8426a83be5a00a6e2e6b (patch) | |
| tree | 3117fa6a15cbf71d1783b2411085667468b665af /tests | |
| parent | 4da77c4cb0756191ee13f3c0003a2b04863b73ae (diff) | |
| download | cmd2-git-2ab91a81787aff9c0ecc8426a83be5a00a6e2e6b.tar.gz | |
Added support for ANSI styles and newlines in tab completion results
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test_ansi.py | 15 | ||||
| -rw-r--r-- | tests/test_argparse_completer.py | 23 |
2 files changed, 28 insertions, 10 deletions
diff --git a/tests/test_ansi.py b/tests/test_ansi.py index 7ebda497..1797a047 100644 --- a/tests/test_ansi.py +++ b/tests/test_ansi.py @@ -20,7 +20,20 @@ def test_strip_style(): def test_style_aware_wcswidth(): base_str = HELLO_WORLD ansi_str = ansi.style(base_str, fg='green') - assert ansi.style_aware_wcswidth(ansi_str) != len(ansi_str) + assert ansi.style_aware_wcswidth(HELLO_WORLD) == ansi.style_aware_wcswidth(ansi_str) + + assert ansi.style_aware_wcswidth('i have a tab\t') == -1 + assert ansi.style_aware_wcswidth('i have a newline\n') == -1 + + +def test_widest_line(): + text = ansi.style('i have\n3 lines\nThis is the longest one', fg='green') + assert ansi.widest_line(text) == ansi.style_aware_wcswidth("This is the longest one") + + text = "I'm just one line" + assert ansi.widest_line(text) == ansi.style_aware_wcswidth(text) + + assert ansi.widest_line('i have a tab\t') == -1 def test_style_none(): diff --git a/tests/test_argparse_completer.py b/tests/test_argparse_completer.py index efda7660..75f24b3e 100644 --- a/tests/test_argparse_completer.py +++ b/tests/test_argparse_completer.py @@ -24,6 +24,7 @@ from cmd2.utils import ( from .conftest import ( complete_tester, + normalize, run_cmd, ) @@ -720,8 +721,12 @@ def test_completion_items(ac_app, num_aliases, show_description): assert len(ac_app.completion_matches) == num_aliases assert len(ac_app.display_matches) == num_aliases - # If show_description is True, the alias's value will be in the display text - assert ('help' in ac_app.display_matches[0]) == show_description + assert bool(ac_app.formatted_completions) == show_description + if show_description: + # If show_description is True, the table will show both the alias name and result + first_result_line = normalize(ac_app.formatted_completions)[1] + assert 'fake_alias0' in first_result_line + assert 'help' in first_result_line @pytest.mark.parametrize( @@ -842,7 +847,7 @@ def test_completion_items_arg_header(ac_app): begidx = endidx - len(text) complete_tester(text, line, begidx, endidx, ac_app) - assert "DESC_HEADER" in ac_app.completion_header + assert "DESC_HEADER" in normalize(ac_app.formatted_completions)[0] # Test when metavar is a string text = '' @@ -851,7 +856,7 @@ def test_completion_items_arg_header(ac_app): begidx = endidx - len(text) complete_tester(text, line, begidx, endidx, ac_app) - assert ac_app.STR_METAVAR in ac_app.completion_header + assert ac_app.STR_METAVAR in normalize(ac_app.formatted_completions)[0] # Test when metavar is a tuple text = '' @@ -861,7 +866,7 @@ def test_completion_items_arg_header(ac_app): # We are completing the first argument of this flag. The first element in the tuple should be the column header. complete_tester(text, line, begidx, endidx, ac_app) - assert ac_app.TUPLE_METAVAR[0].upper() in ac_app.completion_header + assert ac_app.TUPLE_METAVAR[0].upper() in normalize(ac_app.formatted_completions)[0] text = '' line = 'choices --tuple_metavar token_1 {}'.format(text) @@ -870,7 +875,7 @@ def test_completion_items_arg_header(ac_app): # We are completing the second argument of this flag. The second element in the tuple should be the column header. complete_tester(text, line, begidx, endidx, ac_app) - assert ac_app.TUPLE_METAVAR[1].upper() in ac_app.completion_header + assert ac_app.TUPLE_METAVAR[1].upper() in normalize(ac_app.formatted_completions)[0] text = '' line = 'choices --tuple_metavar token_1 token_2 {}'.format(text) @@ -880,7 +885,7 @@ def test_completion_items_arg_header(ac_app): # We are completing the third argument of this flag. It should still be the second tuple element # in the column header since the tuple only has two strings in it. complete_tester(text, line, begidx, endidx, ac_app) - assert ac_app.TUPLE_METAVAR[1].upper() in ac_app.completion_header + assert ac_app.TUPLE_METAVAR[1].upper() in normalize(ac_app.formatted_completions)[0] def test_completion_items_descriptive_header(ac_app): @@ -895,7 +900,7 @@ def test_completion_items_descriptive_header(ac_app): begidx = endidx - len(text) complete_tester(text, line, begidx, endidx, ac_app) - assert ac_app.CUSTOM_DESC_HEADER in ac_app.completion_header + assert ac_app.CUSTOM_DESC_HEADER in normalize(ac_app.formatted_completions)[0] # This argument did not provide a descriptive header, so it should be DEFAULT_DESCRIPTIVE_HEADER text = '' @@ -904,7 +909,7 @@ def test_completion_items_descriptive_header(ac_app): begidx = endidx - len(text) complete_tester(text, line, begidx, endidx, ac_app) - assert DEFAULT_DESCRIPTIVE_HEADER in ac_app.completion_header + assert DEFAULT_DESCRIPTIVE_HEADER in normalize(ac_app.formatted_completions)[0] @pytest.mark.parametrize( |
