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.2 by root, Wed Mar 26 02:35:45 2008 UTC vs.
Revision 1.5 by root, Thu May 23 09:31:32 2013 UTC

1#! perl 1#! perl
2 2
3use strict; 3use strict;
4no warnings; 4no warnings;
5use Test::More; 5use Test::More;
6BEGIN { plan tests => 689 }; 6BEGIN { plan tests => 697 };
7 7
8use JSON::XS; 8use JSON::XS;
9 9
10sub splitter { 10sub splitter {
11 my ($coder, $text) = @_; 11 my ($coder, $text) = @_;
12
13 # work around hash randomisation bug introduced in 5.18
14 $coder->canonical;
12 15
13 for (0 .. length $text) { 16 for (0 .. length $text) {
14 my $a = substr $text, 0, $_; 17 my $a = substr $text, 0, $_;
15 my $b = substr $text, $_; 18 my $b = substr $text, $_;
16 19
61 ok (!eval { $coder->incr_parse }, "sparse2"); 64 ok (!eval { $coder->incr_parse }, "sparse2");
62 $coder->incr_skip; 65 $coder->incr_skip;
63 ok ('[5]' eq $coder->encode (scalar $coder->incr_parse), "sparse3"); 66 ok ('[5]' eq $coder->encode (scalar $coder->incr_parse), "sparse3");
64} 67}
65 68
69{
70 my $coder = JSON::XS->new->max_size (5);
71 ok (!$coder->incr_parse ("[ "), "incsize1");
72 eval { !$coder->incr_parse ("] ") }; ok ($@ =~ /6 bytes/, "incsize2 $@");
73}
74
75{
76 my $coder = JSON::XS->new->max_depth (3);
77 ok (!$coder->incr_parse ("[[["), "incdepth1");
78 eval { !$coder->incr_parse (" [] ") }; ok ($@ =~ /maximum nesting/, "incdepth2 $@");
79}
80
81# contributed by yuval kogman, reformatted to fit style
82{
83 my $coder = JSON::XS->new;
84
85 my $res = eval { $coder->incr_parse("]") };
86 my $e = $@; # test more clobbers $@, we need it twice
87
88 ok (!$res, "unbalanced bracket");
89 ok ($e, "got error");
90 like ($e, qr/malformed/, "malformed json string error");
91
92 $coder->incr_skip;
93
94 is_deeply (eval { $coder->incr_parse("[42]") }, [42], "valid data after incr_skip");
95}
96
97

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines