File tree Expand file tree Collapse file tree 2 files changed +57
-0
lines changed Expand file tree Collapse file tree 2 files changed +57
-0
lines changed Original file line number Diff line number Diff line change 1+ /int 12345678
2+ /str "json"
3+ /x y z "spaces"
4+ /sub/a "struct"
5+ /sub/b 12345
6+ /sub/b 54321
7+ /sub/c 1.23
8+ /sub/d/e/f/g 54321
9+ /bool false
10+ /empty null
11+ /empty ""
12+ /array/0 "A"
13+ /array/1 "B"
14+ /array/2 "C"
15+ /array/3/0 "D"
16+ /array/3/1/0 "E"
17+ /array/3/1/1 "F"
Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bash
2+
3+ source test/setup
4+
5+ use Test::More tests 21
6+ use JSON
7+
8+ dbg () {
9+ : diag " DBG: $1 =${! 1} "
10+ }
11+
12+ test_dump () {
13+ JSON.style " $1 "
14+ ok $? " JSON.style succeeded"
15+
16+ json1=" $( JSON.dump < test/dump.data) "
17+ dbg json1
18+ ok $? " JSON.dump succeeded"
19+
20+ [ -n " $json1 " ]
21+ ok $? " dumped result has content"
22+
23+ JSON.load " $json1 " tree1
24+ dbg tree1
25+ ok $? " dumped json can be loaded"
26+
27+ json2=" $( echo " $tree1 " | JSON.dump) "
28+ dbg json2
29+ is " $json2 " " $json1 " " dump | load | dump produces same result as dump"
30+
31+ is " $( grep -o : <<< " $json1" | wc -l) " \
32+ " $( grep -oE ' /[^/ ]*' test/dump.data | sort -u | grep -cvE ' /[0-9]*$' ) " \
33+ " dumped result contains correct number of keys"
34+
35+ like " $json1 " ' "x y z": *"spaces"' " keys with spaces work correctly"
36+ }
37+
38+ test_dump normal
39+ test_dump minimal
40+ test_dump pretty
You can’t perform that action at this time.
0 commit comments