-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.sh
executable file
·46 lines (34 loc) · 947 Bytes
/
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
#!/bin/sh -eu
# SPDX-License-Identifier: WTFPL
# shellcheck enable=
cd "$(dirname "$0")"
got=$(mktemp sorted.XXXXXX)
trap 'rm "$got"' EXIT
indent () {
python3 -m json.tool --indent 2
}
init () {
./flatten-json.py "$@" | indent > "$got"
}
check () {
indent | diff -u - "$got"
}
# flatten
init < example-normal.json
check < example-flat.json
# --expand
init --expand < example-flat.json
check < example-normal.json
# --separator, flatten
# XXX unfortunately there are slashes in json value so a basic sed isn't enough
init --separator : < example-normal.json
sed -e s@/@:@g -e "s@<:@</@" < example-flat.json | check
# --separator, --expand
sed -e s@/@:@g -e "s@<:@</@" < example-normal.json | init --expand --separator :
check < example-normal.json
# --indent
init --indent < example-normal.json
cat < example-flat.json | diff -u - "$got"
# --no-lists
init --expand --no-lists < example-flat.json
check < example-normal-no-lists.json