Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

file 42 lines (32 sloc) 1.111 kb
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
pir::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');
}
Something went wrong with that request. Please try again.