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