From d054adb37c635ececabc31b147c968a480d1891a Mon Sep 17 00:00:00 2001 From: Aleksa Sarai Date: Sun, 31 Oct 2021 18:35:34 +1100 Subject: [PATCH] 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 --- CMakeLists.txt | 1 + .../test.dict | Bin 0 -> 13757 bytes .../test.idx | Bin 0 -> 5977 bytes .../test.ifo | 7 ++ .../test.syn | Bin 0 -> 2228 bytes tests/t_json | 5 +- tests/t_multiple_results | 67 ++++++++++++++++++ 7 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 tests/stardict-test_multiple_results-2.4.2/test.dict create mode 100644 tests/stardict-test_multiple_results-2.4.2/test.idx create mode 100644 tests/stardict-test_multiple_results-2.4.2/test.ifo create mode 100644 tests/stardict-test_multiple_results-2.4.2/test.syn create mode 100755 tests/t_multiple_results diff --git a/CMakeLists.txt b/CMakeLists.txt index 45b324b..15da246 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -143,5 +143,6 @@ if (BUILD_TESTS) add_sdcv_shell_test(t_utf8input) add_sdcv_shell_test(t_datadir) add_sdcv_shell_test(t_return_code) + add_sdcv_shell_test(t_multiple_results) endif (BUILD_TESTS) diff --git a/tests/stardict-test_multiple_results-2.4.2/test.dict b/tests/stardict-test_multiple_results-2.4.2/test.dict new file mode 100644 index 0000000000000000000000000000000000000000..53fc2d55e7e79211858c6ed6cf668c3a4f717ce9 GIT binary patch literal 13757 zcmbu`&1&2*6b0ZsilCbW(jZ;^FALpt-(3m8$#}*lV{5QI9sKsyw9{P+@i|*dN5=5s z#kpws-nFW0rnysdIgdLvG`m*4uBuVHa(KEMuIo!VA39aeOFOBz^0S@#@u13HEmPah zs;Q~6bam}g%5GJsV>2#ujeb#YHB#66p*gBc*S~e@erl%nxIU=YW_tg#>DWw%>%q-( z+cWfsZc(p&&93DhWm6qY;lLJeu*S(L|Q;WC&1(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MXikcCfhtr`S3lTm}dDE+(S};pt>_THzcSH3(lKqXywuWYi#13TB!bL}rmugGio?8bq#; zQG>`EGHMVlBcle#*dPE4*OqXx;NWYi#ekBk~5`^l(5%1cHKQftVl oLFzaeHAp=mqXwxTWYi!X1T(NsOs|*Op2>AIXY=~xDRUS43zt!u+W-In literal 0 HcmV?d00001 diff --git a/tests/stardict-test_multiple_results-2.4.2/test.ifo b/tests/stardict-test_multiple_results-2.4.2/test.ifo new file mode 100644 index 0000000..b6ccf64 --- /dev/null +++ b/tests/stardict-test_multiple_results-2.4.2/test.ifo @@ -0,0 +1,7 @@ +StarDict's dict ifo file +version=3.0.0 +bookname=Test multiple results +wordcount=246 +idxfilesize=5977 +synwordcount=124 +description= diff --git a/tests/stardict-test_multiple_results-2.4.2/test.syn b/tests/stardict-test_multiple_results-2.4.2/test.syn new file mode 100644 index 0000000000000000000000000000000000000000..925160056038d21f179ad77491b402d2a2e1a7f5 GIT binary patch literal 2228 zcmajV=`$1n7{_rl{h?-Orx|9l+t~GDXG&7!NK&psgoGR+R4QlaaGyn@=pc0PK5cKz zd|r6oJTsr)HyDT}9Nnql|9_Yg2*napPe;OM(xS=XP~zD@G%510ICsJliG{+USW3J- zA8(IKI&uNYKrSMg$R*@5l7(a=SCAYe7s*5Nk*i1nat$d&t|LXr4df0lAMfB27p$@&IW;T9G!S9eId!Ae~4T@(Afh zdXQe^G4cd?iu57Rkmtw?q#qeT29Y6T7#TrcBBRI{GLF1LUL$Xix5xxCiA*8W$P6-z z%pvp00z9Qd{@5nZ?gZw~tkv(J| N`HB2Oej|U7gTJis5x4*V literal 0 HcmV?d00001 diff --git a/tests/t_json b/tests/t_json index 79db5f6..40d3128 100755 --- a/tests/t_json +++ b/tests/t_json @@ -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 diff --git a/tests/t_multiple_results b/tests/t_multiple_results new file mode 100755 index 0000000..07a4a70 --- /dev/null +++ b/tests/t_multiple_results @@ -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