-
Notifications
You must be signed in to change notification settings - Fork 0
/
test2.sh
executable file
·54 lines (45 loc) · 1.02 KB
/
test2.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
#!/bin/sh
. ./lib/jq_stack2.lib.sh
. ./lib/jq_stack2_modcall.lib.sh
. ./lib/jq_stack2_modload.lib.sh
. ./lib/jq_stack2_oneline.lib.sh
export JQ_STACK2_MODDIR="../jsondiff/lib"
#jq -rc '["jq", .option, (.functiondef + .call)]|@sh'
jqmod2jqargs() {
jq -rc '
[
"jq",
.option,
( (.functiondef|join("\n")) + .call )
]|@sh'
}
test2a_() {
{
echo '{"option": "-c"}'
echo '{"name":"sortallarrays"}'
echo '{"function": '"$(jq -cR . < test2-function-jq.def | jq -s .)"'}'
echo '{"modload": "sortallarrays"}'
echo '{"call":".|sortallarrays|."}'
} | jq_stack2 run
}
test2a() {
eval "jq $(test2a_)"
}
test1a() {
jq_stack init
jq_stack option -c
jq_stack modcall sortallarrays '.|sortallarrays|.'
jq_stack run
}
test2b() {
jq_stack2 oneline -c sortallarrays: '.|sortallarrays|.'
}
test1b() {
jq_stack oneline -c sortallarrays: '.|sortallarrays|.'
}
checktest() {
read result;
[ "$result" = '["1","2","3"]' ] && echo ok || echo fail
}
echo '["3", "1", "2"]' | test2a | checktest
echo '["3", "1", "2"]' | test2b | checktest