line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::BSON; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
87604
|
use 5.006; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
79
|
|
4
|
2
|
|
|
2
|
|
11
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
77
|
|
5
|
2
|
|
|
2
|
|
1881
|
use parent 'Test::Builder::Module'; |
|
2
|
|
|
|
|
589
|
|
|
2
|
|
|
|
|
10
|
|
6
|
2
|
|
|
2
|
|
1972
|
use English qw( -no_match_vars ); |
|
2
|
|
|
|
|
9448
|
|
|
2
|
|
|
|
|
20
|
|
7
|
2
|
|
|
2
|
|
874
|
use Carp; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
132
|
|
8
|
2
|
|
|
2
|
|
1575
|
use BSON; |
|
2
|
|
|
|
|
74638
|
|
|
2
|
|
|
|
|
170
|
|
9
|
2
|
|
|
2
|
|
2432
|
use Test::Differences; |
|
2
|
|
|
|
|
28222
|
|
|
2
|
|
|
|
|
1062
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
12
|
|
|
|
|
|
|
our @EXPORT = qw( bson_ok bson_is ); |
13
|
|
|
|
|
|
|
our @EXPORT_OK = qw( is_valid_bson is_bson ); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
*is_valid_bson = \&bson_ok; |
16
|
|
|
|
|
|
|
*is_bson = \&bson_is; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub bson_ok ($;$) { |
19
|
2
|
|
|
2
|
1
|
3992
|
my ($input, $test_name) = @_; |
20
|
2
|
|
|
|
|
14
|
my $test = __PACKAGE__->builder; |
21
|
|
|
|
|
|
|
|
22
|
2
|
50
|
|
|
|
18
|
croak 'usage: bson_ok(input, test_name)' |
23
|
|
|
|
|
|
|
if !defined $input; |
24
|
|
|
|
|
|
|
|
25
|
2
|
|
|
|
|
4
|
eval { BSON::decode($input) }; |
|
2
|
|
|
|
|
12
|
|
26
|
|
|
|
|
|
|
|
27
|
2
|
100
|
|
|
|
491
|
if (my $error = $EVAL_ERROR) { |
28
|
1
|
|
|
|
|
9
|
$test->ok(0, $test_name); |
29
|
1
|
|
|
|
|
124
|
$test->diag("Input was not valid BSON: $error"); |
30
|
1
|
|
|
|
|
33
|
return; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
1
|
|
|
|
|
13
|
$test->ok(1, $test_name); |
34
|
1
|
|
|
|
|
175
|
return 1; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub bson_is ($$;$) { |
38
|
4
|
|
|
4
|
1
|
52055
|
my ($input, $expected, $test_name) = @_; |
39
|
4
|
|
|
|
|
25
|
my $test = __PACKAGE__->builder; |
40
|
4
|
|
|
|
|
26
|
my %result_for; |
41
|
|
|
|
|
|
|
|
42
|
4
|
50
|
33
|
|
|
28
|
croak 'usage: bson_is(input, expected, test_name)' |
43
|
|
|
|
|
|
|
if !defined $input || !defined $expected; |
44
|
|
|
|
|
|
|
|
45
|
4
|
|
|
|
|
27
|
for my $item ( |
46
|
|
|
|
|
|
|
{ key => 'input', value => $input }, |
47
|
|
|
|
|
|
|
{ key => 'expected', value => $expected }, |
48
|
|
|
|
|
|
|
) { |
49
|
7
|
|
|
|
|
9
|
$result_for{ $item->{key} } = eval { BSON::decode( $item->{value} ) }; |
|
7
|
|
|
|
|
30
|
|
50
|
|
|
|
|
|
|
|
51
|
7
|
100
|
|
|
|
888
|
if (my $error = $EVAL_ERROR) { |
52
|
2
|
|
|
|
|
12
|
$test->ok(0, $test_name); |
53
|
2
|
|
|
|
|
187
|
$test->diag(ucfirst "$item->{key} was not valid BSON: $error"); |
54
|
2
|
|
|
|
|
69
|
return; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
2
|
|
|
|
|
7
|
local $Test::Builder::Level = $Test::Builder::Level + 1; |
59
|
|
|
|
|
|
|
|
60
|
2
|
|
|
|
|
14
|
return eq_or_diff($result_for{input}, $result_for{expected}, $test_name); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
1; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
__END__ |