1 |
# provided by makamaka@donzoko.net. |
2 |
|
3 |
use strict; |
4 |
use warnings; |
5 |
|
6 |
use Test::More tests => 12; |
7 |
|
8 |
use JSON::XS; |
9 |
|
10 |
use Data::Dumper qw( Dumper ); |
11 |
|
12 |
sub decoder { |
13 |
my ($str) = @_; |
14 |
|
15 |
my $json = 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 |
|
31 |
is( decoder( "[]" ), '[]', 'array baseline' ); |
32 |
is( decoder( " []" ), '[]', 'space ignored before array' ); |
33 |
is( decoder( "\n[]" ), '[]', 'newline ignored before array' ); |
34 |
is( decoder( "# foo\n[]" ), '[]', 'comment ignored before array' ); |
35 |
is( decoder( "# fo[o\n[]"), '[]', 'comment ignored before array' ); |
36 |
is( decoder( "# fo]o\n[]"), '[]', 'comment ignored before array' ); |
37 |
is( decoder( "[# fo]o\n]"), '[]', 'comment ignored inside array' ); |
38 |
|
39 |
is( decoder( "" ), 'undef', 'eof baseline' ); |
40 |
is( decoder( " " ), 'undef', 'space ignored before eof' ); |
41 |
is( decoder( "\n" ), 'undef', 'newline ignored before eof' ); |
42 |
is( decoder( "#,foo\n" ), 'undef', 'comment ignored before eof' ); |
43 |
is( decoder( "# []o\n" ), 'undef', 'comment ignored before eof' ); |
44 |
|