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