mirror of
https://github.com/Dushistov/sdcv.git
synced 2025-12-15 17:31:56 +00:00
Due to the lack of deinflection support in StarDict, users might want to be able to create a list of possible deinflections and search each one to see if there is a dictionary entry for that deinflection. Being able to do this in one sdcv invocation is far more preferable to calling sdcv once for each candidate due to the performance cost of doing so. The most obvious language that would benefit from this is Japanese, but I'm sure other folks would prefer this. In order to make this use-case better supported -- try to look up every word in the provided list of words before existing with an error if any one of the words failed to be looked up. Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
29 lines
872 B
Bash
Executable File
29 lines
872 B
Bash
Executable File
#!/bin/sh
|
|
|
|
set -e
|
|
|
|
SDCV="$1"
|
|
TEST_DIR="$2"
|
|
|
|
unset SDCV_PAGER
|
|
unset STARDICT_DATA_DIR
|
|
|
|
test_json() {
|
|
EXPECTED=$(echo "$1" | jq 'sort')
|
|
shift
|
|
RESULT=$($SDCV "$@" | jq 'sort')
|
|
if [ "$EXPECTED" != "$RESULT" ]; then
|
|
echo "expected $EXPECTED but got $RESULT"
|
|
exit 1
|
|
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 '[{"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 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
|