Merge pull request #77 from cyphar/multi-word-lookups

lookup: do not bail on first failed lookup with a word list
This commit is contained in:
Evgeniy Dushistov
2021-10-17 21:03:14 +03:00
committed by GitHub
2 changed files with 10 additions and 4 deletions

View File

@@ -219,12 +219,15 @@ try {
search_result rval = SEARCH_SUCCESS; search_result rval = SEARCH_SUCCESS;
gchar **p = get_impl(word_list); gchar **p = get_impl(word_list);
while (*p) { while (*p) {
if ((rval = lib.process_phrase(*p++, *io, non_interactive)) != SEARCH_SUCCESS) { search_result this_rval = lib.process_phrase(*p++, *io, non_interactive);
return rval; // If we encounter any error, save it but continue through the word
} // list to check all requested words.
if (rval == SEARCH_SUCCESS)
rval = this_rval;
} }
if (rval != SEARCH_SUCCESS)
return rval;
} else if (!non_interactive) { } else if (!non_interactive) {
std::string phrase; std::string phrase;
while (io->read(_("Enter word or phrase: "), phrase)) { while (io->read(_("Enter word or phrase: "), phrase)) {
if (lib.process_phrase(phrase.c_str(), *io) == SEARCH_FAILURE) if (lib.process_phrase(phrase.c_str(), *io) == SEARCH_FAILURE)

View File

@@ -22,4 +22,7 @@ test_json '[{"name": "Test synonyms", "wordcount": "2"},{"name": "Sample 1 test
test_json '[{"dict": "Test synonyms","word":"test","definition":"\u000aresult of test"}]' -x -j -n --data-dir "$TEST_DIR" foo test_json '[{"dict": "Test synonyms","word":"test","definition":"\u000aresult of test"}]' -x -j -n --data-dir "$TEST_DIR" foo
test_json '[]' -x -j -n --data-dir "$TEST_DIR" foobarbaaz test_json '[]' -x -j -n --data-dir "$TEST_DIR" foobarbaaz
# Test multiple searches, with the first failing.
test_json '[][{"dict": "Test synonyms","word":"test","definition":"\u000aresult of test"}]' -x -j -n --data-dir "$TEST_DIR" foobarbaaz foo
exit 0 exit 0