line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CHI::t::Util; |
2
|
|
|
|
|
|
|
$CHI::t::Util::VERSION = '0.60'; |
3
|
1
|
|
|
1
|
|
305
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
33
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
22
|
|
5
|
1
|
|
|
1
|
|
315
|
use CHI::Test; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
10
|
|
6
|
1
|
|
|
1
|
|
8
|
use CHI::Util qw(unique_id parse_memory_size); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
70
|
|
7
|
1
|
|
|
1
|
|
5
|
use CHI::Test::Util qw(random_string); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
44
|
|
8
|
1
|
|
|
1
|
|
6
|
use List::MoreUtils qw(uniq); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
19
|
|
9
|
1
|
|
|
1
|
|
467
|
use base qw(CHI::Test::Class); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
516
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# The inevitably lame unique_id test |
12
|
|
|
|
|
|
|
sub test_unique_id : Tests { |
13
|
1
|
|
|
1
|
0
|
1500
|
my @ids = map { unique_id } ( 0 .. 9 ); |
|
10
|
|
|
|
|
19
|
|
14
|
1
|
|
|
|
|
27
|
cmp_deeply( \@ids, [ uniq(@ids) ], 'generated ten unique ids' ); |
15
|
1
|
|
|
1
|
|
12
|
} |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub test_random_string : Tests { |
18
|
1
|
|
|
1
|
0
|
870
|
my @strings = map { random_string(100) } ( 0 .. 2 ); |
|
3
|
|
|
|
|
10
|
|
19
|
1
|
|
|
|
|
23
|
cmp_deeply( |
20
|
|
|
|
|
|
|
\@strings, |
21
|
|
|
|
|
|
|
[ uniq(@strings) ], |
22
|
|
|
|
|
|
|
'generated three unique strings' |
23
|
|
|
|
|
|
|
); |
24
|
3
|
|
|
|
|
12
|
cmp_deeply( |
25
|
1
|
|
|
|
|
5242
|
[ map { length($_) } @strings ], |
26
|
|
|
|
|
|
|
[ 100, 100, 100 ], |
27
|
|
|
|
|
|
|
'lengths are 100' |
28
|
|
|
|
|
|
|
); |
29
|
1
|
|
|
1
|
|
376
|
} |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
3
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub test_non_common_constructor_params : Tests { |
32
|
5
|
|
|
|
|
14
|
my $params = |
33
|
1
|
|
|
1
|
0
|
964
|
{ map { ( $_, 1 ) } qw( foo expires_in bar baz on_get_error ) }; |
34
|
1
|
|
|
|
|
11
|
my $non_common_params = CHI::Driver->non_common_constructor_params($params); |
35
|
1
|
|
|
|
|
3
|
cmp_deeply( $non_common_params, { map { ( $_, 1 ) } qw(foo bar baz) } ); |
|
3
|
|
|
|
|
10
|
|
36
|
1
|
|
|
1
|
|
350
|
} |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub test_parse_memory_size : Tests { |
39
|
1
|
|
|
1
|
0
|
11119
|
my %results = ( |
40
|
|
|
|
|
|
|
'12345' => '12345', |
41
|
|
|
|
|
|
|
'50K' => 50 * 1024, |
42
|
|
|
|
|
|
|
'8Mb' => 8 * 1024 * 1024, |
43
|
|
|
|
|
|
|
'301k' => 301 * 1024, |
44
|
|
|
|
|
|
|
); |
45
|
1
|
|
|
|
|
7
|
while ( my ( $input, $expected ) = each(%results) ) { |
46
|
4
|
|
|
|
|
725
|
is( parse_memory_size($input), $expected ); |
47
|
|
|
|
|
|
|
} |
48
|
1
|
|
|
1
|
|
232
|
throws_ok { parse_memory_size('8kk') } qr/cannot parse/; |
|
1
|
|
|
|
|
75
|
|
49
|
1
|
|
|
1
|
|
327
|
} |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
7
|
|
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
1; |