1# copied over from JSON::XS and modified to use JSON 2 3use strict; 4use Test::More; 5BEGIN { plan tests => 31 }; 6 7BEGIN { $ENV{PERL_JSON_BACKEND} = "JSON::backportPP"; } 8 9BEGIN { 10 use lib qw(t); 11 use _unicode_handling; 12} 13 14use utf8; 15use JSON; 16 17 18eval { JSON->new->encode ([\-1]) }; ok $@ =~ /cannot encode reference/; 19eval { JSON->new->encode ([\undef]) }; ok $@ =~ /cannot encode reference/; 20eval { JSON->new->encode ([\2]) }; ok $@ =~ /cannot encode reference/; 21eval { JSON->new->encode ([\{}]) }; ok $@ =~ /cannot encode reference/; 22eval { JSON->new->encode ([\[]]) }; ok $@ =~ /cannot encode reference/; 23eval { JSON->new->encode ([\\1]) }; ok $@ =~ /cannot encode reference/; 24eval { JSON->new->allow_nonref (1)->decode ('"\u1234\udc00"') }; ok $@ =~ /missing high /; 25eval { JSON->new->allow_nonref->decode ('"\ud800"') }; ok $@ =~ /missing low /; 26eval { JSON->new->allow_nonref (1)->decode ('"\ud800\u1234"') }; ok $@ =~ /surrogate pair /; 27eval { JSON->new->decode ('null') }; ok $@ =~ /allow_nonref/; 28eval { JSON->new->allow_nonref (1)->decode ('+0') }; ok $@ =~ /malformed/; 29eval { JSON->new->allow_nonref->decode ('.2') }; ok $@ =~ /malformed/; 30eval { JSON->new->allow_nonref (1)->decode ('bare') }; ok $@ =~ /malformed/; 31eval { JSON->new->allow_nonref->decode ('naughty') }; ok $@ =~ /null/; 32eval { JSON->new->allow_nonref (1)->decode ('01') }; ok $@ =~ /leading zero/; 33eval { JSON->new->allow_nonref->decode ('00') }; ok $@ =~ /leading zero/; 34eval { JSON->new->allow_nonref (1)->decode ('-0.') }; ok $@ =~ /decimal point/; 35eval { JSON->new->allow_nonref->decode ('-0e') }; ok $@ =~ /exp sign/; 36eval { JSON->new->allow_nonref (1)->decode ('-e+1') }; ok $@ =~ /initial minus/; 37eval { JSON->new->allow_nonref->decode ("\"\n\"") }; ok $@ =~ /invalid character/; 38eval { JSON->new->allow_nonref (1)->decode ("\"\x01\"") }; ok $@ =~ /invalid character/; 39eval { JSON->new->decode ('[5') }; ok $@ =~ /parsing array/; 40eval { JSON->new->decode ('{"5"') }; ok $@ =~ /':' expected/; 41eval { JSON->new->decode ('{"5":null') }; ok $@ =~ /parsing object/; 42 43eval { JSON->new->decode (undef) }; ok $@ =~ /malformed/; 44eval { JSON->new->decode (\5) }; ok !!$@; # Can't coerce readonly 45eval { JSON->new->decode ([]) }; ok $@ =~ /malformed/; 46eval { JSON->new->decode (\*STDERR) }; ok $@ =~ /malformed/; 47eval { JSON->new->decode (*STDERR) }; ok !!$@; # cannot coerce GLOB 48 49eval { decode_json ("\"\xa0") }; ok $@ =~ /malformed.*character/; 50eval { decode_json ("\"\xa0\"") }; ok $@ =~ /malformed.*character/; 51 52