/
json-test.nqp
42 lines (32 loc) · 1022 Bytes
/
json-test.nqp
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
###
### json-test.nqp: Test behavior of the JSON parsing language (data_json)
###
# TO USE:
# $ parrot_nqp json-test.nqp
# First, load the Parrot data structure dumper module
load_bytecode('dumper.pbc');
# All of the crazy testing
my @tests := (
# Basic sanity checks
'"Hello from JSON"',
'[1,2,3]',
'{"a":1,"b":2}',
# Null becomes undef by itself,
# but null in an array or object
'null',
'[null]',
'{"a":null}',
# Booleans get converted to 1/0
'{"true": true, "false": false}',
# Duplicate keys silently overwrite!
'{"a":1, "a":"bar"}',
# Complex test
'{"config":{"a":1,"b":2.4e-2,"c":"foo","d":{"1":11,"2":22},"e":[4,5,6],"f":true,"g":false,"h":null}}'
);
# Iterate over test strings, showing original and roundtripped version
for @tests {
say("\nOriginal: " ~ $_);
print("Roundtripped: ");
my $rt := eval($_, 'data_json');
_dumper($rt, 'JSON');
}