TestML1/Compiler/Pegex/AST.pm

filter: Statementstmt 100% 94 / 94 Branchbran 83.3% 25 / 30 Conditioncond 58.8% 10 / 17 MC/DCmcdc 44.4% 4 / 9 Subroutinesub 100% 22 / 22 Podpod 0.0% 0 / 19 totaltotal 81.1% 155 / 191 CC 25 SCAR 13.5
CC
25
Cov
91%
got_call_object
7.2
got_code_statement
6.0
got_assertion_call
6.0
CRAP 3.9
« TestML1/Runtime/TAP.pm ↑ Summary TestML1.pm »
1 package TestML1::Compiler::Pegex::AST;
2  
3 22 ▶use TestML1::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 22 extends 'Pegex::Tree';
5  
6 22 ▶use TestML1::Runtime;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 22 has points => [];
9 21 ▶has function => sub { TestML1::Function->new };
Subroutine __ANON__: called CC=1 SCAR=0.0
10  
11 # sub final {
12 # my ($self, $match, $top) = @_;
13 # XXX $match;
14 # }
15 # __END__
16  
17 21 ▶sub got_code_section {
Subroutine got_code_section: called CC=1 SCAR=0.0
Pod undocumented
18 21 my ($self, $code) = @_;
19 21 $self->function->{statements} = $code;
20 }
21  
22 54 ▶sub got_assignment_statement {
Subroutine got_assignment_statement: called CC=1 SCAR=0.0
Pod undocumented
23 54 my ($self, $match) = @_;
24 54 return TestML1::Assignment->new(
25 name => $match->[0],
26 expr => $match->[1],
27 );
28 }
29  
30 92 ▶sub got_code_statement {
Subroutine got_code_statement: called CC=6 SCAR=17.9
Pod undocumented
31 92 my ($self, $list) = @_;
32 92 my ($expression, $assertion);
33 92 my $points = $self->points;
34 92 $self->{points} = [];
35  
36 92 for (@$list) {
37 174 ▶ if (ref eq 'TestML1::Assertion') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_ eq 'TestML1::Assertion') { } 82 92 174
38 82 $assertion = $_;
39 }
40 else {
41 #if (ref eq 'TestML1::Expression') {
42 92 $expression = $_;
43 }
44 }
45 92 ▶ return TestML1::Statement->new(
Branch: 3 branches
BranchTrueFalseTotal
$expression ? : 92 0 92
$assertion ? : 82 10 92
@$points ? : 33 59 92
46 $expression ? ( expr => $expression ) : (),
47 $assertion ? ( assert => $assertion ) : (),
48 @$points ? ( points => $points ) : (),
49 );
50 }
51  
52 246 ▶sub got_code_expression {
Subroutine got_code_expression: called CC=5 SCAR=16.2
Pod undocumented
53 246 my ($self, $list) = @_;
54 246 my $calls = [];
55 246 ▶ push @$calls, shift @$list if @$list;
Branch: 1 branch
BranchTrueFalseTotal
if @$list 246 0 246
56 246 ▶ $list = shift @$list || [];
Condition50%1/2
shift @$list || []
l!l
2460
MC/DC0%0/1
shift @$list || []
shift @$list
Truth table50%1/2
A
A= shift @$list
Aresult
11
00
57 246 for (@$list) {
58 80 my $call = $_->[0]; #->{call_call}[0][0];
59 80 push @$calls, $call;
60 }
61 246 ▶ return $calls->[0] if @$calls == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @$calls == 1 191 55 246
62 55 return TestML1::Expression->new(
63 calls => $calls,
64 );
65 }
66  
67 76 ▶sub got_string_object {
Subroutine got_string_object: called CC=1 SCAR=0.0
Pod undocumented
68 76 my ($self, $string) = @_;
69 76 return TestML1::Str->new(
70 value => $string,
71 );
72 }
73  
74 10 ▶sub got_double_quoted_string {
Subroutine got_double_quoted_string: called CC=1 SCAR=0.0
Pod undocumented
75 10 my ($self, $string) = @_;
76 10 $string =~ s/\\n/\n/g;
77 10 return $string;
78 }
79  
80 35 ▶sub got_number_object {
Subroutine got_number_object: called CC=1 SCAR=0.0
Pod undocumented
81 35 my ($self, $number) = @_;
82 35 return TestML1::Num->new(
83 value => $number + 0,
84 );
85 }
86  
87 65 ▶sub got_point_object {
Subroutine got_point_object: called CC=2 SCAR=7.0
Pod undocumented
88 65 my ($self, $point) = @_;
89 65 ▶ $point =~ s/^\*// or die;
Branch: 1 branch
BranchTrueFalseTotal
$point =~ s/^\*// or die 65 0 65
90 65 push @{$self->points}, $point;
91 65 return TestML1::Point->new(
92 name => $point,
93 );
94 }
95  
96 82 ▶sub got_assertion_call {
Subroutine got_assertion_call: called CC=6 SCAR=17.9
Pod undocumented
97 82 my ($self, $call) = @_;
98 # XXX $call strangley becomes an array when $PERL_PEGEX_DEBUG is on.
99 # Workaround for now, until I figure it out.
100 82 ▶ $call = $call->[0] if ref $call eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $call eq "ARRAY" 0 82 82
101 82 my ($name, $expr);
102 82 for (qw( eq has ok )) {
103 124 ▶ if ($expr = $call->{"assertion_$_"}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expr = $$call{"assertion_$_"}) 82 42 124
104 82 $name = uc $_;
105 $expr =
106 $expr->{"assertion_operator_$_"}[0] ||
107 82 ▶ $expr->{"assertion_function_$_"}[0];
Condition100%3/3
$$expr{"assertion_operator_$_"}[0] || $$expr{"assertion_function_$_"}[0]
l!l&&r!l&&!r
61219
MC/DC100%2/2
$$expr{"assertion_operator_$_"}[0] || $$expr{"assertion_function_$_"}[0]
$$expr{"assertion_operator_$_"}[0] $$expr{"assertion_function_$_"}[0]
Truth table100%3/3
A || B
A= $$expr{"assertion_operator_$_"}[0]B= $$expr{"assertion_function_$_"}[0]
ABresult
1X1
011
000
108 82 last;
109 }
110 }
111 82 ▶ return TestML1::Assertion->new(
Branch: 1 branch
BranchTrueFalseTotal
$expr ? : 63 19 82
112 name => $name,
113 $expr ? (expr => $expr) : (),
114 );
115 }
116  
117 19 ▶sub got_assertion_function_ok {
Subroutine got_assertion_function_ok: called CC=1 SCAR=0.0
Pod undocumented
118 19 my ($self, $ok) = @_;
119 return {
120 19 assertion_function_ok => [],
121 }
122 }
123  
124 11 ▶sub got_function_start {
Subroutine got_function_start: called CC=1 SCAR=0.0
Pod undocumented
125 11 my ($self) = @_;
126 11 my $function = TestML1::Function->new;
127 11 $function->outer($self->function);
128 11 $self->{function} = $function;
129 11 return 1;
130 }
131  
132 11 ▶sub got_function_object {
Subroutine got_function_object: called CC=3 SCAR=11.0
Pod undocumented
133 11 my ($self, $object) = @_;
134  
135 11 my $function = $self->function;
136 11 $self->{function} = $function->outer;
137  
138 11 ▶ if (ref($object->[0]) and ref($object->[0][0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $object->[0] and ref $object->[0][0]) 5 6 11
Condition100%3/3
ref $object->[0] and ref $object->[0][0]
!ll&&!rl&&r
515
MC/DC100%2/2
ref $object->[0] and ref $object->[0][0]
ref $object->[0] ref $object->[0][0]
Truth table100%3/3
A and B
A= ref $object->[0]B= ref $object->[0][0]
ABresult
0X0
100
111
139 5 $function->{signature} = $object->[0][0];
140 }
141 11 $function->{statements} = $object->[-1];
142  
143 11 return $function;
144 }
145  
146 139 ▶sub got_call_name {
Subroutine got_call_name: called CC=1 SCAR=0.0
Pod undocumented
147 139 my ($self, $name) = @_;
148 139 return TestML1::Call->new(name => $name);
149 }
150  
151 139 ▶sub got_call_object {
Subroutine got_call_object: called CC=6 SCAR=19.7
Pod undocumented
152 139 my ($self, $object) = @_;
153 139 my $call = $object->[0];
154 139 my $args = $object->[1][-1];
155 139 ▶ if ($args) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args) 35 104 139
156 $args = [
157 map {
158 35 ▶ ($_->isa('TestML1::Expression') and @{$_->calls} == 1 and
Branch: 1 branch
BranchTrueFalseTotal
$_->isa('TestML1::Expression') && @{$_->calls;} == 1 && ($_->calls->[0]->isa('TestML1::Point') || $_->calls->[0]->isa('TestML1::Object')) ? : 0 37 37
Condition33%3/9
$_->isa("TestML1::Expression") and @{$_->calls;} == 1 and $_->calls->[0]->isa("TestML1::Point") || $_->calls->[0]->isa("TestML1::Object")
!ll&&!rl&&r
3700
$_->isa("TestML1::Expression") and @{$_->calls;} == 1
!ll&&!rl&&r
3610
$_->calls->[0]->isa("TestML1::Point") or $_->calls->[0]->isa("TestML1::Object")
l!l&&r!l&&!r
000
MC/DC0%0/4
$_->isa("TestML1::Expression") and @{$_->calls;} == 1 and $_->calls->[0]->isa("TestML1::Point") || $_->calls->[0]->isa("TestML1::Object")
$_->isa("TestML1::Expression") @{$_->calls;} == 1 $_->calls->[0]->isa("TestML1::Point") $_->calls->[0]->isa("TestML1::Object")
Truth table40%2/5
A and B and C or D
A= $_->isa("TestML1::Expression")B= @{$_->calls;} == 1C= $_->calls->[0]->isa("TestML1::Point")D= $_->calls->[0]->isa("TestML1::Object")
ABCDresult
0XXX0
10XX0
11000
111X1
11011
159 (
160 $_->calls->[0]->isa('TestML1::Point') ||
161 $_->calls->[0]->isa('TestML1::Object')
162 )) ? $_->calls->[0] : $_;
163 } @$args
164 ];
165 35 $call->args($args)
166 }
167 139 return $call;
168 }
169  
170 35 ▶sub got_call_argument_list {
Subroutine got_call_argument_list: called CC=1 SCAR=0.0
Pod undocumented
171 35 my ($self, $list) = @_;
172 35 return $list;
173 }
174  
175 80 ▶sub got_call_indicator {
Subroutine got_call_indicator: called CC=1 SCAR=0.0
Pod undocumented
176 80 my ($self) = @_;
177 80 return;
178 }
179  
180 14 ▶sub got_data_section {
Subroutine got_data_section: called CC=1 SCAR=0.0
Pod undocumented
181 14 my ($self, $data) = @_;
182 14 $self->function->data($data);
183 }
184  
185 35 ▶sub got_data_block {
Subroutine got_data_block: called CC=1 SCAR=0.0
Pod undocumented
186 35 my ($self, $block) = @_;
187 return TestML1::Block->new(
188 label => $block->[0][0][0],
189 35 points => +{map %$_, @{$block->[1]}},
190 );
191 }
192  
193 83 ▶sub got_block_point {
Subroutine got_block_point: called CC=3 SCAR=11.0
Pod undocumented
194 83 my ($self, $point) = @_;
195 83 my ($name, $value) = @$point;
196 83 ▶ my $eol = ($value =~ s/(\r?\n)\s*\z//) ? $1 : '';
Branch: 1 branch
BranchTrueFalseTotal
$value =~ s/(\r?\n)\s*\z// ? : 22 61 83
197 83 ▶ if (length $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $value) 82 1 83
198 82 $value .= $eol;
199 }
200 83 return { $name => $value };
201 }
202  
203 22 1;
« TestML1/Runtime/TAP.pm ↑ Summary TestML1.pm »