wordlist: fix "1-word- TAB" case

This commit is contained in:
Brian Warner 2017-04-06 15:05:37 -07:00
parent ddc6319bf6
commit 67d53f1388
3 changed files with 9 additions and 2 deletions

View File

@ -114,7 +114,7 @@ class CodeInputter(object):
# improve the user experience. # improve the user experience.
self.bcft(ih.when_wordlist_is_available) # blocks on CLAIM self.bcft(ih.when_wordlist_is_available) # blocks on CLAIM
# and we're completing on words now # and we're completing on words now
debug(" getting words") debug(" getting words (%s)" % (words,))
completions = [nameplate+"-"+c completions = [nameplate+"-"+c
for c in self.bcft(ih.get_word_completions, words)] for c in self.bcft(ih.get_word_completions, words)]

View File

@ -172,7 +172,10 @@ class PGPWordList(object):
completions = set() completions = set()
for word in words: for word in words:
if word.startswith(last_partial_word): if word.startswith(last_partial_word):
suffix = prefix[:-lp] + word if lp == 0:
suffix = prefix + word
else:
suffix = prefix[:-lp] + word
# append a hyphen if we expect more words # append a hyphen if we expect more words
if count+1 < num_words: if count+1 < num_words:
suffix += "-" suffix += "-"

View File

@ -10,6 +10,10 @@ class Completions(unittest.TestCase):
self.assertEqual(gc("ar", 2), {"armistice-", "article-"}) self.assertEqual(gc("ar", 2), {"armistice-", "article-"})
self.assertEqual(gc("armis", 2), {"armistice-"}) self.assertEqual(gc("armis", 2), {"armistice-"})
self.assertEqual(gc("armistice", 2), {"armistice-"}) self.assertEqual(gc("armistice", 2), {"armistice-"})
lots = gc("armistice-", 2)
self.assertEqual(len(lots), 256, lots)
first = list(lots)[0]
self.assert_(first.startswith("armistice-"), first)
self.assertEqual(gc("armistice-ba", 2), self.assertEqual(gc("armistice-ba", 2),
{"armistice-baboon", "armistice-backfield", {"armistice-baboon", "armistice-backfield",
"armistice-backward", "armistice-banjo"}) "armistice-backward", "armistice-banjo"})