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