Diff3/Diff3.pm

filter: Statementstmt 92.3% 72 / 78 Branchbran 86.6% 26 / 30 Conditioncond 77.7% 7 / 9 MC/DCmcdc 66.6% 4 / 6 Subroutinesub 100% 7 / 7 Podpod 100% 1 / 1 totaltotal 89.3% 117 / 131 CC 20 SCAR 26.8
CC
20
Cov
90%
diff3
19.4
_is_a_text
2.1
BEGIN
1.0
CRAP 14.6
« Diff3.pm ↑ Summary Diff3/Text.pm »
1 package Text::Diff3::Diff3;
2 # diff3 component
3 6 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 6 ▶use base qw(Text::Diff3::Base);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 6 ▶use version; our $VERSION = '0.08';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 # the three-way diff procedure based on the GNU diff3.c by Randy Smith.
12 21 ▶sub diff3 {
Subroutine diff3: called CC=19 SCAR=29.7
Pod documented
13 21 my($self, $text0, $text2, $text1) = @_;
14 21 my $f = $self->factory;
15 21 ▶ if (! $self->_is_a_text($text0)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_is_a_text($text0)) 0 21 21
16 0 $text0 = $f->create_text($text0);
17 }
18 21 ▶ if (! $self->_is_a_text($text2)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_is_a_text($text2)) 0 21 21
19 0 $text0 = $f->create_text($text2);
20 }
21 21 ▶ if (! $self->_is_a_text($text1)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_is_a_text($text1)) 0 21 21
22 0 $text0 = $f->create_text($text1);
23 }
24 21 my $diffp = $f->create_diff;
25 21 my @diff2 = (
26 $diffp->diff($text2, $text0),
27 $diffp->diff($text2, $text1),
28 );
29 21 my $diff3 = $f->create_list3;
30 21 my $range3 = $f->create_null_range3;
31 21 ▶ while (! $diff2[0]->is_empty || ! $diff2[1]->is_empty) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($diff2[0]->is_empty and $diff2[1]->is_empty) 33 21 54
Condition100%3/3
$diff2[0]->is_empty and $diff2[1]->is_empty
!ll&&!rl&&r
231021
MC/DC100%2/2
$diff2[0]->is_empty and $diff2[1]->is_empty
$diff2[0]->is_empty $diff2[1]->is_empty
Truth table100%3/3
A and B
A= $diff2[0]->is_emptyB= $diff2[1]->is_empty
ABresult
0X0
100
111
32 # find a continual range in text2 $lo2..$hi2
33 # changed by text0 or by text1.
34 #
35 # diff2[0] 222 222222222
36 # text2 ...L!!!!!!!!!!!!!!!!!!!!H...
37 # diff2[1] 222222 22 2222222
38 33 my @range2 = ([], []);
39 33 ▶ my $i =
Branch: 3 branches
BranchTrueFalseTotal
$diff2[0]->is_empty ? : 10 23 33
$diff2[1]->is_empty ? : 9 14 23
$diff2[0]->first->loA <= $diff2[1]->first->loA ? : 12 2 14
40 $diff2[0]->is_empty ? 1
41 : $diff2[1]->is_empty ? 0
42 : $diff2[0]->first->loA <= $diff2[1]->first->loA ? 0
43 : 1;
44 33 my $j = $i;
45 33 my $k = $i ^ 1;
46 33 my $hi = $diff2[$j]->first->hiA;
47 33 push @{$range2[$j]}, $diff2[$j]->shift;
48 33 ▶ while (! $diff2[$k]->is_empty && $diff2[$k]->first->loA <= $hi + 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $diff2[$k]->is_empty and $diff2[$k]->first->loA <= $hi + 1) 10 33 43
Condition100%3/3
not $diff2[$k]->is_empty and $diff2[$k]->first->loA <= $hi + 1
!ll&&!rl&&r
25810
MC/DC100%2/2
not $diff2[$k]->is_empty and $diff2[$k]->first->loA <= $hi + 1
not $diff2[$k]->is_empty $diff2[$k]->first->loA <= $hi + 1
Truth table100%3/3
not(A) and B
A= not $diff2[$k]->is_emptyB= $diff2[$k]->first->loA <= $hi + 1
ABresult
0X0
100
111
49 10 my $hi_k = $diff2[$k]->first->hiA;
50 10 push @{$range2[$k]}, $diff2[$k]->shift;
51 10 ▶ if ($hi < $hi_k) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hi < $hi_k) 0 10 10
52 0 $hi = $hi_k;
53 0 $j = $k;
54 0 $k = $k ^ 1;
55 }
56 }
57 33 my $lo2 = $range2[$i][ 0]->loA;
58 33 my $hi2 = $range2[$j][-1]->hiA;
59 # take the corresponding ranges in text0 $lo0..$hi0
60 # and in text1 $lo1..$hi1.
61 #
62 # text0 ..L!!!!!!!!!!!!!!!!!!!!!!!!!!!!H...
63 # diff2[0] 222 222222222
64 # text2 ...00!1111!000!!00!111111...
65 # diff2[1] 222222 22 2222222
66 # text1 ...L!!!!!!!!!!!!!!!!H...
67 33 my($lo0, $hi0);
68 33 ▶ if (@{$range2[0]}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$range2[0];}) { } 21 12 33
69 21 $lo0 = $range2[0][ 0]->loB - $range2[0][ 0]->loA + $lo2;
70 21 $hi0 = $range2[0][-1]->hiB - $range2[0][-1]->hiA + $hi2;
71 } else {
72 12 $lo0 = $range3->hi0 - $range3->hi2 + $lo2;
73 12 $hi0 = $range3->hi0 - $range3->hi2 + $hi2;
74 }
75 33 my($lo1, $hi1);
76 33 ▶ if (@{$range2[1]}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$range2[1];}) { } 22 11 33
77 22 $lo1 = $range2[1][ 0]->loB - $range2[1][ 0]->loA + $lo2;
78 22 $hi1 = $range2[1][-1]->hiB - $range2[1][-1]->hiA + $hi2;
79 } else {
80 11 $lo1 = $range3->hi1 - $range3->hi2 + $lo2;
81 11 $hi1 = $range3->hi1 - $range3->hi2 + $hi2;
82 }
83 33 $range3 = $f->create_range3(
84 undef, $lo0, $hi0, $lo1, $hi1, $lo2, $hi2
85 );
86 # detect type of changes.
87 33 ▶ if (! @{$range2[0]}) {
Branch: 3 branches
BranchTrueFalseTotal
if (not @{$range2[0];}) { } 12 21 33
elsif (not @{$range2[1];}) { } 11 10 21
elsif ($hi0 - $lo0 != $hi1 - $lo1) { } 2 8 10
88 12 $range3->type('1');
89 21 } elsif (! @{$range2[1]}) {
90 11 $range3->type('0');
91 } elsif ($hi0 - $lo0 != $hi1 - $lo1) {
92 2 $range3->type('A');
93 } else {
94 8 $range3->type('2');
95 8 for my $d (0 .. $hi0 - $lo0) {
96 13 ▶ if (! $text0->eq_at($lo0 + $d, $text1->at($lo1 + $d))) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($text0->eq_at($lo0 + $d, $text1->at($lo1 + $d))) 2 11 13
97 2 $range3->type('A');
98 2 last;
99 }
100 }
101 }
102 33 $diff3->push($range3);
103 }
104 21 return $diff3;
105 }
106  
107 63 ▶sub _is_a_text {
Subroutine _is_a_text: called CC=2 SCAR=7.4
108 63 my($self, $x) = @_;
109 63 ▶ return eval{ $x->can('at') } && eval{ $x->can('eq_at') };
Condition33%1/3
eval { do { $x->can('at') } } && eval { do { $x->can('eq_at') } }
!ll&&!rl&&r
0063
MC/DC0%0/2
eval { do { $x->can('at') } } && eval { do { $x->can('eq_at') } }
eval { do { $x->can('at') } } eval { do { $x->can('eq_at') } }
Truth table33%1/3
A && B
A= eval { do { $x->can('at') } }B= eval { do { $x->can('eq_at') } }
ABresult
0X0
100
111
110 }
111  
112 6 1;
113  
114 __END__
« Diff3.pm ↑ Summary Diff3/Text.pm »