line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
=head1 NAME |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
JSON::Streaming::Reader::TestUtil - Utility functions for the JSON::Streaming::Reader test suite |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 DESCRIPTION |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
This package contains some utility functions for use in the test suite for L. |
9
|
|
|
|
|
|
|
It's not useful outside of this context. |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=cut |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
package JSON::Streaming::Reader::TestUtil; |
14
|
|
|
|
|
|
|
|
15
|
6
|
|
|
6
|
|
130603
|
use JSON::Streaming::Reader; |
|
6
|
|
|
|
|
26
|
|
|
6
|
|
|
|
|
220
|
|
16
|
6
|
|
|
6
|
|
1477
|
use Test::More; |
|
6
|
|
|
|
|
20150
|
|
|
6
|
|
|
|
|
68
|
|
17
|
|
|
|
|
|
|
|
18
|
6
|
|
|
6
|
|
2203
|
use base qw(Exporter); |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
3171
|
|
19
|
|
|
|
|
|
|
our @EXPORT = qw(test_parse compare_event_parse); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub test_parse { |
22
|
61
|
|
|
61
|
0
|
67379
|
my ($name, $input, $expected_tokens) = @_; |
23
|
|
|
|
|
|
|
|
24
|
61
|
|
|
|
|
256
|
my $jsonw = JSON::Streaming::Reader->for_string($input); |
25
|
61
|
|
|
|
|
106
|
my @tokens = (); |
26
|
|
|
|
|
|
|
|
27
|
61
|
|
|
|
|
200
|
while (my $token = $jsonw->get_token()) { |
28
|
108
|
|
|
|
|
376
|
push @tokens, $token; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
61
|
|
|
|
|
214
|
is_deeply(\@tokens, $expected_tokens, $name); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub compare_event_parse { |
35
|
65
|
|
|
65
|
0
|
89806
|
my (@chunks) = @_; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# First do a normal callback-based parse |
38
|
|
|
|
|
|
|
# to tell us what the result should be. |
39
|
|
|
|
|
|
|
# This assumes that the callback API is |
40
|
|
|
|
|
|
|
# functioning correctly, but we test that |
41
|
|
|
|
|
|
|
# separately so we can be reasonably sure |
42
|
|
|
|
|
|
|
# that it is. |
43
|
|
|
|
|
|
|
|
44
|
65
|
|
|
|
|
157
|
my ($callback_callbacks, $callback_tokens) = test_callbacks(); |
45
|
65
|
|
|
|
|
367
|
my $jsonw = JSON::Streaming::Reader->for_string(join('', @chunks)); |
46
|
|
|
|
|
|
|
|
47
|
65
|
|
|
|
|
441
|
$jsonw->process_tokens(%$callback_callbacks); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# Now we do an event-driven parse. |
50
|
|
|
|
|
|
|
|
51
|
65
|
|
|
|
|
216
|
my ($event_callbacks, $event_tokens) = test_callbacks(); |
52
|
65
|
|
|
|
|
430
|
$jsonw = JSON::Streaming::Reader->event_based(%$event_callbacks); |
53
|
|
|
|
|
|
|
|
54
|
65
|
|
|
|
|
377
|
foreach my $chunk (@chunks) { |
55
|
106
|
|
|
|
|
1081
|
$jsonw->feed_buffer(\$chunk); |
56
|
|
|
|
|
|
|
} |
57
|
65
|
|
|
|
|
217
|
$jsonw->signal_eof(); |
58
|
|
|
|
|
|
|
|
59
|
65
|
|
|
|
|
187
|
my $name = join('|', '', @chunks, ''); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
#use Data::Dumper; |
62
|
|
|
|
|
|
|
#print STDERR Data::Dumper::Dumper($callback_tokens, $event_tokens); |
63
|
|
|
|
|
|
|
|
64
|
65
|
|
|
|
|
241
|
is_deeply($callback_tokens, $event_tokens, $name); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub test_callbacks { |
68
|
|
|
|
|
|
|
|
69
|
130
|
|
|
130
|
0
|
234
|
my %callbacks = (); |
70
|
130
|
|
|
|
|
174
|
my @tokens = (); |
71
|
|
|
|
|
|
|
|
72
|
130
|
|
|
|
|
241
|
foreach my $callback_name (qw(start_object end_object start_array end_array start_property end_property add_string add_number add_boolean add_null error)) { |
73
|
|
|
|
|
|
|
$callbacks{$callback_name} = sub { |
74
|
416
|
|
|
416
|
|
1726
|
push @tokens, [ $callback_name, @_ ]; |
75
|
1430
|
|
|
|
|
5280
|
}; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
130
|
|
|
83
|
|
451
|
$callbacks{eof} = sub {}; |
|
83
|
|
|
|
|
198
|
|
79
|
|
|
|
|
|
|
|
80
|
130
|
|
|
|
|
427
|
return \%callbacks, \@tokens; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
1; |