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