-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathreadme-test.sh
55 lines (49 loc) · 1.44 KB
/
readme-test.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
alias echo='builtin echo'
function ok() {
json='{ "users": [ { "name": "Amy", "age": 12 }, { "name": "Bill", "age": 42 } ] }'
expected="$(echo)$(echo -E "$2")"
results="$(echo && echo -E "$json" | ./$1 && echo)"
if [[ "$expected" == "$results" ]]; then
echo "OK ${test}"
else
echo "NOT OK ${test}"
echo " DIFF:"
diff -y <(echo -E "$expected") <(echo -$ "$results")
exit 1
fi
}
test="Empty Search"
ok 'jason' '
this["users"][0]["name"] "Amy"
this["users"][0]["age"] 12
this["users"][0] { "name": "Amy", "age": 12 }
this["users"][1]["name"] "Bill"
this["users"][1]["age"] 42
this["users"][1] { "name": "Bill", "age": 42 }
this["users"] [ { "name": "Amy", "age": 12 }, { "name": "Bill", "age": 42 } ]
this { "users": [ { "name": "Amy", "age": 12 }, { "name": "Bill", "age": 42 } ] }
'
test="Anchored Search"
ok 'jason this.users' '
this["users"] [ { "name": "Amy", "age": 12 }, { "name": "Bill", "age": 42 } ]
'
test="Unanchored Search"
ok 'jason users' '
this["users"] [ { "name": "Amy", "age": 12 }, { "name": "Bill", "age": 42 } ]
'
test="Anchor with Subscript"
ok 'jason this["users"]' '
this["users"] [ { "name": "Amy", "age": 12 }, { "name": "Bill", "age": 42 } ]
'
test="Map Operator"
ok 'jason users:name' '
this["users"][0]["name"] "Amy"
this["users"][1]["name"] "Bill"
'
test="Asterisk"
ok 'jason users[*][*]' '
this["users"][0]["name"] "Amy"
this["users"][0]["age"] 12
this["users"][1]["name"] "Bill"
this["users"][1]["age"] 42
'