-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.sh
executable file
·58 lines (48 loc) · 908 Bytes
/
tests.sh
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/bash
source "$(dirname "$0")/jsonParser.sh"
function simpleNumber() {
data='{"a":1,"b":2}'
res=$(parseJson "$data" b)
exp=2
}
function simpleText() {
data='{"a":1,"b":"2"}'
res=$(parseJson "$data" b)
exp=2
}
function nestedSameKey() {
data='{"a":{"b":{"c":1}},"b":{"c":2}}'
res=$(parseJson "$data" b c)
exp=2
}
function numberInArray() {
data='{"a":[1,2]}'
res=$(parseJson "$data" a 1)
exp=2
}
function textInArray() {
data='{"a":[1,"2"]}'
res=$(parseJson "$data" a 1)
exp=2
}
function keyInObjectsArray() {
data='{"a":[{"b":1},{"b":2}]}'
res=$(parseJson "$data" a 1 b)
exp=2
}
function testIt() {
local name=$1
echo -n "TEST $name "
$name
if [ "$res" = "$exp" ]; then
echo OK
else
echo "FAIL expected='$exp' res='$res' data='$data'"
fi
}
testIt simpleNumber
testIt simpleText
testIt nestedSameKey
testIt numberInArray
testIt textInArray
testIt keyInObjectsArray