File Coverage

lib/Test/Chai/Core/Assertions/Within.pm
Criterion Covered Total %
statement 26 26 100.0
branch 3 4 75.0
condition 5 6 83.3
subroutine 7 7 100.0
pod 0 1 0.0
total 41 44 93.1


line stmt bran cond sub pod time code
1             package Test::Chai::Core::Assertions::Within;
2 2     2   9 use strict;
  2         4  
  2         55  
3 2     2   9 use warnings;
  2         4  
  2         50  
4 2     2   9 use utf8;
  2         5  
  2         18  
5              
6 2     2   53 use Exporter qw/import/;
  2         4  
  2         116  
7             our @EXPORT_OK = qw/assert_within/;
8              
9 2     2   10 use Test::Chai::Util::Flag qw/flag/;
  2         3  
  2         97  
10 2     2   9 use Test::Chai::Util::GenericLength qw/generic_length/;
  2         4  
  2         389  
11              
12             sub assert_within {
13 9     9 0 12 my ($self, $start, $finish, $msg) = @_;
14              
15 9 50       20 flag($self, 'message', $msg) if defined $msg;
16 9         22 my $obj = flag($self, 'object');
17 9         23 my $range = $start . '..' . $finish;
18              
19 9 100       20 if (flag($self, 'do_length')) {
20 3         11 my $len = generic_length($obj);
21 3   66     25 return $self->assert(
22             $len >= $start && $len < $finish,
23             'expected #{this} to have a length within ' . $range,
24             'expected #{this} to not have a length within ' . $range
25             );
26             }
27              
28             else {
29 6   100     44 return $self->assert(
30             $obj >= $start && $obj <= $finish,
31             'expected #{this} to be within ' . $range,
32             'expected #{this} to not be within ' . $range
33             );
34             }
35             }
36              
37             1;