mirror of
https://github.com/Dushistov/sdcv.git
synced 2025-12-15 17:31:56 +00:00
tests: add multiple results integration test
Make sure we return all of the relevant results, even in cases with lots of results (larger than ENTR_PER_PAGE in the offset index) and where you have a synyonym and headword present for the same word. Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
This commit is contained in:
committed by
Evgeniy Dushistov
parent
4a9b1dae3d
commit
d054adb37c
BIN
tests/stardict-test_multiple_results-2.4.2/test.dict
Normal file
BIN
tests/stardict-test_multiple_results-2.4.2/test.dict
Normal file
Binary file not shown.
BIN
tests/stardict-test_multiple_results-2.4.2/test.idx
Normal file
BIN
tests/stardict-test_multiple_results-2.4.2/test.idx
Normal file
Binary file not shown.
7
tests/stardict-test_multiple_results-2.4.2/test.ifo
Normal file
7
tests/stardict-test_multiple_results-2.4.2/test.ifo
Normal file
@@ -0,0 +1,7 @@
|
||||
StarDict's dict ifo file
|
||||
version=3.0.0
|
||||
bookname=Test multiple results
|
||||
wordcount=246
|
||||
idxfilesize=5977
|
||||
synwordcount=124
|
||||
description=
|
||||
BIN
tests/stardict-test_multiple_results-2.4.2/test.syn
Normal file
BIN
tests/stardict-test_multiple_results-2.4.2/test.syn
Normal file
Binary file not shown.
@@ -18,7 +18,10 @@ test_json() {
|
||||
fi
|
||||
}
|
||||
|
||||
test_json '[{"name": "Test synonyms", "wordcount": "2"},{"name": "Sample 1 test dictionary", "wordcount": "1"},{"name": "test_dict", "wordcount": "1"}]' -x -j -l -n --data-dir "$TEST_DIR"
|
||||
test_json '[{"name": "Test synonyms", "wordcount": "2"},
|
||||
{"name": "Test multiple results", "wordcount": "246"},
|
||||
{"name": "Sample 1 test dictionary", "wordcount": "1"},
|
||||
{"name": "test_dict", "wordcount": "1"}]' -x -j -l -n --data-dir "$TEST_DIR"
|
||||
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
|
||||
|
||||
|
||||
67
tests/t_multiple_results
Executable file
67
tests/t_multiple_results
Executable file
@@ -0,0 +1,67 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
SDCV="$1"
|
||||
TEST_DIR="$2"
|
||||
|
||||
unset SDCV_PAGER
|
||||
unset STARDICT_DATA_DIR
|
||||
|
||||
test_json() {
|
||||
word="$1"
|
||||
jq_cmp="$2"
|
||||
result="$("$SDCV" --data-dir "$TEST_DIR" -exjn "$word" | sed 's|\\n|\\u000a|g')"
|
||||
cmp_result="$(echo "$result" | jq "$jq_cmp")"
|
||||
if [ "$cmp_result" != "true" ]; then
|
||||
echo "expected '$jq_cmp' to return true, but $result didn't"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Basic two-result search for the same headword.
|
||||
test_json bark \
|
||||
'. == [
|
||||
{"dict":"Test multiple results","word":"bark","definition":"\u000aThe harsh sound made by a dog."},
|
||||
{"dict":"Test multiple results","word":"bark","definition":"\u000aThe tough outer covering of trees and other woody plants."}
|
||||
]'
|
||||
|
||||
# Multi-result search where one word exists as both a synyonym and a separate
|
||||
# headword. This ensures that if there is a matching synyonym we don't skip the
|
||||
# regular search.
|
||||
test_json cat \
|
||||
'. == [
|
||||
{"dict":"Test multiple results","word":"cat","definition":"\u000aA cute animal which (rarely) barks."},
|
||||
{"dict":"Test multiple results","word":"lion","definition":"\u000aA larger cat which might bite your head off."},
|
||||
{"dict":"Test multiple results","word":"panther","definition":"\u000aI know very little about panthers, sorry."}
|
||||
]'
|
||||
|
||||
# Many-result search for a word that matches 120 distinct headwords.
|
||||
test_json many_headwords 'length == 120'
|
||||
test_json many_headwords 'all(.word == "many_headwords")'
|
||||
test_json many_headwords \
|
||||
'to_entries | map(.value.definition == "\u000aDefinition for [many_headwords] entry #\(.key+1) (same headword).") | all'
|
||||
|
||||
# Many-result search for 120 words that have the same synonym.
|
||||
test_json many_synonyms 'length == 120'
|
||||
test_json many_synonyms \
|
||||
'to_entries | map(.value.word == "many_synonyms-\(.key+101)") | all'
|
||||
test_json many_synonyms \
|
||||
'to_entries | map(.value.definition == "\u000aDefinition for [many_synonyms-\(.key+101)] (same synonym).") | all'
|
||||
|
||||
# Ensure that we don't return more than one result even if a word can be
|
||||
# resolved in more than one way.
|
||||
#
|
||||
# Most well-formed dictionaries don't have entries like this (it basically
|
||||
# requires you to have a dictionary where there is a synonym that is identical
|
||||
# to a word's headword or multiple identical synyonym entries).
|
||||
#
|
||||
# This entry was created by creating extra synonyms with different names then
|
||||
# modifying the .syn file manually.
|
||||
test_json many_resolution_paths \
|
||||
'. == [
|
||||
{"dict":"Test multiple results","word":"many_resolution_paths",
|
||||
"definition":"\u000aDefinition for [many_resolution_paths] headword (same word, multiple synonym entries)."}
|
||||
]'
|
||||
|
||||
exit 0
|
||||
Reference in New Issue
Block a user