Debian Codegraph @

t/rt_90071_incr_parse.t

raw
1 use strict;
2 use warnings;
3 use Test::More;
4 BEGIN { $ENV{PERL_JSON_BACKEND} ||= "JSON::backportPP"; }
5 use JSON;
6
7 BEGIN { plan skip_all => "requires $JSON::BackendModule 2.90 or newer" if JSON->backend->is_pp and eval $JSON::BackendModule->VERSION < 2.90 }
8
9 BEGIN { plan tests => 2 };
10
11 my $json = JSON->new;
12 my $kb = 'a' x 1024;
13 my $hash = { map { $_ => $kb } (1..40) };
14 my $data = join ( '', $json->encode($hash), $json->encode($hash) );
15 my $size = length($data);
16 # note "Total size: [$size]";
17 my $offset = 0;
18 while ($size) {
19 # note "Bytes left [$size]";
20 my $incr = substr($data, $offset, 4096);
21 my $bytes = length($incr);
22 $size -= $bytes;
23 $offset += $bytes;
24 if ($bytes) {
25 $json->incr_parse($incr);
26 }
27 while( my $obj = $json->incr_parse ) {
28 ok "Got JSON object";
29 }
30 }