1use strict;
2use warnings;
3use Test::More tests => 8;
4
5BEGIN {
6    $ENV{ PERL_JSON_BACKEND } = 0;
7}
8
9use JSON::PP;
10
11my $json = JSON::PP->new;
12
13my $complete_text = qq/{"foo":"bar"}/;
14my $garbaged_text  = qq/{"foo":"bar"}\n/;
15my $garbaged_text2 = qq/{"foo":"bar"}\n\n/;
16my $garbaged_text3 = qq/{"foo":"bar"}\n----/;
17
18is( ( $json->decode_prefix( $complete_text )  ) [1], 13 );
19is( ( $json->decode_prefix( $garbaged_text )  ) [1], 13 );
20is( ( $json->decode_prefix( $garbaged_text2 ) ) [1], 13 );
21is( ( $json->decode_prefix( $garbaged_text3 ) ) [1], 13 );
22
23eval { $json->decode( "\n" ) }; ok( $@ =~ /malformed JSON/ );
24eval { $json->allow_nonref(0)->decode('null') }; ok $@ =~ /allow_nonref/;
25
26eval { $json->decode_prefix( "\n" ) }; ok( $@ =~ /malformed JSON/ );
27eval { $json->allow_nonref(0)->decode_prefix('null') }; ok $@ =~ /allow_nonref/;
28
29