--- JSON-XS/t/19_incr.t 2008/03/25 06:37:39 1.1 +++ JSON-XS/t/19_incr.t 2008/03/26 02:35:45 1.2 @@ -3,7 +3,7 @@ use strict; no warnings; use Test::More; -BEGIN { plan tests => 686 }; +BEGIN { plan tests => 689 }; use JSON::XS; @@ -29,25 +29,37 @@ splitter +JSON::XS->new->allow_nonref, '"test"'; splitter +JSON::XS->new->allow_nonref, ' "5" '; -my $text = '[5],{"":1} , [ 1,2, 3], {"3":null}'; -my $coder = new JSON::XS; -for (0 .. length $text) { - my $a = substr $text, 0, $_; - my $b = substr $text, $_; - - $coder->incr_parse ($a); - $coder->incr_parse ($b); - - my $j1 = $coder->incr_parse; ok ($coder->incr_text =~ s/^\s*,//, "cskip1"); - my $j2 = $coder->incr_parse; ok ($coder->incr_text =~ s/^\s*,//, "cskip2"); - my $j3 = $coder->incr_parse; ok ($coder->incr_text =~ s/^\s*,//, "cskip3"); - my $j4 = $coder->incr_parse; ok ($coder->incr_text !~ s/^\s*,//, "cskip4"); - my $j5 = $coder->incr_parse; ok ($coder->incr_text !~ s/^\s*,//, "cskip5"); - - ok ('[5]' eq encode_json $j1, "cjson1"); - ok ('{"":1}' eq encode_json $j2, "cjson2"); - ok ('[1,2,3]' eq encode_json $j3, "cjson3"); - ok ('{"3":null}' eq encode_json $j4, "cjson4"); - ok (!defined $j5, "cjson5"); +{ + my $text = '[5],{"":1} , [ 1,2, 3], {"3":null}'; + my $coder = new JSON::XS; + for (0 .. length $text) { + my $a = substr $text, 0, $_; + my $b = substr $text, $_; + + $coder->incr_parse ($a); + $coder->incr_parse ($b); + + my $j1 = $coder->incr_parse; ok ($coder->incr_text =~ s/^\s*,//, "cskip1"); + my $j2 = $coder->incr_parse; ok ($coder->incr_text =~ s/^\s*,//, "cskip2"); + my $j3 = $coder->incr_parse; ok ($coder->incr_text =~ s/^\s*,//, "cskip3"); + my $j4 = $coder->incr_parse; ok ($coder->incr_text !~ s/^\s*,//, "cskip4"); + my $j5 = $coder->incr_parse; ok ($coder->incr_text !~ s/^\s*,//, "cskip5"); + + ok ('[5]' eq encode_json $j1, "cjson1"); + ok ('{"":1}' eq encode_json $j2, "cjson2"); + ok ('[1,2,3]' eq encode_json $j3, "cjson3"); + ok ('{"3":null}' eq encode_json $j4, "cjson4"); + ok (!defined $j5, "cjson5"); + } +} + +{ + my $text = '[x][5]'; + my $coder = new JSON::XS; + $coder->incr_parse ($text); + ok (!eval { $coder->incr_parse }, "sparse1"); + ok (!eval { $coder->incr_parse }, "sparse2"); + $coder->incr_skip; + ok ('[5]' eq $coder->encode (scalar $coder->incr_parse), "sparse3"); }