• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1
2use strict;
3use Test::More tests => 8;
4
5BEGIN {
6    $ENV{ PERL_JSON_BACKEND } = "JSON::backportPP";
7}
8
9use JSON;
10
11my $json = JSON->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->decode('null') }; ok $@ =~ /allow_nonref/;
25
26eval { $json->decode_prefix( "\n" ) }; ok( $@ =~ /malformed JSON/ );
27eval { $json->decode_prefix('null') }; ok $@ =~ /allow_nonref/;
28
29