File: t_json

package info (click to toggle)
sdcv 0.5.5-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 596 kB
  • sloc: cpp: 3,082; sh: 226; xml: 23; makefile: 10
file content (32 lines) | stat: -rwxr-xr-x 1,048 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/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": "Russian-English Dictionary (ru-en)", "wordcount": "415144"},
            {"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

# 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