line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Deep::JSON; |
2
|
2
|
|
|
2
|
|
900983
|
use strict; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
83
|
|
3
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
63
|
|
4
|
2
|
|
|
2
|
|
64
|
use 5.008_001; |
|
2
|
|
|
|
|
18
|
|
|
2
|
|
|
|
|
74
|
|
5
|
2
|
|
|
2
|
|
1303
|
use Test::Deep (); |
|
2
|
|
|
|
|
14965
|
|
|
2
|
|
|
|
|
46
|
|
6
|
2
|
|
|
2
|
|
3216
|
use Test::Deep::Cmp; |
|
2
|
|
|
|
|
2122
|
|
|
2
|
|
|
|
|
10
|
|
7
|
2
|
|
|
2
|
|
1266
|
use JSON; |
|
2
|
|
|
|
|
15121
|
|
|
2
|
|
|
|
|
18
|
|
8
|
2
|
|
|
2
|
|
3056
|
use Exporter::Lite; |
|
2
|
|
|
|
|
134188
|
|
|
2
|
|
|
|
|
23
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our @EXPORT = qw(json); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub json ($) { |
15
|
6
|
|
|
6
|
1
|
574688
|
my ($expected) = @_; |
16
|
6
|
|
|
|
|
37
|
return __PACKAGE__->new($expected); |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub init { |
20
|
6
|
|
|
6
|
0
|
41
|
my ($self, $expected) = @_; |
21
|
6
|
|
|
|
|
92
|
$self->{val} = $expected; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub descend { |
25
|
6
|
|
|
6
|
0
|
25933
|
my ($self, $got) = @_; |
26
|
6
|
|
|
|
|
8
|
my $parsed = eval { decode_json($got) }; |
|
6
|
|
|
|
|
53
|
|
27
|
6
|
100
|
|
|
|
19
|
if ($@) { |
28
|
1
|
|
|
|
|
5
|
$self->{error} = $@; |
29
|
1
|
|
|
|
|
3
|
return 0; |
30
|
|
|
|
|
|
|
} |
31
|
5
|
|
|
|
|
16
|
return Test::Deep::wrap($self->{val})->descend($parsed); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub diagnostics { |
35
|
2
|
|
|
2
|
0
|
440
|
my $self = shift; |
36
|
2
|
100
|
66
|
|
|
16
|
return $self->{error} if defined $self->{error} && length $self->{error}; |
37
|
1
|
|
|
|
|
4
|
return $self->{val}->diagnostics(@_); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
1; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
__END__ |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head1 NAME |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
Test::Deep::JSON - Compare JSON with Test::Deep |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head1 SYNOPSIS |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
use Test::Deep; |
51
|
|
|
|
|
|
|
use Test::Deep::JSON; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
cmp_deeply { |
54
|
|
|
|
|
|
|
foo => 'bar', |
55
|
|
|
|
|
|
|
payload => '{"a":1}', |
56
|
|
|
|
|
|
|
}, { |
57
|
|
|
|
|
|
|
foo => 'bar', |
58
|
|
|
|
|
|
|
payload => json({ a => ignore() }), |
59
|
|
|
|
|
|
|
}; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head1 DESCRIPTION |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
Test::Deep::JSON provides C<json($expected)> function to expect that |
64
|
|
|
|
|
|
|
target can be parsed as a JSON string and matches (by C<cmp_deeply>) with |
65
|
|
|
|
|
|
|
I<$expected>. |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head1 FUNCTIONS |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=over 4 |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=item json($expected) |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Exported by default. |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
I<$expected> can be anything that C<Test::Deep> recognizes. |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
This parses the data as a JSON string, and compares the parsed object |
78
|
|
|
|
|
|
|
and I<$expected> by C<Test::Deep> functionality. |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
Fails if the data cannot be parsed as a JSON. |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=back |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head1 AUTHOR |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
motemen E<lt>motemen@gmail.comE<gt> |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head1 SEE ALSO |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
L<Test::Deep> |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head1 LICENSE |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
95
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=cut |