Skip to content

Commit 1f49511

Browse files
committed
Added completion test to handle word break in a quoted token.
1 parent cf9243f commit 1f49511

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

tests/test_completion.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -915,6 +915,27 @@ def test_add_opening_quote_nothing_added(cmd2_app) -> None:
915915
assert not completions._quote_char
916916

917917

918+
def test_word_break_in_quote(cmd2_app) -> None:
919+
"""Test case where search text has a space and is in a quote."""
920+
921+
# Cmd2Completer still performs word breaks after a quote. Since space
922+
# is word-break character, it says the search text starts at 'S' and
923+
# passes that to the complete() function.
924+
text = 'S'
925+
line = 'test_basic "Ham S'
926+
endidx = len(line)
927+
begidx = endidx - len(text)
928+
929+
# Since the search text is within an opening quote, cmd2 will rebuild
930+
# the whole search token as 'Ham S' and match it to 'Ham Sandwich'.
931+
# But before it returns the results back to Cmd2Completer, it removes
932+
# anything before the original search text since this is what Cmd2Completer
933+
# expects. Therefore the actual match text is 'Sandwich'.
934+
expected = ["Sandwich"]
935+
completions = cmd2_app.complete(text, line, begidx, endidx)
936+
assert completions.to_strings() == Completions.from_values(expected).to_strings()
937+
938+
918939
def test_no_completer(cmd2_app) -> None:
919940
text = ''
920941
line = f'test_no_completer {text}'

0 commit comments

Comments
 (0)