CHI/t/Util.pm

filter: Statementstmt 100% 53 / 53 Branchbran 100% 2 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 16 / 16 Podpod 0.0% 0 / 4 totaltotal 94.6% 71 / 75 SCAR 6.9
CC
2
Cov
100%
test_parse_memory_size
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 2.0
« CHI/t/Driver/Subcache.pm ↑ Summary CHI/Driver/Null.pm »
1 package CHI::t::Util;
2 1 $CHI::t::Util::VERSION = '0.59';
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use CHI::Test;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use CHI::Util qw(unique_id parse_memory_size);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use CHI::Test::Util qw(random_string);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use List::MoreUtils qw(uniq);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use base qw(CHI::Test::Class);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 # The inevitably lame unique_id test
12 sub test_unique_id : Tests {
13 1 ▶ my @ids = map { unique_id } ( 0 .. 9 );
Subroutine test_unique_id: called CC=1 SCAR=0.0
Pod undocumented
14 1 cmp_deeply( \@ids, [ uniq(@ids) ], 'generated ten unique ids' );
15 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 sub test_random_string : Tests {
18 1 ▶ my @strings = map { random_string(100) } ( 0 .. 2 );
Subroutine test_random_string: called CC=1 SCAR=0.0
Pod undocumented
19 1 cmp_deeply(
20 \@strings,
21 [ uniq(@strings) ],
22 'generated three unique strings'
23 );
24 cmp_deeply(
25 1 [ map { length($_) } @strings ],
26 [ 100, 100, 100 ],
27 'lengths are 100'
28 );
29 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31 sub test_non_common_constructor_params : Tests {
32 my $params =
33 1 ▶ { map { ( $_, 1 ) } qw( foo expires_in bar baz on_get_error ) };
Subroutine test_non_common_constructor_params: called CC=1 SCAR=0.0
Pod undocumented
34 1 my $non_common_params = CHI::Driver->non_common_constructor_params($params);
35 1 cmp_deeply( $non_common_params, { map { ( $_, 1 ) } qw(foo bar baz) } );
36 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
37  
38 sub test_parse_memory_size : Tests {
39 1 ▶ my %results = (
Subroutine test_parse_memory_size: called CC=2 SCAR=6.9
Pod undocumented
40 '12345' => '12345',
41 '50K' => 50 * 1024,
42 '8Mb' => 8 * 1024 * 1024,
43 '301k' => 301 * 1024,
44 );
45 1 ▶ while ( my ( $input, $expected ) = each(%results) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %results) 4 1 5
46 4 is( parse_memory_size($input), $expected );
47 }
48 1 ▶ throws_ok { parse_memory_size('8kk') } qr/cannot parse/;
Subroutine __ANON__: called CC=1 SCAR=0.0
49 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
50  
51 1 1;
« CHI/t/Driver/Subcache.pm ↑ Summary CHI/Driver/Null.pm »