line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Data::Hash; |
2
|
3
|
|
|
3
|
|
1372
|
use strict; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
99
|
|
3
|
|
|
|
|
|
|
|
4
|
3
|
|
|
3
|
|
17
|
use Exporter qw(import); |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
167
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our @EXPORT = qw(exists_ok not_exists_ok |
7
|
|
|
|
|
|
|
hash_value_defined_ok hash_value_undef_ok |
8
|
|
|
|
|
|
|
hash_value_true_ok hash_value_false_ok); |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '1.242'; |
11
|
|
|
|
|
|
|
|
12
|
3
|
|
|
3
|
|
20
|
use Test::Builder; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
1448
|
|
13
|
|
|
|
|
|
|
my $Test = Test::Builder->new(); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=encoding utf8 |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 NAME |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
Test::Data::Hash -- test functions for hash variables |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 SYNOPSIS |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
use Test::Data qw(Hash); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 DESCRIPTION |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
This modules provides a collection of test utilities for |
28
|
|
|
|
|
|
|
hash variables. Load the module through Test::Data. |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head2 Functions |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=over 4 |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=item exists_ok( KEY, HASH [, NAME] ) |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
Ok if the value for KEY in HASH exists. The function |
37
|
|
|
|
|
|
|
does not create KEY in HASH. |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=cut |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub exists_ok($\%;$) |
42
|
|
|
|
|
|
|
{ |
43
|
0
|
|
|
0
|
1
|
|
my $key = shift; |
44
|
0
|
|
|
|
|
|
my $hash = shift; |
45
|
0
|
|
0
|
|
|
|
my $name = shift || "Hash key [$key] exists"; |
46
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
$Test->ok( exists $hash->{$key}, $name ); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=item not_exists_ok( KEY, HASH [, NAME] ) |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
Ok if the value for KEY in HASH does not exist. The function |
53
|
|
|
|
|
|
|
does not create KEY in HASH. |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=cut |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub not_exists_ok($\%;$) |
58
|
|
|
|
|
|
|
{ |
59
|
0
|
|
|
0
|
1
|
|
my $key = shift; |
60
|
0
|
|
|
|
|
|
my $hash = shift; |
61
|
0
|
|
0
|
|
|
|
my $name = shift || "Hash key [$key] does not exist"; |
62
|
|
|
|
|
|
|
|
63
|
0
|
0
|
|
|
|
|
$Test->ok( exists $hash->{$key} ? 0 : 1, $name ); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=item hash_value_defined_ok( KEY, HASH [, NAME] ) |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
Ok if the value for KEY in HASH is defined. The function |
69
|
|
|
|
|
|
|
does not create KEY in HASH. |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=cut |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub hash_value_defined_ok($\%;$) |
74
|
|
|
|
|
|
|
{ |
75
|
0
|
|
|
0
|
1
|
|
my $key = shift; |
76
|
0
|
|
|
|
|
|
my $hash = shift; |
77
|
0
|
|
0
|
|
|
|
my $name = shift || "Hash value for key [$key] is defined"; |
78
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
$Test->ok( defined $hash->{$key}, $name ); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=item hash_value_undef_ok( KEY, HASH [, NAME] ) |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Ok if the value for KEY in HASH is undefined. The function |
85
|
|
|
|
|
|
|
does not create KEY in HASH. |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=cut |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub hash_value_undef_ok($\%;$) { |
90
|
0
|
|
|
0
|
1
|
|
my $key = shift; |
91
|
0
|
|
|
|
|
|
my $hash = shift; |
92
|
0
|
|
0
|
|
|
|
my $name = shift || "Hash value for key [$key] is undef"; |
93
|
|
|
|
|
|
|
|
94
|
0
|
0
|
|
|
|
|
$Test->ok( defined $hash->{$key} ? 0 : 1, $name ); |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=item hash_value_true_ok( KEY, HASH [, NAME] ) |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
Ok if the value for KEY in HASH is true. The function |
100
|
|
|
|
|
|
|
does not create KEY in HASH. |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=cut |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub hash_value_true_ok($\%;$) { |
105
|
0
|
|
|
0
|
1
|
|
my $key = shift; |
106
|
0
|
|
|
|
|
|
my $hash = shift; |
107
|
0
|
|
0
|
|
|
|
my $name = shift || "Hash value for key [$key] is true"; |
108
|
|
|
|
|
|
|
|
109
|
0
|
|
|
|
|
|
$Test->ok( $hash->{$key}, $name ); |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=item hash_value_false_ok( KEY, HASH [, NAME] ) |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Ok if the value for KEY in HASH is false. The function |
115
|
|
|
|
|
|
|
does not create KEY in HASH. |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=cut |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub hash_value_false_ok($\%;$) { |
120
|
0
|
|
|
0
|
1
|
|
my $key = shift; |
121
|
0
|
|
|
|
|
|
my $hash = shift; |
122
|
0
|
|
0
|
|
|
|
my $name = shift || "Hash value for key [$key] is false"; |
123
|
|
|
|
|
|
|
|
124
|
0
|
0
|
|
|
|
|
$Test->ok( $hash->{$key} ? 0 : 1, $name ); |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=back |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head1 SEE ALSO |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
L, |
132
|
|
|
|
|
|
|
L, |
133
|
|
|
|
|
|
|
L, |
134
|
|
|
|
|
|
|
L, |
135
|
|
|
|
|
|
|
L |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head1 SOURCE AVAILABILITY |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
This source is in Github: |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
https://github.com/briandfoy/test-data |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=head1 AUTHOR |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
brian d foy, C<< >> |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
Copyright © 2002-2018, brian d foy . All rights reserved. |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify |
152
|
|
|
|
|
|
|
it under the terms of the Artistic License 2.0. |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=cut |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
"red leather yellow leather"; |