1# copied over from JSON::XS and modified to use JSON::PP 2 3# the original test case was provided by IKEGAMI@cpan.org 4 5use strict; 6use warnings; 7 8use Test::More tests => 13; 9 10BEGIN { $ENV{PERL_JSON_BACKEND} = 0; } 11 12use JSON::PP; 13 14use Data::Dumper qw( Dumper ); 15 16sub decoder { 17 my ($str) = @_; 18 19 my $json = JSON::PP->new->relaxed; 20 21 $json->incr_parse($_[0]); 22 23 my $rv; 24 if (!eval { $rv = $json->incr_parse(); 1 }) { 25 $rv = "died with $@"; 26 } 27 28 local $Data::Dumper::Useqq = 1; 29 local $Data::Dumper::Terse = 1; 30 local $Data::Dumper::Indent = 0; 31 32 return Dumper($rv); 33} 34 35is( decoder( "[]" ), '[]', 'array baseline' ); 36is( decoder( " []" ), '[]', 'space ignored before array' ); 37is( decoder( "\n[]" ), '[]', 'newline ignored before array' ); 38is( decoder( "# foo\n[]" ), '[]', 'comment ignored before array' ); 39is( decoder( "# fo[o\n[]"), '[]', 'comment ignored before array' ); 40is( decoder( "# fo]o\n[]"), '[]', 'comment ignored before array' ); 41is( decoder( "[# fo]o\n]"), '[]', 'comment ignored inside array' ); 42 43is( decoder( "" ), 'undef', 'eof baseline' ); 44is( decoder( " " ), 'undef', 'space ignored before eof' ); 45is( decoder( "\n" ), 'undef', 'newline ignored before eof' ); 46is( decoder( "#,foo\n" ), 'undef', 'comment ignored before eof' ); 47is( decoder( "# []o\n" ), 'undef', 'comment ignored before eof' ); 48 49is( decoder(qq/#\n[#foo\n"#\\n"#\n]/), '["#\n"]', 'array and string in multiple lines' ); 50 51