ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/JSON-XS/t/19_incr.t
(Generate patch)

Comparing JSON-XS/t/19_incr.t (file contents):
Revision 1.1 by root, Tue Mar 25 06:37:39 2008 UTC vs.
Revision 1.2 by root, Wed Mar 26 02:35:45 2008 UTC

1#! perl 1#! perl
2 2
3use strict; 3use strict;
4no warnings; 4no warnings;
5use Test::More; 5use Test::More;
6BEGIN { plan tests => 686 }; 6BEGIN { plan tests => 689 };
7 7
8use JSON::XS; 8use JSON::XS;
9 9
10sub splitter { 10sub splitter {
11 my ($coder, $text) = @_; 11 my ($coder, $text) = @_;
27splitter +JSON::XS->new , ' ["x\\"","\\u1000\\\\n\\nx",1,{"\\\\" :5 , "": "x"}]'; 27splitter +JSON::XS->new , ' ["x\\"","\\u1000\\\\n\\nx",1,{"\\\\" :5 , "": "x"}]';
28splitter +JSON::XS->new , '[ "x\\"","\\u1000\\\\n\\nx" , 1,{"\\\\ " :5 , "": " x"} ] '; 28splitter +JSON::XS->new , '[ "x\\"","\\u1000\\\\n\\nx" , 1,{"\\\\ " :5 , "": " x"} ] ';
29splitter +JSON::XS->new->allow_nonref, '"test"'; 29splitter +JSON::XS->new->allow_nonref, '"test"';
30splitter +JSON::XS->new->allow_nonref, ' "5" '; 30splitter +JSON::XS->new->allow_nonref, ' "5" ';
31 31
32{
32my $text = '[5],{"":1} , [ 1,2, 3], {"3":null}'; 33 my $text = '[5],{"":1} , [ 1,2, 3], {"3":null}';
33my $coder = new JSON::XS; 34 my $coder = new JSON::XS;
34for (0 .. length $text) { 35 for (0 .. length $text) {
35 my $a = substr $text, 0, $_; 36 my $a = substr $text, 0, $_;
36 my $b = substr $text, $_; 37 my $b = substr $text, $_;
37 38
38 $coder->incr_parse ($a); 39 $coder->incr_parse ($a);
39 $coder->incr_parse ($b); 40 $coder->incr_parse ($b);
40 41
41 my $j1 = $coder->incr_parse; ok ($coder->incr_text =~ s/^\s*,//, "cskip1"); 42 my $j1 = $coder->incr_parse; ok ($coder->incr_text =~ s/^\s*,//, "cskip1");
42 my $j2 = $coder->incr_parse; ok ($coder->incr_text =~ s/^\s*,//, "cskip2"); 43 my $j2 = $coder->incr_parse; ok ($coder->incr_text =~ s/^\s*,//, "cskip2");
43 my $j3 = $coder->incr_parse; ok ($coder->incr_text =~ s/^\s*,//, "cskip3"); 44 my $j3 = $coder->incr_parse; ok ($coder->incr_text =~ s/^\s*,//, "cskip3");
44 my $j4 = $coder->incr_parse; ok ($coder->incr_text !~ s/^\s*,//, "cskip4"); 45 my $j4 = $coder->incr_parse; ok ($coder->incr_text !~ s/^\s*,//, "cskip4");
45 my $j5 = $coder->incr_parse; ok ($coder->incr_text !~ s/^\s*,//, "cskip5"); 46 my $j5 = $coder->incr_parse; ok ($coder->incr_text !~ s/^\s*,//, "cskip5");
46 47
47 ok ('[5]' eq encode_json $j1, "cjson1"); 48 ok ('[5]' eq encode_json $j1, "cjson1");
48 ok ('{"":1}' eq encode_json $j2, "cjson2"); 49 ok ('{"":1}' eq encode_json $j2, "cjson2");
49 ok ('[1,2,3]' eq encode_json $j3, "cjson3"); 50 ok ('[1,2,3]' eq encode_json $j3, "cjson3");
50 ok ('{"3":null}' eq encode_json $j4, "cjson4"); 51 ok ('{"3":null}' eq encode_json $j4, "cjson4");
51 ok (!defined $j5, "cjson5"); 52 ok (!defined $j5, "cjson5");
53 }
52} 54}
53 55
56{
57 my $text = '[x][5]';
58 my $coder = new JSON::XS;
59 $coder->incr_parse ($text);
60 ok (!eval { $coder->incr_parse }, "sparse1");
61 ok (!eval { $coder->incr_parse }, "sparse2");
62 $coder->incr_skip;
63 ok ('[5]' eq $coder->encode (scalar $coder->incr_parse), "sparse3");
64}
65

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines