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