diff options
author | kotfu <kotfu@kotfu.net> | 2018-05-31 22:28:00 -0600 |
---|---|---|
committer | kotfu <kotfu@kotfu.net> | 2018-05-31 22:28:00 -0600 |
commit | eaf7415f010ab82688a0a30627a0efa2419f2837 (patch) | |
tree | d9c5431269257b1d732a88fee4fcbbe0c3f98392 /tests/test_bashcompletion.py | |
parent | 005882faeb058da201079b8496eb9322f7da0cfc (diff) | |
parent | 98522702b9131c41741af07f7acdf74b7f25d4d7 (diff) | |
download | cmd2-git-eaf7415f010ab82688a0a30627a0efa2419f2837.tar.gz |
Merge branch 'master' into plugin_functions
Diffstat (limited to 'tests/test_bashcompletion.py')
-rw-r--r-- | tests/test_bashcompletion.py | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/tests/test_bashcompletion.py b/tests/test_bashcompletion.py index 298bdf1e..e2c28fce 100644 --- a/tests/test_bashcompletion.py +++ b/tests/test_bashcompletion.py @@ -7,6 +7,7 @@ Released under MIT license, see LICENSE file """ import os import pytest +import shlex import sys from typing import List @@ -14,7 +15,7 @@ from cmd2.argparse_completer import ACArgumentParser, AutoCompleter try: - from cmd2.argcomplete_bridge import CompletionFinder + from cmd2.argcomplete_bridge import CompletionFinder, tokens_for_completion skip_reason1 = False skip_reason = '' except ImportError: @@ -230,3 +231,26 @@ Hint: out, err = capfd.readouterr() assert out == exp_out assert err == exp_err + +@pytest.mark.skipif(skip_reason1, reason=skip_reason) +def test_argcomplete_tokens_for_completion_simple(): + line = 'this is "a test"' + endidx = len(line) + + tokens, raw_tokens, begin_idx, end_idx = tokens_for_completion(line, endidx) + assert tokens == shlex.split(line) + assert raw_tokens == ['this', 'is', '"a test"'] + assert begin_idx == line.rfind("is ") + len("is ") + assert end_idx == end_idx + +@pytest.mark.skipif(skip_reason1, reason=skip_reason) +def test_argcomplete_tokens_for_completion_unclosed_quotee_exception(): + line = 'this is "a test' + endidx = len(line) + + tokens, raw_tokens, begin_idx, end_idx = tokens_for_completion(line, endidx) + + assert tokens == ['this', 'is', 'a test'] + assert raw_tokens == ['this', 'is', '"a test'] + assert begin_idx == line.rfind("is ") + len("is ") + 1 + assert end_idx == end_idx |