Skilletor/JSString.pm

filter: Statementstmt 100% 37 / 37 Branchbran 75.0% 9 / 12 Conditioncond 40.0% 6 / 15 MC/DCmcdc 10.0% 1 / 10 Subroutinesub 100% 8 / 8 Podpod 100% 4 / 4 totaltotal 75.5% 65 / 86 CC 13 SCAR 19.6
CC
13
Cov
81%
_final_sigma
13.5
js_lc
5.0
js_blank
2.0
CRAP 7.1
« Skilletor/Source/Git.pm ↑ Summary Skilletor/Targets.pm »
1 package Skilletor::JSString;
2 # ABSTRACT: String operations as JavaScript performs them
3  
4 242 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 242 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 242 ▶use Exporter qw( import );
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 242 our $VERSION = '0.001';
10  
11 242 our @EXPORT_OK = qw( js_lc js_trim js_ws_re js_blank );
12  
13 # JavaScript's WhiteSpace and LineTerminator (what \s and String.prototype.trim take): unlike
14 # Perl's \s, U+FEFF is one and U+0085 is none.
15 242 my $WS = qr/[\t\n\x{0B}\f\r \x{A0}\x{1680}\x{2000}-\x{200A}\x{2028}\x{2029}\x{202F}\x{205F}\x{3000}\x{FEFF}]/;
16  
17 103 ▶sub js_ws_re { $WS }
Subroutine js_ws_re: called CC=1 SCAR=0.0
Pod documented
18  
19 12963 ▶sub js_trim {
Subroutine js_trim: called CC=1 SCAR=0.0
Pod documented
20 12963 my ( $s ) = @_;
21 12963 $s =~ s/\A$WS+//;
22 12963 $s =~ s/$WS+\z//;
23 12963 return $s;
24 }
25  
26 803 ▶sub js_blank {
Subroutine js_blank: called CC=2 SCAR=6.9
Pod documented
27 803 my ( $s ) = @_;
28 803 ▶ return js_trim($s) eq '' ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
js_trim($s) eq '' ? : 15 788 803
29 }
30  
31 # String.prototype.toLowerCase: Perl's full lower-case mapping, plus the one context rule
32 # JavaScript applies – a capital sigma ending a word is a final sigma.
33 12119 ▶sub js_lc {
Subroutine js_lc: called CC=5 SCAR=16.1
Pod documented
34 12119 my ( $s ) = @_;
35 12119 ▶ return lc $s unless $s =~ /\x{3A3}/;
Branch: 1 branch
BranchTrueFalseTotal
unless $s =~ /\x{3A3}/ 12118 1 12119
36 1 my @c = split //, $s;
37 1 my $out = '';
38 1 for my $i ( 0 .. $#c ) {
39 4 ▶ if ( $c[$i] eq "\x{3A3}" && _final_sigma( \@c, $i ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c[$i] eq "\x{3a3}" and _final_sigma(\@c, $i)) 1 3 4
Condition66%2/3
$c[$i] eq "\x{3a3}" and _final_sigma(\@c, $i)
!ll&&!rl&&r
301
MC/DC50%1/2
$c[$i] eq "\x{3a3}" and _final_sigma(\@c, $i)
$c[$i] eq "\x{3a3}" _final_sigma(\@c, $i)
Truth table66%2/3
A and B
A= $c[$i] eq "\x{3a3}"B= _final_sigma(\@c, $i)
ABresult
0X0
100
111
40 1 $out .= "\x{3C2}";
41 1 next;
42 }
43 3 $out .= lc $c[$i];
44 }
45 1 return $out;
46 }
47  
48 1 ▶sub _final_sigma {
Subroutine _final_sigma: called CC=8 SCAR=26.0
49 1 my ( $c, $i ) = @_;
50 1 my $j = $i - 1;
51 1 ▶ $j-- while $j >= 0 && $c->[$j] =~ /\p{Case_Ignorable}/;
Branch: 1 branch
BranchTrueFalseTotal
$j >= 0 and $c->[$j] =~ /\p{Case_Ignorable}/ and do { --$j } 0 1 1
Condition33%1/3
$j >= 0 and $c->[$j] =~ /\p{Case_Ignorable}/
!ll&&!rl&&r
010
MC/DC0%0/2
$j >= 0 and $c->[$j] =~ /\p{Case_Ignorable}/
$j >= 0 $c->[$j] =~ /\p{Case_Ignorable}/
Truth table33%1/3
A and B
A= $j >= 0B= $c->[$j] =~ /\p{Case_Ignorable}/
ABresult
0X0
100
111
52 1 ▶ return 0 unless $j >= 0 && $c->[$j] =~ /\p{Cased}/;
Branch: 1 branch
BranchTrueFalseTotal
unless $j >= 0 and $c->[$j] =~ /\p{Cased}/ 0 1 1
Condition33%1/3
$j >= 0 and $c->[$j] =~ /\p{Cased}/
!ll&&!rl&&r
001
MC/DC0%0/2
$j >= 0 and $c->[$j] =~ /\p{Cased}/
$j >= 0 $c->[$j] =~ /\p{Cased}/
Truth table33%1/3
A and B
A= $j >= 0B= $c->[$j] =~ /\p{Cased}/
ABresult
0X0
100
111
53 1 my $k = $i + 1;
54 1 ▶ $k++ while $k < @$c && $c->[$k] =~ /\p{Case_Ignorable}/;
Branch: 1 branch
BranchTrueFalseTotal
$k < @$c and $c->[$k] =~ /\p{Case_Ignorable}/ and do { ++$k } 0 1 1
Condition33%1/3
$k < @$c and $c->[$k] =~ /\p{Case_Ignorable}/
!ll&&!rl&&r
100
MC/DC0%0/2
$k < @$c and $c->[$k] =~ /\p{Case_Ignorable}/
$k < @$c $c->[$k] =~ /\p{Case_Ignorable}/
Truth table33%1/3
A and B
A= $k < @$cB= $c->[$k] =~ /\p{Case_Ignorable}/
ABresult
0X0
100
111
55 1 ▶ return !( $k < @$c && $c->[$k] =~ /\p{Cased}/ );
Condition33%1/3
$k < @$c && $c->[$k] =~ /\p{Cased}/
!ll&&!rl&&r
100
MC/DC0%0/2
$k < @$c && $c->[$k] =~ /\p{Cased}/
$k < @$c $c->[$k] =~ /\p{Cased}/
Truth table33%1/3
A && B
A= $k < @$cB= $c->[$k] =~ /\p{Cased}/
ABresult
0X0
100
111
56 }
57  
58 242 1;
59  
60 __END__
« Skilletor/Source/Git.pm ↑ Summary Skilletor/Targets.pm »