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