Skip to content

Commit 44fc8d1

Browse files
committed
Increase unit test coverage of argcomplete_bridge.py
Added a couple unit tests for tokens_for_completion() function.
1 parent 7000604 commit 44fc8d1

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

tests/test_bashcompletion.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77
"""
88
import os
99
import pytest
10+
import shlex
1011
import sys
1112
from typing import List
1213

14+
from cmd2.argcomplete_bridge import tokens_for_completion
1315
from cmd2.argparse_completer import ACArgumentParser, AutoCompleter
1416

1517

@@ -230,3 +232,25 @@ def test_fail_alt_stderr(parser1, capfd, mock):
230232
out, err = capfd.readouterr()
231233
assert out == exp_out
232234
assert err == exp_err
235+
236+
237+
def test_argcomplete_tokens_for_completion_simple():
238+
line = 'this is "a test"'
239+
endidx = len(line)
240+
241+
tokens, raw_tokens, begin_idx, end_idx = tokens_for_completion(line, endidx)
242+
assert tokens == shlex.split(line)
243+
assert raw_tokens == ['this', 'is', '"a test"']
244+
assert begin_idx == line.rfind("is ") + len("is ")
245+
assert end_idx == end_idx
246+
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)