"Fossies" - the Fresh Open Source Software Archive

Member "perl-5.32.1/cpan/JSON-PP/t/002_error.t" (18 Dec 2020, 2843 Bytes) of package /linux/misc/perl-5.32.1.tar.xz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

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