OLD | NEW |
| (Empty) |
1 # the oritinal test case was provided by IKEGAMI@cpan.org | |
2 | |
3 use strict; | |
4 | |
5 use Test::More tests => 13; | |
6 | |
7 BEGIN { $ENV{PERL_JSON_BACKEND} = "JSON::backportPP"; } | |
8 | |
9 use JSON; | |
10 | |
11 use Data::Dumper qw( Dumper ); | |
12 | |
13 sub 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 | |
33 is( decoder( "[]" ), '[]', 'array baseline' ); | |
34 is( decoder( " []" ), '[]', 'space ignored before array' ); | |
35 is( decoder( "\n[]" ), '[]', 'newline ignored before array' ); | |
36 is( decoder( "# foo\n[]" ), '[]', 'comment ignored before array' ); | |
37 is( decoder( "# fo[o\n[]"), '[]', 'comment ignored before array' ); | |
38 is( decoder( "# fo]o\n[]"), '[]', 'comment ignored before array' ); | |
39 is( decoder( "[# fo]o\n]"), '[]', 'comment ignored inside array' ); | |
40 | |
41 is( decoder( "" ), 'undef', 'eof baseline' ); | |
42 is( decoder( " " ), 'undef', 'space ignored before eof' ); | |
43 is( decoder( "\n" ), 'undef', 'newline ignored before eof' ); | |
44 is( decoder( "#,foo\n" ), 'undef', 'comment ignored before eof' ); | |
45 is( decoder( "# []o\n" ), 'undef', 'comment ignored before eof' ); | |
46 | |
47 is( decoder( qq/#\n[#foo\n"#\\n"#\n]/), '["#\n"]', 'array and string in multiple
lines' ); | |
OLD | NEW |