summaryrefslogtreecommitdiff
path: root/cpan/JSON-PP/t/022_comment_at_eof.t
diff options
context:
space:
mode:
Diffstat (limited to 'cpan/JSON-PP/t/022_comment_at_eof.t')
-rw-r--r--cpan/JSON-PP/t/022_comment_at_eof.t47
1 files changed, 47 insertions, 0 deletions
diff --git a/cpan/JSON-PP/t/022_comment_at_eof.t b/cpan/JSON-PP/t/022_comment_at_eof.t
new file mode 100644
index 0000000000..b235b1f2f9
--- /dev/null
+++ b/cpan/JSON-PP/t/022_comment_at_eof.t
@@ -0,0 +1,47 @@
+# the oritinal test case was provided by IKEGAMI@cpan.org
+
+use strict;
+
+use Test::More tests => 13;
+
+BEGIN { $ENV{PERL_JSON_BACKEND} = 0; }
+
+use JSON::PP;
+
+use Data::Dumper qw( Dumper );
+
+sub decoder {
+ my ($str) = @_;
+
+ my $json = JSON::PP->new->relaxed;
+
+ $json->incr_parse($_[0]);
+
+ my $rv;
+ if (!eval { $rv = $json->incr_parse(); 1 }) {
+ $rv = "died with $@";
+ }
+
+ local $Data::Dumper::Useqq = 1;
+ local $Data::Dumper::Terse = 1;
+ local $Data::Dumper::Indent = 0;
+
+ return Dumper($rv);
+}
+
+
+is( decoder( "[]" ), '[]', 'array baseline' );
+is( decoder( " []" ), '[]', 'space ignored before array' );
+is( decoder( "\n[]" ), '[]', 'newline ignored before array' );
+is( decoder( "# foo\n[]" ), '[]', 'comment ignored before array' );
+is( decoder( "# fo[o\n[]"), '[]', 'comment ignored before array' );
+is( decoder( "# fo]o\n[]"), '[]', 'comment ignored before array' );
+is( decoder( "[# fo]o\n]"), '[]', 'comment ignored inside array' );
+
+is( decoder( "" ), 'undef', 'eof baseline' );
+is( decoder( " " ), 'undef', 'space ignored before eof' );
+is( decoder( "\n" ), 'undef', 'newline ignored before eof' );
+is( decoder( "#,foo\n" ), 'undef', 'comment ignored before eof' );
+is( decoder( "# []o\n" ), 'undef', 'comment ignored before eof' );
+
+is( decoder( qq/#\n[#foo\n"#\\n"#\n]/), '["#\n"]', 'array and string in multiple lines' );