ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/JSON-XS/t/22_comment_at_eof.t
Revision: 1.3
Committed: Thu Jan 7 06:35:43 2010 UTC (14 years, 4 months ago) by root
Content type: application/x-troff
Branch: MAIN
CVS Tags: rel-2_31, rel-2_34, rel-2_32, rel-2_33, rel-3_0, rel-4_01, rel-3_04, rel-4_03, rel-4_02, rel-2_3, rel-2_29, rel-2_28, rel-4_0_00, rel-3_01, rel-3_02, rel-3_03, rel-4_0, rel-2_27, HEAD
Changes since 1.2: +4 -2 lines
Log Message:
2.27

File Contents

# Content
1 # provided by IKEGAMI@cpan.org
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 13;
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
45 is( decoder(qq/#\n[#foo\n"#\\n"#\n]/), '["#\n"]', 'array and string in multiple lines' );
46