line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Hash::Storage::AutoTester; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
4
|
|
|
|
|
|
|
|
5
|
3
|
|
|
3
|
|
1351
|
use strict; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
98
|
|
6
|
3
|
|
|
3
|
|
10
|
use warnings; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
68
|
|
7
|
3
|
|
|
3
|
|
24
|
use v5.10; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
77
|
|
8
|
|
|
|
|
|
|
|
9
|
3
|
|
|
3
|
|
27
|
use Test::More; |
|
3
|
|
|
|
|
21
|
|
|
3
|
|
|
|
|
23
|
|
10
|
3
|
|
|
3
|
|
2508
|
use Test::Deep; |
|
3
|
|
|
|
|
21245
|
|
|
3
|
|
|
|
|
20
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
3
|
|
|
3
|
0
|
33
|
my $class = shift; |
14
|
3
|
|
|
|
|
9
|
my %args = @_; |
15
|
|
|
|
|
|
|
|
16
|
3
|
|
|
|
|
7
|
my $st = $args{storage}; |
17
|
3
|
50
|
33
|
|
|
41
|
die "WRONG STORAGE" unless $st && $st->isa('Hash::Storage'); |
18
|
|
|
|
|
|
|
|
19
|
3
|
|
|
|
|
14
|
return bless { storage => $st }, $class; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub run { |
23
|
3
|
|
|
3
|
0
|
14
|
my $self = shift; |
24
|
3
|
|
|
|
|
11
|
$self->test_get(); |
25
|
3
|
|
|
|
|
6109
|
$self->test_set(); |
26
|
3
|
|
|
|
|
3331
|
$self->test_del(); |
27
|
3
|
|
|
|
|
3528
|
$self->test_list(); |
28
|
3
|
|
|
|
|
23289
|
$self->test_count(); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub test_get { |
32
|
3
|
|
|
3
|
0
|
3
|
my $self = shift; |
33
|
3
|
|
|
|
|
14
|
my $st = $self->{storage}; |
34
|
|
|
|
|
|
|
|
35
|
3
|
|
|
|
|
22
|
my %user1 = ( |
36
|
|
|
|
|
|
|
fname => 'Ivan', |
37
|
|
|
|
|
|
|
lname => 'Ivanov', |
38
|
|
|
|
|
|
|
age => '21', |
39
|
|
|
|
|
|
|
gender => 'male' |
40
|
|
|
|
|
|
|
); |
41
|
|
|
|
|
|
|
|
42
|
3
|
|
|
|
|
12
|
my %user2 = ( |
43
|
|
|
|
|
|
|
fname => 'Taras', |
44
|
|
|
|
|
|
|
lname => 'Schevchenko', |
45
|
|
|
|
|
|
|
age => '64', |
46
|
|
|
|
|
|
|
gender => 'male' |
47
|
|
|
|
|
|
|
); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
subtest 'Getting users' => sub { |
50
|
3
|
|
|
3
|
|
2710
|
ok( $st->set('user1', {%user1}), 'should create "user1" and return true' ); |
51
|
3
|
|
|
|
|
1347
|
ok( $st->set('user2', {%user2}), 'should create "user2" and return true' ); |
52
|
|
|
|
|
|
|
|
53
|
3
|
|
|
|
|
1111
|
cmp_deeply($st->get('user1'), {%user1, _id => 'user1'}, 'should return "user1" attrs'); |
54
|
3
|
|
|
|
|
33371
|
cmp_deeply($st->get('user2'), {%user2, _id => 'user2'}, 'should return "user2" attrs'); |
55
|
3
|
|
|
|
|
27
|
}; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub test_set { |
60
|
3
|
|
|
3
|
0
|
10
|
my $self = shift; |
61
|
3
|
|
|
|
|
9
|
my $st = $self->{storage}; |
62
|
|
|
|
|
|
|
|
63
|
3
|
|
|
|
|
18
|
my %user1 = ( |
64
|
|
|
|
|
|
|
fname => 'Ivan', |
65
|
|
|
|
|
|
|
lname => 'Ivanov', |
66
|
|
|
|
|
|
|
age => '21', |
67
|
|
|
|
|
|
|
gender => 'male' |
68
|
|
|
|
|
|
|
); |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
subtest 'Set and Update user' => sub { |
72
|
3
|
|
|
3
|
|
1679
|
ok( $st->set('user1', {%user1}), 'should create "user1" and return true' ); |
73
|
3
|
|
|
|
|
1033
|
cmp_deeply($st->get('user1'), {%user1, _id => 'user1'}, 'should return "user1" attrs'); |
74
|
|
|
|
|
|
|
|
75
|
3
|
|
|
|
|
3471
|
ok( $st->set('user1', {lname => 'NewLname', age => 33}), 'should update "user1" and return true' ); |
76
|
3
|
|
|
|
|
1030
|
my $updated_user = $st->get('user1'); |
77
|
|
|
|
|
|
|
|
78
|
3
|
|
|
|
|
47
|
is( $updated_user->{_id}, 'user1', '_id should should contain object id'); |
79
|
3
|
|
|
|
|
928
|
is( $updated_user->{fname}, 'Ivan', 'fname should be the same as before'); |
80
|
3
|
|
|
|
|
942
|
is( $updated_user->{lname}, 'NewLname', 'lname should contain new value - "NewLname"'); |
81
|
3
|
|
|
|
|
1046
|
is( $updated_user->{age}, '33', 'age should contain new value - "33"'); |
82
|
3
|
|
|
|
|
975
|
is( $updated_user->{gender}, 'male', 'gender should be the same as before'); |
83
|
3
|
|
|
|
|
34
|
}; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub test_del { |
87
|
3
|
|
|
3
|
0
|
7
|
my $self = shift; |
88
|
3
|
|
|
|
|
6
|
my $st = $self->{storage}; |
89
|
|
|
|
|
|
|
|
90
|
3
|
|
|
|
|
54
|
my %user1 = ( |
91
|
|
|
|
|
|
|
fname => 'Ivan', |
92
|
|
|
|
|
|
|
lname => 'Ivanov', |
93
|
|
|
|
|
|
|
age => '21', |
94
|
|
|
|
|
|
|
gender => 'male' |
95
|
|
|
|
|
|
|
); |
96
|
|
|
|
|
|
|
|
97
|
3
|
|
|
|
|
11
|
my %user2 = ( |
98
|
|
|
|
|
|
|
fname => 'Taras', |
99
|
|
|
|
|
|
|
lname => 'Schevchenko', |
100
|
|
|
|
|
|
|
age => '64', |
101
|
|
|
|
|
|
|
gender => 'male' |
102
|
|
|
|
|
|
|
); |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
subtest 'Deleting users' => sub { |
105
|
3
|
|
|
3
|
|
1519
|
ok( $st->set('user1', {%user1}), 'should create "user1" and return true' ); |
106
|
3
|
|
|
|
|
962
|
ok( $st->set('user2', {%user2}), 'should create "user2" and return true' ); |
107
|
|
|
|
|
|
|
|
108
|
3
|
|
|
|
|
1100
|
ok( $st->del('user1'), 'should delete "user1" and return true' ); |
109
|
|
|
|
|
|
|
|
110
|
3
|
|
|
|
|
1075
|
ok( !$st->get('user1'), 'should return undef because "user1" was deleted'); |
111
|
3
|
|
|
|
|
1100
|
cmp_deeply($st->get('user2'), {%user2, _id => 'user2'}, 'should return not deleted "user2"'); |
112
|
|
|
|
|
|
|
|
113
|
3
|
|
|
|
|
4159
|
ok( $st->del('user2'), 'should delete "user2" and return true' ); |
114
|
3
|
|
|
|
|
1122
|
ok( !$st->get('user1'), 'should return undef because "user2" was deleted'); |
115
|
3
|
|
|
|
|
22
|
}; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub test_list { |
120
|
3
|
|
|
3
|
0
|
7
|
my $self = shift; |
121
|
3
|
|
|
|
|
35
|
my $st = $self->{storage}; |
122
|
|
|
|
|
|
|
|
123
|
3
|
|
|
|
|
21
|
my %user1 = ( |
124
|
|
|
|
|
|
|
fname => 'Ivan', |
125
|
|
|
|
|
|
|
lname => 'Ivanov', |
126
|
|
|
|
|
|
|
age => '30', |
127
|
|
|
|
|
|
|
gender => 'male' |
128
|
|
|
|
|
|
|
); |
129
|
|
|
|
|
|
|
|
130
|
3
|
|
|
|
|
9
|
my %user2 = ( |
131
|
|
|
|
|
|
|
fname => 'Taras', |
132
|
|
|
|
|
|
|
lname => 'Leleka', |
133
|
|
|
|
|
|
|
age => '64', |
134
|
|
|
|
|
|
|
gender => 'male' |
135
|
|
|
|
|
|
|
); |
136
|
|
|
|
|
|
|
|
137
|
3
|
|
|
|
|
45
|
my %user3 = ( |
138
|
|
|
|
|
|
|
fname => 'Taras', |
139
|
|
|
|
|
|
|
lname => 'Schevchenko', |
140
|
|
|
|
|
|
|
age => '22', |
141
|
|
|
|
|
|
|
gender => 'male' |
142
|
|
|
|
|
|
|
); |
143
|
|
|
|
|
|
|
|
144
|
3
|
|
|
|
|
9
|
my %user4 = ( |
145
|
|
|
|
|
|
|
fname => 'Petrik', |
146
|
|
|
|
|
|
|
lname => 'Pyatochkin', |
147
|
|
|
|
|
|
|
age => '8', |
148
|
|
|
|
|
|
|
gender => 'male' |
149
|
|
|
|
|
|
|
); |
150
|
|
|
|
|
|
|
|
151
|
3
|
|
|
|
|
11
|
my %user5 = ( |
152
|
|
|
|
|
|
|
fname => 'Lesya', |
153
|
|
|
|
|
|
|
lname => 'Ukrainka', |
154
|
|
|
|
|
|
|
age => '30', |
155
|
|
|
|
|
|
|
gender => 'female' |
156
|
|
|
|
|
|
|
); |
157
|
|
|
|
|
|
|
|
158
|
3
|
|
|
|
|
19
|
$st->set('user1', {%user1}); |
159
|
3
|
|
|
|
|
17
|
$user1{_id} = 'user1'; |
160
|
|
|
|
|
|
|
|
161
|
3
|
|
|
|
|
18
|
$st->set('user2', {%user2}); |
162
|
3
|
|
|
|
|
17
|
$user2{_id} = 'user2'; |
163
|
|
|
|
|
|
|
|
164
|
3
|
|
|
|
|
18
|
$st->set('user3', {%user3}); |
165
|
3
|
|
|
|
|
16
|
$user3{_id} = 'user3'; |
166
|
|
|
|
|
|
|
|
167
|
3
|
|
|
|
|
21
|
$st->set('user4', {%user4}); |
168
|
3
|
|
|
|
|
21
|
$user4{_id} = 'user4'; |
169
|
|
|
|
|
|
|
|
170
|
3
|
|
|
|
|
24
|
$st->set('user5', {%user5}); |
171
|
3
|
|
|
|
|
18
|
$user5{_id} = 'user5'; |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
subtest 'List users' => sub { |
174
|
3
|
|
|
3
|
|
2037
|
cmp_bag($st->list(), [\%user1, \%user2, \%user3, \%user4, \%user5], 'should return all users'); |
175
|
3
|
|
|
|
|
52474
|
cmp_bag($st->list([fname => 'Ivan']), [\%user1], 'simple query should return user with fname="Ivan" users'); |
176
|
3
|
|
|
|
|
4466
|
cmp_bag($st->list([fname => ['Ivan']]), [\%user1], 'should return user with fname="Ivan" users'); |
177
|
3
|
|
|
|
|
4466
|
cmp_bag($st->list( where => [ |
178
|
|
|
|
|
|
|
fname => ['Ivan', 'Taras', 'Petrik', 'Lesya'], |
179
|
|
|
|
|
|
|
age => {'>=' => 30 }, |
180
|
|
|
|
|
|
|
gender => { 'like' => 'ma%' }, |
181
|
|
|
|
|
|
|
]), [\%user2, \%user1], 'complex query should return "Ivan" and "Taras" '); |
182
|
|
|
|
|
|
|
|
183
|
3
|
|
|
|
|
10332
|
cmp_deeply($st->list( |
184
|
|
|
|
|
|
|
where => [ |
185
|
|
|
|
|
|
|
fname => ['Ivan', 'Taras', 'Petrik', 'Lesya'], |
186
|
|
|
|
|
|
|
age => {'>=' => 30 }, |
187
|
|
|
|
|
|
|
], |
188
|
|
|
|
|
|
|
sort_by => 'age DESC, fname ASC', |
189
|
|
|
|
|
|
|
), [\%user2, \%user1, \%user5], 'complex query with sort should return "Ivan" "Taras" '); |
190
|
3
|
|
|
|
|
28
|
}; |
191
|
|
|
|
|
|
|
} |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
sub test_count { |
194
|
3
|
|
|
3
|
0
|
7
|
my $self = shift; |
195
|
3
|
|
|
|
|
8
|
my $st = $self->{storage}; |
196
|
|
|
|
|
|
|
|
197
|
3
|
|
|
|
|
16
|
my %user1 = ( |
198
|
|
|
|
|
|
|
fname => 'Ivan', |
199
|
|
|
|
|
|
|
lname => 'Ivanov', |
200
|
|
|
|
|
|
|
age => '30', |
201
|
|
|
|
|
|
|
gender => 'male' |
202
|
|
|
|
|
|
|
); |
203
|
|
|
|
|
|
|
|
204
|
3
|
|
|
|
|
9
|
my %user2 = ( |
205
|
|
|
|
|
|
|
fname => 'Taras', |
206
|
|
|
|
|
|
|
lname => 'Leleka', |
207
|
|
|
|
|
|
|
age => '64', |
208
|
|
|
|
|
|
|
gender => 'male' |
209
|
|
|
|
|
|
|
); |
210
|
|
|
|
|
|
|
|
211
|
3
|
|
|
|
|
11
|
my %user3 = ( |
212
|
|
|
|
|
|
|
fname => 'Taras', |
213
|
|
|
|
|
|
|
lname => 'Schevchenko', |
214
|
|
|
|
|
|
|
age => '22', |
215
|
|
|
|
|
|
|
gender => 'male' |
216
|
|
|
|
|
|
|
); |
217
|
|
|
|
|
|
|
|
218
|
3
|
|
|
|
|
9
|
my %user4 = ( |
219
|
|
|
|
|
|
|
fname => 'Petrik', |
220
|
|
|
|
|
|
|
lname => 'Pyatochkin', |
221
|
|
|
|
|
|
|
age => '8', |
222
|
|
|
|
|
|
|
gender => 'male' |
223
|
|
|
|
|
|
|
); |
224
|
|
|
|
|
|
|
|
225
|
3
|
|
|
|
|
9
|
my %user5 = ( |
226
|
|
|
|
|
|
|
fname => 'Lesya', |
227
|
|
|
|
|
|
|
lname => 'Ukrainka', |
228
|
|
|
|
|
|
|
age => '30', |
229
|
|
|
|
|
|
|
gender => 'female' |
230
|
|
|
|
|
|
|
); |
231
|
|
|
|
|
|
|
|
232
|
3
|
|
|
|
|
20
|
$st->set('user1', {%user1}); |
233
|
3
|
|
|
|
|
33
|
$st->set('user2', {%user2}); |
234
|
3
|
|
|
|
|
29
|
$st->set('user3', {%user3}); |
235
|
3
|
|
|
|
|
29
|
$st->set('user4', {%user4}); |
236
|
3
|
|
|
|
|
28
|
$st->set('user5', {%user5}); |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
subtest 'Count users' => sub { |
239
|
3
|
|
|
3
|
|
1849
|
is($st->count(), 5, 'should return 5 '); |
240
|
3
|
|
|
|
|
1186
|
is($st->count([fname => 'Ivan']), 1, 'should return 1'); |
241
|
3
|
|
|
|
|
1009
|
is($st->count([fname => ['Ivan']]), 1, 'should return 1'); |
242
|
3
|
|
|
|
|
1040
|
is($st->count( [ |
243
|
|
|
|
|
|
|
fname => ['Ivan', 'Taras', 'Petrik', 'Lesya'], |
244
|
|
|
|
|
|
|
age => {'>=' => 30 }, |
245
|
|
|
|
|
|
|
gender => { 'like' => 'ma%' }, |
246
|
|
|
|
|
|
|
]), 2, 'complex query: should return 2'); |
247
|
|
|
|
|
|
|
|
248
|
3
|
|
|
|
|
1130
|
is($st->count( [ |
249
|
|
|
|
|
|
|
fname => ['Ivan', 'Taras', 'Petrik', 'Lesya'], |
250
|
|
|
|
|
|
|
age => {'>=' => 30 }, |
251
|
|
|
|
|
|
|
]), 3, 'complex query: should return 3 '); |
252
|
3
|
|
|
|
|
34
|
}; |
253
|
|
|
|
|
|
|
} |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
1; |