xref: /openbsd-src/gnu/usr.bin/perl/cpan/JSON-PP/t/114_decode_prefix.t (revision 256a93a44f36679bee503f12e49566c2183f6181)
1898184e3Ssthenuse strict;
2*256a93a4Safresh1use warnings;
3898184e3Ssthenuse Test::More tests => 8;
4898184e3Ssthen
5898184e3SsthenBEGIN {
6898184e3Ssthen    $ENV{ PERL_JSON_BACKEND } = 0;
7898184e3Ssthen}
8898184e3Ssthen
9898184e3Ssthenuse JSON::PP;
10898184e3Ssthen
11898184e3Ssthenmy $json = JSON::PP->new;
12898184e3Ssthen
13898184e3Ssthenmy $complete_text = qq/{"foo":"bar"}/;
14898184e3Ssthenmy $garbaged_text  = qq/{"foo":"bar"}\n/;
15898184e3Ssthenmy $garbaged_text2 = qq/{"foo":"bar"}\n\n/;
16898184e3Ssthenmy $garbaged_text3 = qq/{"foo":"bar"}\n----/;
17898184e3Ssthen
18898184e3Ssthenis( ( $json->decode_prefix( $complete_text )  ) [1], 13 );
19898184e3Ssthenis( ( $json->decode_prefix( $garbaged_text )  ) [1], 13 );
20898184e3Ssthenis( ( $json->decode_prefix( $garbaged_text2 ) ) [1], 13 );
21898184e3Ssthenis( ( $json->decode_prefix( $garbaged_text3 ) ) [1], 13 );
22898184e3Ssthen
23898184e3Sstheneval { $json->decode( "\n" ) }; ok( $@ =~ /malformed JSON/ );
24f3efcd01Safresh1eval { $json->allow_nonref(0)->decode('null') }; ok $@ =~ /allow_nonref/;
25898184e3Ssthen
26898184e3Sstheneval { $json->decode_prefix( "\n" ) }; ok( $@ =~ /malformed JSON/ );
27f3efcd01Safresh1eval { $json->allow_nonref(0)->decode_prefix('null') }; ok $@ =~ /allow_nonref/;
28898184e3Ssthen
29