line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CHI::t::Util; |
2
|
|
|
|
|
|
|
$CHI::t::Util::VERSION = '0.61'; |
3
|
1
|
|
|
1
|
|
394
|
use strict; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
30
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
24
|
|
5
|
1
|
|
|
1
|
|
398
|
use CHI::Test; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
6
|
|
6
|
1
|
|
|
1
|
|
7
|
use CHI::Util qw(unique_id parse_memory_size); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
50
|
|
7
|
1
|
|
|
1
|
|
5
|
use CHI::Test::Util qw(random_string); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
45
|
|
8
|
1
|
|
|
1
|
|
6
|
use List::MoreUtils qw(uniq); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
13
|
|
9
|
1
|
|
|
1
|
|
716
|
use base qw(CHI::Test::Class); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
470
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# The inevitably lame unique_id test |
12
|
|
|
|
|
|
|
sub test_unique_id : Tests { |
13
|
1
|
|
|
1
|
0
|
2192
|
my @ids = map { unique_id } ( 0 .. 9 ); |
|
10
|
|
|
|
|
19
|
|
14
|
1
|
|
|
|
|
15
|
cmp_deeply( \@ids, [ uniq(@ids) ], 'generated ten unique ids' ); |
15
|
1
|
|
|
1
|
|
8
|
} |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub test_random_string : Tests { |
18
|
1
|
|
|
1
|
0
|
1587
|
my @strings = map { random_string(100) } ( 0 .. 2 ); |
|
3
|
|
|
|
|
10
|
|
19
|
1
|
|
|
|
|
13
|
cmp_deeply( |
20
|
|
|
|
|
|
|
\@strings, |
21
|
|
|
|
|
|
|
[ uniq(@strings) ], |
22
|
|
|
|
|
|
|
'generated three unique strings' |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
cmp_deeply( |
25
|
1
|
|
|
|
|
4692
|
[ map { length($_) } @strings ], |
|
3
|
|
|
|
|
10
|
|
26
|
|
|
|
|
|
|
[ 100, 100, 100 ], |
27
|
|
|
|
|
|
|
'lengths are 100' |
28
|
|
|
|
|
|
|
); |
29
|
1
|
|
|
1
|
|
357
|
} |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
3
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub test_non_common_constructor_params : Tests { |
32
|
|
|
|
|
|
|
my $params = |
33
|
1
|
|
|
1
|
0
|
1713
|
{ map { ( $_, 1 ) } qw( foo expires_in bar baz on_get_error ) }; |
|
5
|
|
|
|
|
13
|
|
34
|
1
|
|
|
|
|
8
|
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
|
|
|
|
|
8
|
|
36
|
1
|
|
|
1
|
|
331
|
} |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
4
|
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub test_parse_memory_size : Tests { |
39
|
1
|
|
|
1
|
0
|
11802
|
my %results = ( |
40
|
|
|
|
|
|
|
'12345' => '12345', |
41
|
|
|
|
|
|
|
'50K' => 50 * 1024, |
42
|
|
|
|
|
|
|
'8Mb' => 8 * 1024 * 1024, |
43
|
|
|
|
|
|
|
'301k' => 301 * 1024, |
44
|
|
|
|
|
|
|
); |
45
|
1
|
|
|
|
|
6
|
while ( my ( $input, $expected ) = each(%results) ) { |
46
|
4
|
|
|
|
|
1038
|
is( parse_memory_size($input), $expected ); |
47
|
|
|
|
|
|
|
} |
48
|
1
|
|
|
1
|
|
347
|
throws_ok { parse_memory_size('8kk') } qr/cannot parse/; |
|
1
|
|
|
|
|
78
|
|
49
|
1
|
|
|
1
|
|
406
|
} |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
4
|
|
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
1; |