Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

43 lines (32 sloc) 1.022 kb
###
### 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');
}
Jump to Line
Something went wrong with that request. Please try again.