Skip to content

Commit 9852270

Browse files
authored
Merge pull request #425 from python-cmd2/unit_tests
Add a couple unit tests for tokens_for_completion in argcomplete_bridge.py
2 parents 26c9219 + 8ca52ba commit 9852270

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

tests/test_bashcompletion.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@
77
"""
88
import os
99
import pytest
10+
import shlex
1011
import sys
1112
from typing import List
1213

1314
from cmd2.argparse_completer import ACArgumentParser, AutoCompleter
1415

1516

1617
try:
17-
from cmd2.argcomplete_bridge import CompletionFinder
18+
from cmd2.argcomplete_bridge import CompletionFinder, tokens_for_completion
1819
skip_reason1 = False
1920
skip_reason = ''
2021
except ImportError:
@@ -230,3 +231,26 @@ def test_fail_alt_stderr(parser1, capfd, mock):
230231
out, err = capfd.readouterr()
231232
assert out == exp_out
232233
assert err == exp_err
234+
235+
@pytest.mark.skipif(skip_reason1, reason=skip_reason)
236+
def test_argcomplete_tokens_for_completion_simple():
237+
line = 'this is "a test"'
238+
endidx = len(line)
239+
240+
tokens, raw_tokens, begin_idx, end_idx = tokens_for_completion(line, endidx)
241+
assert tokens == shlex.split(line)
242+
assert raw_tokens == ['this', 'is', '"a test"']
243+
assert begin_idx == line.rfind("is ") + len("is ")
244+
assert end_idx == end_idx
245+
246+
@pytest.mark.skipif(skip_reason1, reason=skip_reason)
247+
def test_argcomplete_tokens_for_completion_unclosed_quotee_exception():
248+
line = 'this is "a test'
249+
endidx = len(line)
250+
251+
tokens, raw_tokens, begin_idx, end_idx = tokens_for_completion(line, endidx)
252+
253+
assert tokens == ['this', 'is', 'a test']
254+
assert raw_tokens == ['this', 'is', '"a test']
255+
assert begin_idx == line.rfind("is ") + len("is ") + 1
256+
assert end_idx == end_idx

0 commit comments

Comments
 (0)