blib/lib/JavaScript/Beautifier.pm

filter: Statementstmt 98.3% 476 / 484 Branchbran 95.1% 291 / 306 Conditioncond 89.2% 225 / 252 MC/DCmcdc 72.9% 97 / 133 Subroutinesub 100% 18 / 18 Podpod 7.6% 1 / 13 totaltotal 91.8% 1108 / 1206 CC 242 SCAR 45.0
CC
242
Cov
95%
js_beautify
123.1
get_next_token
90.0
is_ternary_op
14.0
CRAP 90.1
↑ Summary Build »
1 package JavaScript::Beautifier;
2  
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use JavaScript::Packer1 qw/js_packer/;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 our $VERSION = '0.24';
8 2 our $AUTHORITY = 'cpan:FAYLAND';
9  
10 2 ▶use base 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use vars qw/@EXPORT_OK/;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 @EXPORT_OK = qw/js_beautify/;
13  
14 2 my ( @input, @output, @modes );
15 2 my ( $token_text, $last_type, $last_text, $last_last_text, $last_word, $current_mode, $indent_string, $parser_pos, $in_case, $prefix, $token_type, $do_block_just_closed, $var_line, $var_line_tainted, $if_line_flag, $wanted_newline, $just_added_newline );
16  
17 2 my @whitespace = split('', "\n\r\t ");
18 2 my @wordchar = split('', 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_$');
19 2 my @digits = split('', '0123456789');
20 # <!-- is a special case (ok, it's a minor hack actually)
21 2 my @punct = split(' ', '+ - * / % & ++ -- = += -= *= /= %= == === != !== > < >= <= >> << >>> >>>= >>= <<= && &= | || ! !! , : ? ^ ^= |= ::');
22 # words which should always start on new line.
23 2 my @line_starter = split(',', 'continue,try,throw,return,var,if,switch,case,default,for,while,break,function');
24  
25 2 my ( $opt_indent_level, $opt_indent_size, $opt_indent_character, $opt_preserve_newlines, $opt_space_after_anon_function );
26  
27 sub js_beautify {
28 280 ▶ my ( $js_source_code, $opts ) = @_;
Subroutine js_beautify: called CC=122 SCAR=48.1
Pod documented
29  
30 280 $js_source_code = js_packer($js_source_code);
31  
32 280 ▶ $opt_indent_size = $opts->{indent_size} || 4;
Condition50%1/2
$opts->{'indent_size'} || 4
l!l
2800
MC/DC0%0/1
$opts->{'indent_size'} || 4
$opts->{'indent_size'}
Truth table50%1/2
A
A= $opts->{'indent_size'}
Aresult
11
00
33 280 ▶ $opt_indent_character = $opts->{indent_character} || ' ';
Condition50%1/2
$opts->{'indent_character'} || ' '
l!l
2800
MC/DC0%0/1
$opts->{'indent_character'} || ' '
$opts->{'indent_character'}
Truth table50%1/2
A
A= $opts->{'indent_character'}
Aresult
11
00
34 280 ▶ $opt_preserve_newlines = exists $opts->{preserve_newlines} ? $opts->{preserve_newlines} : 1;
Branch: 1 branch
BranchTrueFalseTotal
exists $opts->{'preserve_newlines'} ? : 280 0 280
35 280 ▶ $opt_indent_level = $opts->{indent_level} ||= 0;
Condition50%1/2
$opts->{"indent_level"} ||= 0
l!l
0280
MC/DC0%0/1
$opts->{"indent_level"} ||= 0
$opts->{"indent_level"}
Truth table50%1/2
A
A= $opts->{"indent_level"}
Aresult
11
00
36 280 ▶ $opt_space_after_anon_function = exists $opts->{space_after_anon_function} ? $opts->{space_after_anon_function} : 0;
Branch: 1 branch
BranchTrueFalseTotal
exists $opts->{'space_after_anon_function'} ? : 280 0 280
37  
38 # -------------------------------------
39 280 $just_added_newline = 0;
40 280 $indent_string = '';
41 280 ▶ while ( $opt_indent_size-- ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt_indent_size--) 1105 280 1385
42 1105 $indent_string .= $opt_indent_character;
43 }
44 280 @input = split('', $js_source_code);
45  
46 280 $last_word = ''; # last 'TK_WORD' passed
47 280 $last_type = 'TK_START_EXPR'; # last token type
48 280 $last_text = ''; # last token text
49 280 $last_last_text = ''; # pre-last token text
50 280 @output = ();
51  
52 280 $do_block_just_closed = 0;
53 280 $var_line = 0;
54 280 $var_line_tainted = 0;
55  
56 # states showing if we are currently in expression (i.e. "if" case) - 'EXPRESSION', or in usual block (like, procedure), 'BLOCK'.
57 # some formatting depends on that.
58 280 $current_mode = 'BLOCK';
59 280 @modes = ( $current_mode );
60  
61 280 $parser_pos = 0; # parser position
62 280 $in_case = 0; # flag for parser that case/default has been processed, and next colon needs special attention
63 280 while ( 1 ) {
64 3474 my $t = get_next_token($parser_pos);
65 3474 $token_text = $t->[0];
66 3474 $token_type = $t->[1];
67 3474 ▶ if ( $token_type eq 'TK_EOF' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type eq "TK_EOF") 280 3194 3474
68 280 last;
69 }
70  
71 3194 ▶ if ( $token_type eq 'TK_START_EXPR' ) {
Branch: 11 branches
BranchTrueFalseTotal
if ($token_type eq 'TK_START_EXPR') { } 332 2862 3194
elsif ($token_type eq 'TK_END_EXPR') { } 319 2543 2862
elsif ($token_type eq 'TK_START_BLOCK') { } 254 2289 2543
elsif ($token_type eq 'TK_END_BLOCK') { } 251 2038 2289
elsif ($token_type eq 'TK_WORD') { } 1127 911 2038
elsif ($token_type eq 'TK_SEMICOLON') { } 292 619 911
elsif ($token_type eq 'TK_STRING') { } 88 531 619
elsif ($token_type eq 'TK_OPERATOR') { } 445 86 531
elsif ($token_type eq 'TK_BLOCK_COMMENT') { } 2 84 86
elsif ($token_type eq 'TK_COMMENT') { } 34 50 84
elsif ($token_type eq 'TK_UNKNOWN') { } 50 0 50
72 332 $var_line = 0;
73  
74 332 ▶ if ( $token_text eq '[' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_text eq '[') { } 76 256 332
75 76 ▶ if ( $last_type eq 'TK_WORD' || $last_text eq ')' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_type eq "TK_WORD" or $last_text eq ")") 24 52 76
Condition100%3/3
$last_type eq "TK_WORD" or $last_text eq ")"
l!l&&r!l&&!r
22252
MC/DC100%2/2
$last_type eq "TK_WORD" or $last_text eq ")"
$last_type eq "TK_WORD" $last_text eq ")"
Truth table100%3/3
A or B
A= $last_type eq "TK_WORD"B= $last_text eq ")"
ABresult
1X1
011
000
76 # this is array index specifier, break immediately
77 # a[x], fn()[x]
78 24 set_mode('(EXPRESSION)');
79 24 print_token();
80 24 $last_last_text = $last_text;$last_type = $token_type;$last_text = $token_text;next;
81 }
82 52 ▶ if ( $current_mode eq '[EXPRESSION]' || $current_mode eq '[INDENTED-EXPRESSION]' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($current_mode eq '[EXPRESSION]' or $current_mode eq '[INDENTED-EXPRESSION]') { } 30 22 52
Condition100%3/3
$current_mode eq "[EXPRESSION]" or $current_mode eq "[INDENTED-EXPRESSION]"
l!l&&r!l&&!r
161422
MC/DC100%2/2
$current_mode eq "[EXPRESSION]" or $current_mode eq "[INDENTED-EXPRESSION]"
$current_mode eq "[EXPRESSION]" $current_mode eq "[INDENTED-EXPRESSION]"
Truth table100%3/3
A or B
A= $current_mode eq "[EXPRESSION]"B= $current_mode eq "[INDENTED-EXPRESSION]"
ABresult
1X1
011
000
83 30 ▶ if ( $last_last_text eq ']' && $last_text eq ',' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($last_last_text eq ']' and $last_text eq ',') { } 16 14 30
elsif ($last_text eq '[') { } 10 4 14
Condition66%2/3
$last_last_text eq "]" and $last_text eq ","
!ll&&!rl&&r
14016
MC/DC50%1/2
$last_last_text eq "]" and $last_text eq ","
$last_last_text eq "]" $last_text eq ","
Truth table66%2/3
A and B
A= $last_last_text eq "]"B= $last_text eq ","
ABresult
0X0
100
111
84 # ], [ goes to new line
85 16 indent();
86 16 print_newline();
87 16 set_mode('[INDENTED-EXPRESSION]');
88 } elsif ($last_text eq '[') {
89 10 indent();
90 10 print_newline();
91 10 set_mode('[INDENTED-EXPRESSION]');
92 } else {
93 4 set_mode('[EXPRESSION]');
94 }
95 } else {
96 22 set_mode('[EXPRESSION]');
97 }
98 } else {
99 256 set_mode('(EXPRESSION)');
100 }
101  
102 308 ▶ if ( $last_text eq ';' || $last_type eq 'TK_START_BLOCK' ) {
Branch: 5 branches
BranchTrueFalseTotal
if ($last_text eq ';' or $last_type eq 'TK_START_BLOCK') { } 12 296 308
elsif ($last_type eq 'TK_END_EXPR' or $last_type eq 'TK_START_EXPR') { } 20 276 296
elsif ($last_type ne 'TK_WORD' and $last_type ne 'TK_OPERATOR') { } 6 270 276
elsif ($last_word eq 'function') { } 17 253 270
elsif (grep {$last_word eq $_;} @line_starter) { } 67 186 253
Condition100%3/3
$last_text eq ";" or $last_type eq "TK_START_BLOCK"
l!l&&r!l&&!r
210296
MC/DC100%2/2
$last_text eq ";" or $last_type eq "TK_START_BLOCK"
$last_text eq ";" $last_type eq "TK_START_BLOCK"
Truth table100%3/3
A or B
A= $last_text eq ";"B= $last_type eq "TK_START_BLOCK"
ABresult
1X1
011
000
103 12 print_newline();
104 ▶ } elsif ( $last_type eq 'TK_END_EXPR' || $last_type eq 'TK_START_EXPR' ) {
Condition100%3/3
$last_type eq "TK_END_EXPR" or $last_type eq "TK_START_EXPR"
l!l&&r!l&&!r
416276
MC/DC100%2/2
$last_type eq "TK_END_EXPR" or $last_type eq "TK_START_EXPR"
$last_type eq "TK_END_EXPR" $last_type eq "TK_START_EXPR"
Truth table100%3/3
A or B
A= $last_type eq "TK_END_EXPR"B= $last_type eq "TK_START_EXPR"
ABresult
1X1
011
000
105 # do nothing on (( and )( and ][ and ]( ..
106 ▶ } elsif ( $last_type ne 'TK_WORD' && $last_type ne 'TK_OPERATOR' ) {
Condition100%3/3
$last_type ne "TK_WORD" and $last_type ne "TK_OPERATOR"
!ll&&!rl&&r
230406
MC/DC100%2/2
$last_type ne "TK_WORD" and $last_type ne "TK_OPERATOR"
$last_type ne "TK_WORD" $last_type ne "TK_OPERATOR"
Truth table100%3/3
A and B
A= $last_type ne "TK_WORD"B= $last_type ne "TK_OPERATOR"
ABresult
0X0
100
111
107 6 print_space();
108 } elsif ( $last_word eq 'function' ) {
109 # function() vs function ()
110 17 ▶ if ( $opt_space_after_anon_function ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt_space_after_anon_function) 8 9 17
111 8 print_space();
112 }
113 3289 } elsif ( grep { $last_word eq $_ } @line_starter ) {
114 67 print_space();
115 }
116 308 print_token();
117 308 $last_last_text = $last_text;$last_type = $token_type;$last_text = $token_text;next;
118 } elsif ( $token_type eq 'TK_END_EXPR' ) {
119 319 ▶ if ( $token_text eq ']' && $current_mode eq '[INDENTED-EXPRESSION]' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_text eq "]" and $current_mode eq "[INDENTED-EXPRESSION]") 26 293 319
Condition100%3/3
$token_text eq "]" and $current_mode eq "[INDENTED-EXPRESSION]"
!ll&&!rl&&r
2435026
MC/DC100%2/2
$token_text eq "]" and $current_mode eq "[INDENTED-EXPRESSION]"
$token_text eq "]" $current_mode eq "[INDENTED-EXPRESSION]"
Truth table100%3/3
A and B
A= $token_text eq "]"B= $current_mode eq "[INDENTED-EXPRESSION]"
ABresult
0X0
100
111
120 26 unindent();
121 }
122 319 restore_mode();
123 319 print_token();
124 319 $last_last_text = $last_text;$last_type = $token_type;$last_text = $token_text;next;
125 } elsif ( $token_type eq 'TK_START_BLOCK' ) {
126 254 ▶ if ( $last_word eq 'do' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_word eq 'do') { } 10 244 254
127 10 set_mode('DO_BLOCK');
128 } else {
129 244 set_mode('BLOCK');
130 }
131 254 ▶ if ( $last_type ne 'TK_OPERATOR' && $last_type ne 'TK_START_EXPR' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_type ne "TK_OPERATOR" and $last_type ne "TK_START_EXPR") 87 167 254
Condition100%3/3
$last_type ne "TK_OPERATOR" and $last_type ne "TK_START_EXPR"
!ll&&!rl&&r
1015787
MC/DC100%2/2
$last_type ne "TK_OPERATOR" and $last_type ne "TK_START_EXPR"
$last_type ne "TK_OPERATOR" $last_type ne "TK_START_EXPR"
Truth table100%3/3
A and B
A= $last_type ne "TK_OPERATOR"B= $last_type ne "TK_START_EXPR"
ABresult
0X0
100
111
132 87 ▶ if ( $last_type eq 'TK_START_BLOCK' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_type eq 'TK_START_BLOCK') { } 19 68 87
133 19 print_newline();
134 } else {
135 68 print_space();
136 }
137 }
138 254 print_token();
139 254 indent();
140 254 $last_last_text = $last_text;$last_type = $token_type;$last_text = $token_text;next;
141 } elsif ( $token_type eq 'TK_END_BLOCK' ) {
142 251 ▶ if ( $last_type eq 'TK_START_BLOCK' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_type eq 'TK_START_BLOCK') { } 22 229 251
143 # nothing
144 22 ▶ if ($just_added_newline) {
Branch: 1 branch
BranchTrueFalseTotal
if ($just_added_newline) { } 4 18 22
145 4 remove_indent();
146 # {
147 #
148 # }
149 } else {
150 # {}
151 18 trim_output();
152 }
153 22 unindent();
154 } else {
155 229 unindent();
156 229 print_newline();
157 }
158 251 print_token();
159 251 restore_mode();
160 251 $last_last_text = $last_text;$last_type = $token_type;$last_text = $token_text;next;
161 } elsif ( $token_type eq 'TK_WORD' ) {
162 # no, it's not you. even I have problems understanding how this works
163 # and what does what.
164 1127 ▶ if ( $do_block_just_closed ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($do_block_just_closed) 10 1117 1127
165 10 print_space();
166 10 print_token();
167 10 print_space();
168 10 $do_block_just_closed = 0;
169 10 $last_last_text = $last_text;$last_type = $token_type;$last_text = $token_text;next;
170 }
171 1117 ▶ if ( $token_text eq 'case' || $token_text eq 'default' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_text eq "case" or $token_text eq "default") 10 1107 1117
Condition100%3/3
$token_text eq "case" or $token_text eq "default"
l!l&&r!l&&!r
821107
MC/DC100%2/2
$token_text eq "case" or $token_text eq "default"
$token_text eq "case" $token_text eq "default"
Truth table100%3/3
A or B
A= $token_text eq "case"B= $token_text eq "default"
ABresult
1X1
011
000
172 10 ▶ if ( $last_text eq ':' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_text eq ':') { } 2 8 10
173 # switch cases following one another
174 2 remove_indent();
175 } else {
176 # case statement starts in the same line where switch
177 8 unindent();
178 8 print_newline();
179 8 indent();
180 }
181 10 print_token();
182 10 $in_case = 1;
183 10 $last_last_text = $last_text;$last_type = $token_type;$last_text = $token_text;next;
184 }
185 1107 $prefix = 'NONE';
186 1107 ▶ if ( $last_type eq 'TK_END_BLOCK' ) {
Branch: 7 branches
BranchTrueFalseTotal
if ($last_type eq 'TK_END_BLOCK') { } 49 1058 1107
elsif ($last_type eq 'TK_SEMICOLON' and $current_mode eq 'BLOCK' || $current_mode eq 'DO_BLOCK') { } 51 1007 1058
elsif ($last_type eq 'TK_SEMICOLON' and is_expression($current_mode)) { } 6 1001 1007
elsif ($last_type eq 'TK_STRING') { } 7 994 1001
elsif ($last_type eq 'TK_WORD') { } 102 892 994
elsif ($last_type eq 'TK_START_BLOCK') { } 180 712 892
elsif ($last_type eq 'TK_END_EXPR') { } 67 645 712
187 49 ▶ if ( not (grep { lc($token_text) eq $_ } ('else', 'catch', 'finally')) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not grep({lc $token_text eq $_;} 'else', 'catch', 'finally')) { } 37 12 49
188 37 $prefix = 'NEWLINE';
189 } else {
190 12 $prefix = 'SPACE';
191 12 print_space();
192 }
193 ▶ } elsif ( $last_type eq 'TK_SEMICOLON' && ( $current_mode eq 'BLOCK' || $current_mode eq 'DO_BLOCK' ) ) {
Condition83%5/6
$last_type eq "TK_SEMICOLON" and $current_mode eq "BLOCK" || $current_mode eq "DO_BLOCK"
!ll&&!rl&&r
1001651
$current_mode eq "BLOCK" or $current_mode eq "DO_BLOCK"
l!l&&r!l&&!r
5106
MC/DC66%2/3
$last_type eq "TK_SEMICOLON" and $current_mode eq "BLOCK" || $current_mode eq "DO_BLOCK"
$last_type eq "TK_SEMICOLON" $current_mode eq "BLOCK" $current_mode eq "DO_BLOCK"
Truth table75%3/4
A and B or C
A= $last_type eq "TK_SEMICOLON"B= $current_mode eq "BLOCK"C= $current_mode eq "DO_BLOCK"
ABCresult
0XX0
1000
11X1
1011
194 51 $prefix = 'NEWLINE';
195 ▶ } elsif ( $last_type eq 'TK_SEMICOLON' && is_expression($current_mode) ) {
Condition66%2/3
$last_type eq "TK_SEMICOLON" and is_expression($current_mode)
!ll&&!rl&&r
100106
MC/DC50%1/2
$last_type eq "TK_SEMICOLON" and is_expression($current_mode)
$last_type eq "TK_SEMICOLON" is_expression($current_mode)
Truth table66%2/3
A and B
A= $last_type eq "TK_SEMICOLON"B= is_expression($current_mode)
ABresult
0X0
100
111
196 6 $prefix = 'SPACE';
197 } elsif ( $last_type eq 'TK_STRING') {
198 7 $prefix = 'NEWLINE';
199 } elsif ( $last_type eq 'TK_WORD' ) {
200 102 $prefix = 'SPACE';
201 } elsif ( $last_type eq 'TK_START_BLOCK') {
202 180 $prefix = 'NEWLINE';
203 } elsif ( $last_type eq 'TK_END_EXPR' ) {
204 67 print_space();
205 67 $prefix = 'NEWLINE';
206 }
207  
208 1107 ▶ if ( $last_type ne 'TK_END_BLOCK' && (grep { lc($token_text) eq $_ } ('else', 'catch', 'finally')) ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($last_type ne 'TK_END_BLOCK' and grep {lc $token_text eq $_;} 'else', 'catch', 'finally') { } 6 1101 1107
elsif (grep {$token_text eq $_;} @line_starter or $prefix eq 'NEWLINE') { } 426 675 1101
elsif ($prefix eq 'SPACE') { } 110 565 675
Condition100%3/3
$last_type ne "TK_END_BLOCK" and grep {lc $token_text eq $_;} "else", "catch", "finally"
!ll&&!rl&&r
4910526
MC/DC100%2/2
$last_type ne "TK_END_BLOCK" and grep {lc $token_text eq $_;} "else", "catch", "finally"
$last_type ne "TK_END_BLOCK" grep {lc $token_text eq $_;} "else", "catch", "finally"
Truth table100%3/3
A and B
A= $last_type ne "TK_END_BLOCK"B= grep {lc $token_text eq $_;} "else", "catch", "finally"
ABresult
0X0
100
111
209 6 print_newline();
210 14313 ▶ } elsif ( (grep { $token_text eq $_ } @line_starter) || $prefix eq 'NEWLINE' ) {
Condition100%3/3
grep {$token_text eq $_;} @line_starter or $prefix eq "NEWLINE"
l!l&&r!l&&!r
154272675
MC/DC100%2/2
grep {$token_text eq $_;} @line_starter or $prefix eq "NEWLINE"
grep {$token_text eq $_;} @line_starter $prefix eq "NEWLINE"
Truth table100%3/3
A or B
A= grep {$token_text eq $_;} @line_starterB= $prefix eq "NEWLINE"
ABresult
1X1
011
000
211 426 ▶ if ( $last_text eq 'else' ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($last_text eq 'else') { } 4 422 426
elsif ($last_type eq 'TK_START_EXPR' || $last_text eq '=' || $last_text eq ',' and $token_text eq 'function') { } 20 402 422
elsif ($last_text eq 'return' or $last_text eq 'throw') { } 0 402 402
elsif ($last_type ne 'TK_END_EXPR') { } 339 63 402
212 # no need to force newline on else break
213 4 print_space();
214 ▶ } elsif ( ( $last_type eq 'TK_START_EXPR' || $last_text eq '=' || $last_text eq ',' ) && $token_text eq 'function' ) {
Condition100%9/9
$last_type eq "TK_START_EXPR" || $last_text eq "=" || $last_text eq "," and $token_text eq "function"
!ll&&!rl&&r
3515120
$last_type eq "TK_START_EXPR" or $last_text eq "=" or $last_text eq ","
l!l&&r!l&&!r
674351
$last_type eq "TK_START_EXPR" or $last_text eq "="
l!l&&r!l&&!r
634355
MC/DC100%4/4
$last_type eq "TK_START_EXPR" || $last_text eq "=" || $last_text eq "," and $token_text eq "function"
$last_type eq "TK_START_EXPR" $last_text eq "=" $last_text eq "," $token_text eq "function"
Truth table71%5/7
A or B or C and D
A= $last_type eq "TK_START_EXPR"B= $last_text eq "="C= $last_text eq ","D= $token_text eq "function"
ABCDresult
000X0
1XX00
01X00
00100
1XX11
01X11
00111
215 # no need to force newline on 'function': (function
216 # DONOTHING
217 ▶ } elsif ( $last_text eq 'return' || $last_text eq 'throw' ) {
Condition33%1/3
$last_text eq "return" or $last_text eq "throw"
l!l&&r!l&&!r
00402
MC/DC0%0/2
$last_text eq "return" or $last_text eq "throw"
$last_text eq "return" $last_text eq "throw"
Truth table33%1/3
A or B
A= $last_text eq "return"B= $last_text eq "throw"
ABresult
1X1
011
000
218 # no newline between 'return nnn'
219 0 print_space();
220 } elsif ( $last_type ne 'TK_END_EXPR' ) {
221 339 ▶ if ( ($last_type ne 'TK_START_EXPR' || $token_text ne 'var') && $last_text ne ':' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_type ne "TK_START_EXPR" || $token_text ne "var" and $last_text ne ":") 311 28 339
Condition100%6/6
$last_type ne "TK_START_EXPR" || $token_text ne "var" and $last_text ne ":"
!ll&&!rl&&r
226311
$last_type ne "TK_START_EXPR" or $token_text ne "var"
l!l&&r!l&&!r
2882922
MC/DC100%3/3
$last_type ne "TK_START_EXPR" || $token_text ne "var" and $last_text ne ":"
$last_type ne "TK_START_EXPR" $token_text ne "var" $last_text ne ":"
Truth table80%4/5
A or B and C
A= $last_type ne "TK_START_EXPR"B= $token_text ne "var"C= $last_text ne ":"
ABCresult
00X0
1X00
0100
1X11
0111
222 # no need to force newline on 'var': for (var x = 0...)
223 311 ▶ if ( $token_text eq 'if' && $last_word eq 'else' && $last_text ne '{' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_text eq 'if' and $last_word eq 'else' and $last_text ne '{') { } 0 311 311
Condition83%5/6
$token_text eq "if" and $last_word eq "else" and $last_text ne "{"
!ll&&!rl&&r
30920
$token_text eq "if" and $last_word eq "else"
!ll&&!rl&&r
266432
MC/DC0%0/3
$token_text eq "if" and $last_word eq "else" and $last_text ne "{"
$token_text eq "if" $last_word eq "else" $last_text ne "{"
Truth table75%3/4
A and B and C
A= $token_text eq "if"B= $last_word eq "else"C= $last_text ne "{"
ABCresult
0XX0
10X0
1100
1111
224 # no newline for } else if {
225 0 print_space();
226 } else {
227 311 print_newline();
228 }
229 }
230 } else {
231 63 ▶ if ( (grep { $token_text eq $_ } @line_starter) && $last_text ne ')' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$token_text eq $_;} @line_starter and $last_text ne ")") 2 61 63
Condition100%3/3
grep {$token_text eq $_;} @line_starter and $last_text ne ")"
!ll&&!rl&&r
5922
MC/DC100%2/2
grep {$token_text eq $_;} @line_starter and $last_text ne ")"
grep {$token_text eq $_;} @line_starter $last_text ne ")"
Truth table100%3/3
A and B
A= grep {$token_text eq $_;} @line_starterB= $last_text ne ")"
ABresult
0X0
100
111
232 2 print_newline();
233 }
234 }
235 } elsif ( $prefix eq 'SPACE' ) {
236 110 print_space();
237 }
238 1107 print_token();
239 1107 $last_word = $token_text;
240 1107 ▶ if ( $token_text eq 'var' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_text eq "var") 36 1071 1107
241 36 $var_line = 1;
242 36 $var_line_tainted = 0;
243 }
244 1107 ▶ if ( $token_text eq 'if' || $token_text eq 'else' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_text eq "if" or $token_text eq "else") 65 1042 1107
Condition100%3/3
$token_text eq "if" or $token_text eq "else"
l!l&&r!l&&!r
51141042
MC/DC100%2/2
$token_text eq "if" or $token_text eq "else"
$token_text eq "if" $token_text eq "else"
Truth table100%3/3
A or B
A= $token_text eq "if"B= $token_text eq "else"
ABresult
1X1
011
000
245 65 $if_line_flag = 1;
246 }
247 1107 $last_last_text = $last_text;$last_type = $token_type;$last_text = $token_text;next;
248 } elsif ( $token_type eq 'TK_SEMICOLON' ) {
249 292 print_token();
250 292 $var_line = 0;
251 292 $last_last_text = $last_text;$last_type = $token_type;$last_text = $token_text;next;
252 } elsif ( $token_type eq 'TK_STRING' ) {
253 88 ▶ if ( $last_type eq 'TK_START_BLOCK' || $last_type eq 'TK_END_BLOCK' || $last_type eq 'TK_SEMICOLON' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($last_type eq 'TK_START_BLOCK' or $last_type eq 'TK_END_BLOCK' or $last_type eq 'TK_SEMICOLON') { } 10 78 88
elsif ($last_type eq 'TK_WORD') { } 0 78 78
Condition100%6/6
$last_type eq "TK_START_BLOCK" or $last_type eq "TK_END_BLOCK" or $last_type eq "TK_SEMICOLON"
l!l&&r!l&&!r
8278
$last_type eq "TK_START_BLOCK" or $last_type eq "TK_END_BLOCK"
l!l&&r!l&&!r
6280
MC/DC100%3/3
$last_type eq "TK_START_BLOCK" or $last_type eq "TK_END_BLOCK" or $last_type eq "TK_SEMICOLON"
$last_type eq "TK_START_BLOCK" $last_type eq "TK_END_BLOCK" $last_type eq "TK_SEMICOLON"
Truth table100%4/4
A or B or C
A= $last_type eq "TK_START_BLOCK"B= $last_type eq "TK_END_BLOCK"C= $last_type eq "TK_SEMICOLON"
ABCresult
1XX1
01X1
0011
0000
254 10 print_newline();
255 } elsif ( $last_type eq 'TK_WORD' ) {
256 0 print_space();
257 }
258 88 print_token();
259 88 $last_last_text = $last_text;$last_type = $token_type;$last_text = $token_text;next;
260 } elsif ( $token_type eq 'TK_OPERATOR' ) {
261 445 my $start_delim = 1;
262 445 my $end_delim = 1;
263 445 ▶ if ( $var_line && $token_text ne ',' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($var_line and $token_text ne ",") 54 391 445
Condition100%3/3
$var_line and $token_text ne ","
!ll&&!rl&&r
3632854
MC/DC100%2/2
$var_line and $token_text ne ","
$var_line $token_text ne ","
Truth table100%3/3
A and B
A= $var_lineB= $token_text ne ","
ABresult
0X0
100
111
264 54 $var_line_tainted = 1;
265 54 ▶ if ( $token_text eq ':' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_text eq ":") 2 52 54
266 2 $var_line = 0;
267 }
268 }
269 445 ▶ if ($var_line && $token_text eq ',' && is_expression($current_mode) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($var_line and $token_text eq "," and is_expression($current_mode)) 10 435 445
Condition100%6/6
$var_line and $token_text eq "," and is_expression($current_mode)
!ll&&!rl&&r
4171810
$var_line and $token_text eq ","
!ll&&!rl&&r
3655228
MC/DC100%3/3
$var_line and $token_text eq "," and is_expression($current_mode)
$var_line $token_text eq "," is_expression($current_mode)
Truth table100%4/4
A and B and C
A= $var_lineB= $token_text eq ","C= is_expression($current_mode)
ABCresult
0XX0
10X0
1100
1111
270 # do not break on comma, for(var a = 1, b = 2)
271 10 $var_line_tainted = 0;
272 }
273 445 ▶ if ( $token_text eq ':' && $in_case ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_text eq ":" and $in_case) 10 435 445
Condition100%3/3
$token_text eq ":" and $in_case
!ll&&!rl&&r
3775810
MC/DC100%2/2
$token_text eq ":" and $in_case
$token_text eq ":" $in_case
Truth table100%3/3
A and B
A= $token_text eq ":"B= $in_case
ABresult
0X0
100
111
274 10 print_token(); # colon really asks for separate treatment
275 10 print_newline();
276 10 $in_case = 0;
277 10 $last_last_text = $last_text;$last_type = $token_type;$last_text = $token_text;next;
278 }
279 435 ▶ if ( $token_text eq '::' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_text eq "::") 2 433 435
280 # no spaces around exotic namespacing syntax operator
281 2 print_token();
282 2 $last_last_text = $last_text;$last_type = $token_type;$last_text = $token_text;next;
283 }
284  
285 433 ▶ if ( $token_text eq ',' ) {
Branch: 8 branches
BranchTrueFalseTotal
if ($token_text eq ',') { } 130 303 433
elsif ($token_text eq '--' or $token_text eq '++') { } 16 287 303
elsif ($token_text eq '!' || $token_text eq '+' || $token_text eq '-' and $last_text eq 'return' || $last_text eq 'case') { } 8 279 287
elsif ($token_text eq '!' || $token_text eq '+' || $token_text eq '-' and $last_type eq 'TK_START_EXPR') { } 6 273 279
elsif ($last_type eq 'TK_OPERATOR') { } 11 262 273
elsif ($last_type eq 'TK_END_EXPR') { } 8 254 262
elsif ($token_text eq '.') { } 0 254 254
elsif ($token_text eq ':') { } 56 198 254
286 130 ▶ if ($var_line) {
Branch: 2 branches
BranchTrueFalseTotal
if ($var_line) { } 28 102 130
elsif ($last_type eq 'TK_END_BLOCK') { } 4 98 102
287 28 ▶ if ( $var_line_tainted ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($var_line_tainted) { } 6 22 28
288 6 print_token();
289 6 print_newline();
290 6 $var_line_tainted = 0;
291 } else {
292 22 print_token();
293 22 print_space();
294 }
295 } elsif ( $last_type eq 'TK_END_BLOCK' ) {
296 4 print_token();
297 4 print_newline();
298 } else {
299 98 ▶ if ( $current_mode eq 'BLOCK' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($current_mode eq 'BLOCK') { } 18 80 98
300 18 print_token();
301 18 print_newline();
302 } else {
303 # EXPR or DO_BLOCK
304 80 print_token();
305 80 print_space();
306 }
307 }
308 130 $last_last_text = $last_text;$last_type = $token_type;$last_text = $token_text;next;
309 ▶ } elsif ( $token_text eq '--' || $token_text eq '++' ) { # unary operators special case
Condition100%3/3
$token_text eq "--" or $token_text eq "++"
l!l&&r!l&&!r
412287
MC/DC100%2/2
$token_text eq "--" or $token_text eq "++"
$token_text eq "--" $token_text eq "++"
Truth table100%3/3
A or B
A= $token_text eq "--"B= $token_text eq "++"
ABresult
1X1
011
000
310 16 ▶ if ( $last_text eq ';' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_text eq ';') { } 6 10 16
311 6 ▶ if ( $current_mode eq 'BLOCK') {
Branch: 1 branch
BranchTrueFalseTotal
if ($current_mode eq 'BLOCK') { } 4 2 6
312 # { foo; --i }
313 4 print_newline();
314 4 $start_delim = 1;
315 4 $end_delim = 0;
316 } else {
317 # space for (;; ++i)
318 2 $start_delim = 1;
319 2 $end_delim = 0;
320 }
321 } else {
322 10 ▶ if ($last_text eq '{') {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_text eq "{") 4 6 10
323 # {--i
324 4 print_newline();
325 }
326 10 $start_delim = 0;
327 10 $end_delim = 0;
328 }
329 ▶ } elsif ( ( $token_text eq '!' || $token_text eq '+' || $token_text eq '-' ) && ($last_text eq 'return' || $last_text eq 'case') ) {
Condition100%12/12
$token_text eq "!" || $token_text eq "+" || $token_text eq "-" and $last_text eq "return" || $last_text eq "case"
!ll&&!rl&&r
261188
$token_text eq "!" or $token_text eq "+" or $token_text eq "-"
l!l&&r!l&&!r
1412261
$token_text eq "!" or $token_text eq "+"
l!l&&r!l&&!r
86273
$last_text eq "return" or $last_text eq "case"
l!l&&r!l&&!r
4418
MC/DC80%4/5
$token_text eq "!" || $token_text eq "+" || $token_text eq "-" and $last_text eq "return" || $last_text eq "case"
$token_text eq "!" $token_text eq "+" $token_text eq "-" $last_text eq "return" $last_text eq "case"
Truth table80%8/10
A or B or C and D or E
A= $token_text eq "!"B= $token_text eq "+"C= $token_text eq "-"D= $last_text eq "return"E= $last_text eq "case"
ABCDEresult
000XX0
1XX000
01X000
001000
1XX1X1
1XX011
01X1X1
01X011
0011X1
001011
330 8 $start_delim = 1;
331 8 $end_delim = 0;
332 ▶ } elsif ( ( $token_text eq '!' || $token_text eq '+' || $token_text eq '-' ) && $last_type eq 'TK_START_EXPR' ) {
Condition100%9/9
$token_text eq "!" || $token_text eq "+" || $token_text eq "-" and $last_type eq "TK_START_EXPR"
!ll&&!rl&&r
261126
$token_text eq "!" or $token_text eq "+" or $token_text eq "-"
l!l&&r!l&&!r
108261
$token_text eq "!" or $token_text eq "+"
l!l&&r!l&&!r
46269
MC/DC100%4/4
$token_text eq "!" || $token_text eq "+" || $token_text eq "-" and $last_type eq "TK_START_EXPR"
$token_text eq "!" $token_text eq "+" $token_text eq "-" $last_type eq "TK_START_EXPR"
Truth table100%7/7
A or B or C and D
A= $token_text eq "!"B= $token_text eq "+"C= $token_text eq "-"D= $last_type eq "TK_START_EXPR"
ABCDresult
000X0
1XX00
01X00
00100
1XX11
01X11
00111
333 # special case handling: if (!a)
334 6 $start_delim = 0;
335 6 $end_delim = 0;
336 } elsif ( $last_type eq 'TK_OPERATOR' ) {
337 11 $start_delim = 0;
338 11 $end_delim = 0;
339 } elsif ( $last_type eq 'TK_END_EXPR' ) {
340 8 $start_delim = 1;
341 8 $end_delim = 1;
342 } elsif ( $token_text eq '.' ) {
343 # decimal digits or object.property
344 0 $start_delim = 0;
345 0 $end_delim = 0;
346 } elsif ( $token_text eq ':' ) {
347 56 ▶ if (is_ternary_op()) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_ternary_op()) { } 18 38 56
348 18 $start_delim = 1;
349 } else {
350 38 $start_delim = 0;
351 }
352 }
353 303 ▶ if ( $start_delim ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($start_delim) 238 65 303
354 238 print_space();
355 }
356 303 print_token();
357 303 ▶ if ( $end_delim ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($end_delim) 262 41 303
358 262 print_space();
359 }
360 303 $last_last_text = $last_text;$last_type = $token_type;$last_text = $token_text;next;
361 } elsif ($token_type eq 'TK_BLOCK_COMMENT') {
362 2 print_newline();
363 2 print_token();
364 2 print_newline();
365 2 $last_last_text = $last_text;$last_type = $token_type;$last_text = $token_text;next;
366 } elsif ($token_type eq 'TK_COMMENT') {
367 # print_newline();
368 34 print_space();
369 34 print_token();
370 34 print_newline();
371 34 $last_last_text = $last_text;$last_type = $token_type;$last_text = $token_text;next;
372 } elsif ($token_type eq 'TK_UNKNOWN') {
373 50 print_token();
374 50 $last_last_text = $last_text;$last_type = $token_type;$last_text = $token_text;next;
375 }
376 0 $last_type = $token_type;
377 0 $last_text = $token_text;
378 }
379  
380 280 my $output = join('', @output);
381 280 $output =~ s/\n+$//;
382 280 return $output;
383 }
384  
385 sub trim_output {
386 985 ▶ while ( scalar @output && ( $output[ scalar @output - 1 ] eq ' ' || $output[ scalar @output - 1 ] eq $indent_string ) ) {
Subroutine trim_output: called CC=4 SCAR=13.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @output and $output[scalar @output - 1] eq " " || $output[scalar @output - 1] eq $indent_string) 205 985 1190
Condition100%6/6
scalar @output and $output[scalar @output - 1] eq " " || $output[scalar @output - 1] eq $indent_string
!ll&&!rl&&r
29956205
$output[scalar @output - 1] eq " " or $output[scalar @output - 1] eq $indent_string
l!l&&r!l&&!r
22183956
MC/DC100%3/3
scalar @output and $output[scalar @output - 1] eq " " || $output[scalar @output - 1] eq $indent_string
scalar @output $output[scalar @output - 1] eq " " $output[scalar @output - 1] eq $indent_string
Truth table100%4/4
A and B or C
A= scalar @outputB= $output[scalar @output - 1] eq " "C= $output[scalar @output - 1] eq $indent_string
ABCresult
0XX0
1000
11X1
1011
387 205 pop @output;
388 }
389 }
390 sub print_newline {
391 967 ▶ my ( $ignore_repeated ) = @_;
Subroutine print_newline: called CC=6 SCAR=17.9
Pod undocumented
392 967 ▶ $ignore_repeated = 1 unless defined $ignore_repeated;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ignore_repeated 947 20 967
393 967 $if_line_flag = 0;
394 967 trim_output();
395  
396 967 ▶ if ( not scalar @output ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @output) 29 938 967
397 29 return; # no newline on start of file
398 }
399  
400 938 ▶ if ( $output[ scalar @output - 1 ] ne "\n" || ! $ignore_repeated ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($output[scalar @output - 1] ne "\n" or not $ignore_repeated) 762 176 938
Condition100%3/3
$output[scalar @output - 1] ne "\n" or not $ignore_repeated
l!l&&r!l&&!r
75210176
MC/DC100%2/2
$output[scalar @output - 1] ne "\n" or not $ignore_repeated
$output[scalar @output - 1] ne "\n" not $ignore_repeated
Truth table100%3/3
A or not(B)
A= $output[scalar @output - 1] ne "\n"B= not $ignore_repeated
ABresult
1X1
011
000
401 762 $just_added_newline = 1;
402 762 push @output, "\n";
403 }
404 938 foreach my $i ( 0 .. $opt_indent_level - 1 ) {
405 789 push @output, $indent_string;
406 }
407 }
408  
409 sub print_space {
410 998 ▶ my $last_output = ' ';
Subroutine print_space: called CC=5 SCAR=16.1
Pod undocumented
411 998 ▶ $last_output = $output[ scalar @output - 1 ] if scalar @output;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @output 990 8 998
412 998 ▶ if ( $last_output ne ' ' && $last_output ne "\n" && $last_output ne $indent_string ) { # prevent occassional duplicate space
Branch: 1 branch
BranchTrueFalseTotal
if ($last_output ne " " and $last_output ne "\n" and $last_output ne $indent_string) 886 112 998
Condition100%6/6
$last_output ne " " and $last_output ne "\n" and $last_output ne $indent_string
!ll&&!rl&&r
3478886
$last_output ne " " and $last_output ne "\n"
!ll&&!rl&&r
2014964
MC/DC100%3/3
$last_output ne " " and $last_output ne "\n" and $last_output ne $indent_string
$last_output ne " " $last_output ne "\n" $last_output ne $indent_string
Truth table100%4/4
A and B and C
A= $last_output ne " "B= $last_output ne "\n"C= $last_output ne $indent_string
ABCresult
0XX0
10X0
1100
1111
413 886 push @output, ' ';
414 }
415 }
416  
417 sub print_token {
418 3194 ▶ $just_added_newline = 0;
Subroutine print_token: called CC=1 SCAR=0.0
Pod undocumented
419 3194 push @output, $token_text;
420 }
421 sub indent {
422 288 ▶ $opt_indent_level++;
Subroutine indent: called CC=1 SCAR=0.0
Pod undocumented
423 }
424 sub unindent {
425 285 ▶ if ( $opt_indent_level ) {
Subroutine unindent: called CC=2 SCAR=7.2
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if ($opt_indent_level) 285 0 285
426 285 $opt_indent_level--;
427 }
428 }
429 sub remove_indent {
430 6 ▶ if ( scalar @output && $output[ scalar @output - 1 ] eq $indent_string ) {
Subroutine remove_indent: called CC=3 SCAR=13.1
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @output and $output[scalar @output - 1] eq $indent_string) 6 0 6
Condition33%1/3
scalar @output and $output[scalar @output - 1] eq $indent_string
!ll&&!rl&&r
006
MC/DC0%0/2
scalar @output and $output[scalar @output - 1] eq $indent_string
scalar @output $output[scalar @output - 1] eq $indent_string
Truth table33%1/3
A and B
A= scalar @outputB= $output[scalar @output - 1] eq $indent_string
ABresult
0X0
100
111
431 6 pop @output;
432 }
433 }
434 sub set_mode {
435 586 ▶ my $mode = shift;
Subroutine set_mode: called CC=1 SCAR=0.0
Pod undocumented
436 586 push @modes, $current_mode;
437 586 $current_mode = $mode;
438 }
439 sub is_expression {
440 34 ▶ my $mode = shift;
Subroutine is_expression: called CC=4 SCAR=14.9
Pod undocumented
441 34 ▶ return ($mode eq '[EXPRESSION]' || $mode eq '[INDENTED-EXPRESSION]' || $mode eq '(EXPRESSION)') ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$mode eq '[EXPRESSION]' || $mode eq '[INDENTED-EXPRESSION]' || $mode eq '(EXPRESSION)' ? : 16 18 34
Condition50%3/6
$mode eq "[EXPRESSION]" or $mode eq "[INDENTED-EXPRESSION]" or $mode eq "(EXPRESSION)"
l!l&&r!l&&!r
01618
$mode eq "[EXPRESSION]" or $mode eq "[INDENTED-EXPRESSION]"
l!l&&r!l&&!r
0034
MC/DC33%1/3
$mode eq "[EXPRESSION]" or $mode eq "[INDENTED-EXPRESSION]" or $mode eq "(EXPRESSION)"
$mode eq "[EXPRESSION]" $mode eq "[INDENTED-EXPRESSION]" $mode eq "(EXPRESSION)"
Truth table50%2/4
A or B or C
A= $mode eq "[EXPRESSION]"B= $mode eq "[INDENTED-EXPRESSION]"C= $mode eq "(EXPRESSION)"
ABCresult
1XX1
01X1
0011
0000
442 }
443 sub restore_mode {
444 570 ▶ $do_block_just_closed = ( $current_mode eq 'DO_BLOCK' ) ? 1 : 0;
Subroutine restore_mode: called CC=2 SCAR=6.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$current_mode eq 'DO_BLOCK' ? : 10 560 570
445 570 $current_mode = pop @modes;
446 }
447  
448 # Walk backwards from the colon to find a '?' (colon is part of a ternary op)
449 # or a '{' (colon is part of a class literal). Along the way, keep track of
450 # the blocks and expressions we pass so we only trigger on those chars in our
451 # own level, and keep track of the colons so we only trigger on the matching '?'.
452 sub is_ternary_op {
453 56 ▶ my $level = 0;
Subroutine is_ternary_op: called CC=14 SCAR=26.4
Pod undocumented
454 56 my $colon_count = 0;
455 56 foreach my $o (reverse @output) {
456 574 ▶ if ( $o eq ':' ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($o eq ':') { } 42 532 574
elsif ($o eq '?') { } 32 500 532
elsif ($o eq '{') { } 42 458 500
457 42 ▶ if ( $level == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($level == 0) 34 8 42
458 34 $colon_count++;
459 }
460 42 next;
461 } elsif ( $o eq '?' ) {
462 32 ▶ if ( $level == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($level == 0) 32 0 32
463 32 ▶ if ( $colon_count == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($colon_count == 0) { } 18 14 32
464 18 return 1;
465 } else {
466 14 $colon_count--;
467 }
468 }
469 14 next;
470 } elsif ( $o eq '{' ) {
471 42 ▶ if ( $level == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($level == 0) 38 4 42
472 38 return 0;
473 }
474 4 $level--;
475 4 next;
476 }
477 458 ▶ if ( $o eq '(' or $o eq '[' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($o eq '(' or $o eq '[') { } 6 452 458
elsif ($o eq ')' or $o eq ']' or $o eq '}') { } 10 442 452
Condition66%2/3
$o eq "(" or $o eq "["
l!l&&r!l&&!r
06452
MC/DC50%1/2
$o eq "(" or $o eq "["
$o eq "(" $o eq "["
Truth table66%2/3
A or B
A= $o eq "("B= $o eq "["
ABresult
1X1
011
000
478 6 $level--;
479 6 next;
480 ▶ } elsif ( $o eq ')' or $o eq ']' or $o eq '}' ) {
Condition83%5/6
$o eq ")" or $o eq "]" or $o eq "}"
l!l&&r!l&&!r
64442
$o eq ")" or $o eq "]"
l!l&&r!l&&!r
06446
MC/DC66%2/3
$o eq ")" or $o eq "]" or $o eq "}"
$o eq ")" $o eq "]" $o eq "}"
Truth table75%3/4
A or B or C
A= $o eq ")"B= $o eq "]"C= $o eq "}"
ABCresult
1XX1
01X1
0011
0000
481 10 $level++;
482 10 next;
483 }
484 }
485 }
486  
487 sub get_next_token {
488 3484 ▶ my $n_newlines = 0;
Subroutine get_next_token: called CC=89 SCAR=45.0
Pod undocumented
489  
490 3484 ▶ if ( $parser_pos >= scalar @input ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parser_pos >= scalar @input) 279 3205 3484
491 279 return ['', 'TK_EOF'];
492 }
493  
494 3205 my $c = $input[$parser_pos];
495 3205 $parser_pos++;
496  
497 3205 ▶ while ( grep { $_ eq $c } @whitespace ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_ eq $c;} @whitespace) 821 3204 4025
498 821 ▶ if ( $parser_pos >= scalar @input ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parser_pos >= scalar @input) 1 820 821
499 1 return ['', 'TK_EOF'];
500 }
501 820 ▶ if ( $c eq "\n" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq "\n") 336 484 820
502 336 $n_newlines += 1;
503 }
504 820 $c = $input[$parser_pos];
505 820 $parser_pos++;
506 };
507 3204 $wanted_newline = 0;
508 3204 ▶ if ( $opt_preserve_newlines ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt_preserve_newlines) 3200 4 3204
509 3200 ▶ if ( $n_newlines > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n_newlines > 1) 10 3190 3200
510 10 foreach my $i ( 0 .. 1 ) {
511 20 ▶ my $flag = ( $i == 0 ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$i == 0 ? : 10 10 20
512 20 print_newline( $flag );
513 }
514 }
515 3200 ▶ $wanted_newline = ($n_newlines == 1) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$n_newlines == 1 ? : 315 2885 3200
516 }
517 3204 ▶ if ( grep { $c eq $_ } @wordchar ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$c eq $_;} @wordchar) 1135 2069 3204
518 1135 ▶ if ( $parser_pos < scalar @input ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parser_pos < scalar @input) 1116 19 1135
519 1116 ▶ while ( grep { $input[$parser_pos] eq $_ } @wordchar ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$input[$parser_pos] eq $_;} @wordchar) 1819 1105 2924
520 1819 $c .= $input[$parser_pos];
521 1819 $parser_pos++;
522 1819 ▶ if ( $parser_pos == scalar @input ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parser_pos == scalar @input) 11 1808 1819
523 11 last;
524 }
525 }
526 }
527  
528 # small and surprisingly unugly hack for 1E-10 representation
529 1135 ▶ if ( $parser_pos != scalar @input && $c =~ /^[0-9]+[Ee]$/ && ($input[$parser_pos] eq '-' || $input[$parser_pos] eq '+') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parser_pos != scalar @input and $c =~ /^[0-9]+[Ee]$/ and $input[$parser_pos] eq "-" || $input[$parser_pos] eq "+") 10 1125 1135
Condition88%8/9
$parser_pos != scalar @input and $c =~ /^[0-9]+[Ee]$/ and $input[$parser_pos] eq "-" || $input[$parser_pos] eq "+"
!ll&&!rl&&r
112528
$parser_pos != scalar @input and $c =~ /^[0-9]+[Ee]$/
!ll&&!rl&&r
30109510
$input[$parser_pos] eq "-" or $input[$parser_pos] eq "+"
l!l&&r!l&&!r
820
MC/DC50%2/4
$parser_pos != scalar @input and $c =~ /^[0-9]+[Ee]$/ and $input[$parser_pos] eq "-" || $input[$parser_pos] eq "+"
$parser_pos != scalar @input $c =~ /^[0-9]+[Ee]$/ $input[$parser_pos] eq "-" $input[$parser_pos] eq "+"
Truth table60%3/5
A and B and C or D
A= $parser_pos != scalar @inputB= $c =~ /^[0-9]+[Ee]$/C= $input[$parser_pos] eq "-"D= $input[$parser_pos] eq "+"
ABCDresult
0XXX0
10XX0
11000
111X1
11011
530 10 my $sign = $input[$parser_pos];
531 10 $parser_pos++;
532 10 my $t = get_next_token($parser_pos);
533 10 $c .= $sign . $t->[0];
534 10 return [$c, 'TK_WORD'];
535 }
536 1125 ▶ if ( $c eq 'in' ) { # hack for 'in' operator
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq "in") 4 1121 1125
537 4 return [$c, 'TK_OPERATOR'];
538 }
539 1121 ▶ if ( $wanted_newline && $last_type ne 'TK_OPERATOR' && not $if_line_flag ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($wanted_newline and $last_type ne "TK_OPERATOR" and not $if_line_flag) 222 899 1121
Condition100%6/6
$wanted_newline and $last_type ne "TK_OPERATOR" and not $if_line_flag
!ll&&!rl&&r
86534222
$wanted_newline and $last_type ne "TK_OPERATOR"
!ll&&!rl&&r
8632256
MC/DC100%3/3
$wanted_newline and $last_type ne "TK_OPERATOR" and not $if_line_flag
$wanted_newline $last_type ne "TK_OPERATOR" not $if_line_flag
Truth table100%4/4
A and B and not(C)
A= $wanted_newlineB= $last_type ne "TK_OPERATOR"C= not $if_line_flag
ABCresult
0XX0
10X0
1100
1111
540 222 print_newline();
541 }
542 1121 return [$c, 'TK_WORD'];
543 }
544 2069 ▶ if ( $c eq '(' || $c eq '[' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq "(" or $c eq "[") 332 1737 2069
Condition100%3/3
$c eq "(" or $c eq "["
l!l&&r!l&&!r
256761737
MC/DC100%2/2
$c eq "(" or $c eq "["
$c eq "(" $c eq "["
Truth table100%3/3
A or B
A= $c eq "("B= $c eq "["
ABresult
1X1
011
000
545 332 return [$c, 'TK_START_EXPR'];
546 }
547 1737 ▶ if ( $c eq ')' || $c eq ']' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq ")" or $c eq "]") 319 1418 1737
Condition100%3/3
$c eq ")" or $c eq "]"
l!l&&r!l&&!r
243761418
MC/DC100%2/2
$c eq ")" or $c eq "]"
$c eq ")" $c eq "]"
Truth table100%3/3
A or B
A= $c eq ")"B= $c eq "]"
ABresult
1X1
011
000
548 319 return [$c, 'TK_END_EXPR'];
549 }
550 1418 ▶ if ( $c eq '{' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq "{") 254 1164 1418
551 254 return [$c, 'TK_START_BLOCK'];
552 }
553 1164 ▶ if ( $c eq '}' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq "}") 251 913 1164
554 251 return [$c, 'TK_END_BLOCK'];
555 }
556 913 ▶ if ( $c eq ';' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq ";") 292 621 913
557 292 return [$c, 'TK_SEMICOLON'];
558 }
559 621 ▶ if ( $c eq '/' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq "/") 50 571 621
560 50 my $comment;
561 # peek for comment /* ... */
562 50 ▶ if ( $input[$parser_pos] eq '*' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($input[$parser_pos] eq "*") 2 48 50
563 2 $parser_pos++;
564 2 ▶ if ( $parser_pos < scalar @input ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parser_pos < scalar @input) 2 0 2
565 2 ▶ while (not ( $input[$parser_pos] eq '*' && $input[$parser_pos+1] && $input[$parser_pos+1] eq '/') && $parser_pos < scalar @input ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $input[$parser_pos] eq "*" && $input[$parser_pos + 1] && $input[$parser_pos + 1] eq "/" and $parser_pos < scalar @input) 14 2 16
Condition66%6/9
not $input[$parser_pos] eq "*" && $input[$parser_pos + 1] && $input[$parser_pos + 1] eq "/" and $parser_pos < scalar @input
!ll&&!rl&&r
2014
$input[$parser_pos] eq '*' && $input[$parser_pos + 1] && $input[$parser_pos + 1] eq '/'
!ll&&!rl&&r
1402
$input[$parser_pos] eq "*" and $input[$parser_pos + 1]
!ll&&!rl&&r
1402
MC/DC25%1/4
not $input[$parser_pos] eq "*" && $input[$parser_pos + 1] && $input[$parser_pos + 1] eq "/" and $parser_pos < scalar @input
$input[$parser_pos] eq "*" $input[$parser_pos + 1] $input[$parser_pos + 1] eq '/' $parser_pos < scalar @input
Truth table28%2/7
not(A and B && C) and D
A= $input[$parser_pos] eq "*"B= $input[$parser_pos + 1]C= $input[$parser_pos + 1] eq '/'D= $parser_pos < scalar @input
ABCDresult
111X0
0XX00
10X00
11000
0XX11
10X11
11011
566 14 $comment .= $input[$parser_pos];
567 14 $parser_pos++;
568 14 ▶ if ( $parser_pos >= scalar @input ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parser_pos >= scalar @input) 0 14 14
569 0 last;
570 }
571 }
572 }
573 2 $parser_pos += 2;
574 2 return ['/*' . $comment . '*/', 'TK_BLOCK_COMMENT'];
575 }
576 # peek for comment // ...
577 48 ▶ if ( $input[$parser_pos] eq '/' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($input[$parser_pos] eq "/") 21 27 48
578 21 $comment = $c;
579 21 ▶ while ( $input[$parser_pos] ne "\x0d" && $input[$parser_pos] ne "\x0a" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($input[$parser_pos] ne "\r" and $input[$parser_pos] ne "\n") 193 20 213
Condition66%2/3
$input[$parser_pos] ne "\r" and $input[$parser_pos] ne "\n"
!ll&&!rl&&r
020193
MC/DC50%1/2
$input[$parser_pos] ne "\r" and $input[$parser_pos] ne "\n"
$input[$parser_pos] ne "\r" $input[$parser_pos] ne "\n"
Truth table66%2/3
A and B
A= $input[$parser_pos] ne "\r"B= $input[$parser_pos] ne "\n"
ABresult
0X0
100
111
580 193 $comment .= $input[$parser_pos];
581 193 $parser_pos++;
582 193 ▶ if ( $parser_pos >= scalar @input ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parser_pos >= scalar @input) 1 192 193
583 1 last;
584 }
585 }
586 21 $parser_pos++;
587 21 ▶ if ($wanted_newline) {
Branch: 1 branch
BranchTrueFalseTotal
if ($wanted_newline) 12 9 21
588 12 print_newline();
589 }
590 21 return [$comment, 'TK_COMMENT'];
591 }
592 }
593 598 ▶ if ( $c eq "'" || # string
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq "'" or $c eq "\"" or $c eq "/" and $last_type eq "TK_WORD" && $last_text eq "return" || ($last_type eq "TK_START_EXPR" || $last_type eq "TK_START_BLOCK" || $last_type eq "TK_END_BLOCK" || $last_type eq "TK_OPERATOR" || $last_type eq "TK_EOF" || $last_type eq "TK_SEMICOLON")) 48 510 558
Condition90%27/30
$c eq "'" or $c eq "\"" or $c eq "/" and $last_type eq "TK_WORD" && $last_text eq "return" || ($last_type eq "TK_START_EXPR" || $last_type eq "TK_START_BLOCK" || $last_type eq "TK_END_BLOCK" || $last_type eq "TK_OPERATOR" || $last_type eq "TK_EOF" || $last_type eq "TK_SEMICOLON")
l!l&&r!l&&!r
65282251
$c eq "'" or $c eq "\""
l!l&&r!l&&!r
1946533
$c eq "/" and $last_type eq "TK_WORD" && $last_text eq "return" || ($last_type eq "TK_START_EXPR" || $last_type eq "TK_START_BLOCK" || $last_type eq "TK_END_BLOCK" || $last_type eq "TK_OPERATOR" || $last_type eq "TK_EOF" || $last_type eq "TK_SEMICOLON")
!ll&&!rl&&r
5061215
$last_type eq "TK_WORD" and $last_text eq "return" or ($last_type eq "TK_START_EXPR" or $last_type eq "TK_START_BLOCK" or $last_type eq "TK_END_BLOCK" or $last_type eq "TK_OPERATOR" or $last_type eq "TK_EOF" or $last_type eq "TK_SEMICOLON")
l!l&&r!l&&!r
01512
$last_type eq "TK_WORD" and $last_text eq "return"
!ll&&!rl&&r
2340
$last_type eq "TK_START_EXPR" or $last_type eq "TK_START_BLOCK" or $last_type eq "TK_END_BLOCK" or $last_type eq "TK_OPERATOR" or $last_type eq "TK_EOF" or $last_type eq "TK_SEMICOLON"
l!l&&r!l&&!r
2124
$last_type eq "TK_START_EXPR" or $last_type eq "TK_START_BLOCK" or $last_type eq "TK_END_BLOCK" or $last_type eq "TK_OPERATOR" or $last_type eq "TK_EOF"
l!l&&r!l&&!r
2106
$last_type eq "TK_START_EXPR" or $last_type eq "TK_START_BLOCK" or $last_type eq "TK_END_BLOCK" or $last_type eq "TK_OPERATOR"
l!l&&r!l&&!r
1656
$last_type eq "TK_START_EXPR" or $last_type eq "TK_START_BLOCK" or $last_type eq "TK_END_BLOCK"
l!l&&r!l&&!r
14211
$last_type eq "TK_START_EXPR" or $last_type eq "TK_START_BLOCK"
l!l&&r!l&&!r
10413
MC/DC18%2/11
$c eq "'" or $c eq "\"" or $c eq "/" and $last_type eq "TK_WORD" && $last_text eq "return" || ($last_type eq "TK_START_EXPR" || $last_type eq "TK_START_BLOCK" || $last_type eq "TK_END_BLOCK" || $last_type eq "TK_OPERATOR" || $last_type eq "TK_EOF" || $last_type eq "TK_SEMICOLON")
$c eq "'" $c eq "\"" $c eq "/" $last_type eq "TK_WORD" $last_text eq "return" $last_type eq "TK_START_EXPR" $last_type eq "TK_START_BLOCK" $last_type eq "TK_END_BLOCK" $last_type eq "TK_OPERATOR" $last_type eq "TK_EOF" $last_type eq "TK_SEMICOLON"
Truth table22%4/18
A or B or C and D and E or F or G or H or I or J or K
A= $c eq "'"B= $c eq "\""C= $c eq "/"D= $last_type eq "TK_WORD"E= $last_text eq "return"F= $last_type eq "TK_START_EXPR"G= $last_type eq "TK_START_BLOCK"H= $last_type eq "TK_END_BLOCK"I= $last_type eq "TK_OPERATOR"J= $last_type eq "TK_EOF"K= $last_type eq "TK_SEMICOLON"
ABCDEFGHIJKresult
1XXXXXXXXXX1
01XXXXXXXXX1
00111XXXXXX1
0010X1XXXXX1
0010X01XXXX1
0010X001XXX1
0010X0001XX1
0010X00001X1
0010X0000011
001101XXXXX1
0011001XXXX1
00110001XXX1
001100001XX1
0011000001X1
001100000011
000XXXXXXXX0
0010X0000000
001100000000
594 $c eq '"' || # string
595 ($c eq '/' &&
596 (( $last_type eq 'TK_WORD' && $last_text eq 'return') ||
597 ( $last_type eq 'TK_START_EXPR' || $last_type eq 'TK_START_BLOCK' || $last_type eq 'TK_END_BLOCK' || $last_type eq 'TK_OPERATOR' || $last_type eq 'TK_EOF' || $last_type eq 'TK_SEMICOLON')))) { # regexp
598 88 my $sep = $c;
599 88 my $esc = 0;
600 88 my $resulting_string = $c;
601 88 ▶ if ( $parser_pos < scalar @input ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parser_pos < scalar @input) 88 0 88
602 88 ▶ if ( $sep eq '/') {
Branch: 1 branch
BranchTrueFalseTotal
if ($sep eq '/') { } 23 65 88
603 # handle regexp separately...
604 23 my $in_char_class = 0;
605 23 ▶ while ( $esc || $in_char_class || $input[$parser_pos] ne $sep ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($esc or $in_char_class or $input[$parser_pos] ne $sep) 99 21 120
Condition100%6/6
$esc or $in_char_class or $input[$parser_pos] ne $sep
l!l&&r!l&&!r
297921
$esc or $in_char_class
l!l&&r!l&&!r
920100
MC/DC100%3/3
$esc or $in_char_class or $input[$parser_pos] ne $sep
$esc $in_char_class $input[$parser_pos] ne $sep
Truth table100%4/4
A or B or C
A= $escB= $in_char_classC= $input[$parser_pos] ne $sep
ABCresult
1XX1
01X1
0011
0000
606 108 $resulting_string .= $input[$parser_pos];
607 108 ▶ if ( not $esc ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $esc) { } 99 9 108
608 99 ▶ $esc = ( $input[$parser_pos] eq '\\' ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$input[$parser_pos] eq '\\' ? : 9 90 99
609 99 ▶ if ( $input[$parser_pos] eq '[' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($input[$parser_pos] eq '[') { } 5 94 99
elsif ($input[$parser_pos] eq ']') { } 4 90 94
610 5 $in_char_class = 1;
611 } elsif ( $input[$parser_pos] eq ']' ) {
612 4 $in_char_class = 0;
613 }
614 } else {
615 9 $esc = 0;
616 }
617 108 $parser_pos++;
618 108 ▶ if ( $parser_pos >= scalar @input ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parser_pos >= scalar @input) 2 106 108
619 # incomplete string/rexp when end-of-file reached.
620 # bail out with what had been received so far.
621 2 return [$resulting_string, 'TK_STRING'];
622 }
623 }
624  
625 } else {
626 # and handle string also separately
627 65 ▶ while ( $esc || $input[$parser_pos] ne $sep ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($esc or $input[$parser_pos] ne $sep) 235 64 299
Condition100%3/3
$esc or $input[$parser_pos] ne $sep
l!l&&r!l&&!r
922664
MC/DC100%2/2
$esc or $input[$parser_pos] ne $sep
$esc $input[$parser_pos] ne $sep
Truth table100%3/3
A or B
A= $escB= $input[$parser_pos] ne $sep
ABresult
1X1
011
000
628 235 $resulting_string .= $input[$parser_pos];
629 235 ▶ if ( not $esc ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $esc) { } 226 9 235
630 226 ▶ $esc = ( $input[$parser_pos] eq '\\' ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$input[$parser_pos] eq '\\' ? : 9 217 226
631 } else {
632 9 $esc = 0;
633 }
634 235 $parser_pos++;
635 235 ▶ if ( $parser_pos >= scalar @input ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parser_pos >= scalar @input) 1 234 235
636 # incomplete string/rexp when end-of-file reached.
637 # bail out with what had been received so far.
638 1 return [$resulting_string, 'TK_STRING'];
639 }
640 }
641 }
642 }
643 85 $parser_pos++;
644 85 $resulting_string .= $sep;
645 85 ▶ if ( $sep eq '/' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sep eq "/") 21 64 85
646 # regexps may have modifiers /regexp/MOD , so fetch those, too
647 21 ▶ while ( $parser_pos < scalar @input && (grep { $input[$parser_pos] eq $_ } @wordchar) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parser_pos < scalar @input and grep {$input[$parser_pos] eq $_;} @wordchar) 17 21 38
Condition100%3/3
$parser_pos < scalar @input and grep {$input[$parser_pos] eq $_;} @wordchar
!ll&&!rl&&r
21917
MC/DC100%2/2
$parser_pos < scalar @input and grep {$input[$parser_pos] eq $_;} @wordchar
$parser_pos < scalar @input grep {$input[$parser_pos] eq $_;} @wordchar
Truth table100%3/3
A and B
A= $parser_pos < scalar @inputB= grep {$input[$parser_pos] eq $_;} @wordchar
ABresult
0X0
100
111
648 17 $resulting_string .= $input[$parser_pos];
649 17 $parser_pos++;
650 }
651 }
652 85 return [$resulting_string, 'TK_STRING'];
653 }
654  
655 510 ▶ if ($c eq '#') {
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq "#") 14 496 510
656 # Spidermonkey-specific sharp variables for circular references
657 # https://developer.mozilla.org/En/Sharp_variables_in_JavaScript
658 # http://mxr.mozilla.org/mozilla-central/source/js/src/jsscan.cpp around line 1935
659 14 my $sharp = '#';
660 14 ▶ if ($parser_pos < scalar @input && (grep { $input[$parser_pos] eq $_ } @digits) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parser_pos < scalar @input and grep {$input[$parser_pos] eq $_;} @digits) 13 1 14
Condition66%2/3
$parser_pos < scalar @input and grep {$input[$parser_pos] eq $_;} @digits
!ll&&!rl&&r
1013
MC/DC50%1/2
$parser_pos < scalar @input and grep {$input[$parser_pos] eq $_;} @digits
$parser_pos < scalar @input grep {$input[$parser_pos] eq $_;} @digits
Truth table66%2/3
A and B
A= $parser_pos < scalar @inputB= grep {$input[$parser_pos] eq $_;} @digits
ABresult
0X0
100
111
661 13 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
$parser_pos < scalar @input and $c ne "#" and $c ne "=" and do { do { $c = $input[$parser_pos]; $sharp .= $c; $parser_pos += 1 } } 22 13 35
Condition100%6/6
$parser_pos < scalar @input and $c ne "#" and $c ne "="
!ll&&!rl&&r
7622
$parser_pos < scalar @input and $c ne "#"
!ll&&!rl&&r
1628
MC/DC100%3/3
$parser_pos < scalar @input and $c ne "#" and $c ne "="
$parser_pos < scalar @input $c ne "#" $c ne "="
Truth table100%4/4
A and B and C
A= $parser_pos < scalar @inputB= $c ne "#"C= $c ne "="
ABCresult
0XX0
10X0
1100
1111
662 35 $c = $input[$parser_pos];
663 35 $sharp .= $c;
664 35 $parser_pos += 1;
665 } while ($parser_pos < scalar @input && $c ne '#' && $c ne '=');
666 13 ▶ if ($c eq '#') {
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq '#') { } 6 7 13
667 6 return [$sharp, 'TK_WORD'];
668 } else {
669 7 return [$sharp, 'TK_OPERATOR'];
670 }
671 }
672 }
673  
674 497 ▶ if ($c eq '<' && $parser_pos + 2 < scalar @input && join('', @input[$parser_pos-1 .. $parser_pos+2]) eq '<!--') {
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq "<" and $parser_pos + 2 < scalar @input and join("", @input[$parser_pos - 1 .. $parser_pos + 2]) eq "<!--") 7 490 497
Condition100%6/6
$c eq "<" and $parser_pos + 2 < scalar @input and join("", @input[$parser_pos - 1 .. $parser_pos + 2]) eq "<!--"
!ll&&!rl&&r
478127
$c eq "<" and $parser_pos + 2 < scalar @input
!ll&&!rl&&r
477119
MC/DC100%3/3
$c eq "<" and $parser_pos + 2 < scalar @input and join("", @input[$parser_pos - 1 .. $parser_pos + 2]) eq "<!--"
$c eq "<" $parser_pos + 2 < scalar @input join("", @input[$parser_pos - 1 .. $parser_pos + 2]) eq "<!--"
Truth table100%4/4
A and B and C
A= $c eq "<"B= $parser_pos + 2 < scalar @inputC= join("", @input[$parser_pos - 1 .. $parser_pos + 2]) eq "<!--"
ABCresult
0XX0
10X0
1100
1111
675 7 $parser_pos += 3;
676 7 return ['<!--', 'TK_COMMENT'];
677 }
678 490 ▶ if ($c eq '-' && $parser_pos + 1 < scalar @input && join('', @input[$parser_pos-1 .. $parser_pos+1]) eq '-->') {
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq "-" and $parser_pos + 1 < scalar @input and join("", @input[$parser_pos - 1 .. $parser_pos + 1]) eq "-->") 6 484 490
Condition83%5/6
$c eq "-" and $parser_pos + 1 < scalar @input and join("", @input[$parser_pos - 1 .. $parser_pos + 1]) eq "-->"
!ll&&!rl&&r
468166
$c eq "-" and $parser_pos + 1 < scalar @input
!ll&&!rl&&r
468022
MC/DC66%2/3
$c eq "-" and $parser_pos + 1 < scalar @input and join("", @input[$parser_pos - 1 .. $parser_pos + 1]) eq "-->"
$c eq "-" $parser_pos + 1 < scalar @input join("", @input[$parser_pos - 1 .. $parser_pos + 1]) eq "-->"
Truth table75%3/4
A and B and C
A= $c eq "-"B= $parser_pos + 1 < scalar @inputC= join("", @input[$parser_pos - 1 .. $parser_pos + 1]) eq "-->"
ABCresult
0XX0
10X0
1100
1111
679 6 $parser_pos += 2;
680 6 ▶ if ($wanted_newline) {
Branch: 1 branch
BranchTrueFalseTotal
if ($wanted_newline) 6 0 6
681 6 print_newline();
682 }
683 6 return ['-->', 'TK_COMMENT'];
684 }
685  
686 484 ▶ if ( grep { $c eq $_ } @punct ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$c eq $_;} @punct) 434 50 484
687 434 ▶ while ( $parser_pos < scalar @input && (grep { $c . $input[$parser_pos] eq $_ } @punct) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parser_pos < scalar @input and grep {$c . $input[$parser_pos] eq $_;} @punct) 46 434 480
Condition66%2/3
$parser_pos < scalar @input and grep {$c . $input[$parser_pos] eq $_;} @punct
!ll&&!rl&&r
043446
MC/DC50%1/2
$parser_pos < scalar @input and grep {$c . $input[$parser_pos] eq $_;} @punct
$parser_pos < scalar @input grep {$c . $input[$parser_pos] eq $_;} @punct
Truth table66%2/3
A and B
A= $parser_pos < scalar @inputB= grep {$c . $input[$parser_pos] eq $_;} @punct
ABresult
0X0
100
111
688 46 $c .= $input[$parser_pos];
689 46 $parser_pos++;
690 46 ▶ last if ( $parser_pos >= scalar @input );
Branch: 1 branch
BranchTrueFalseTotal
if $parser_pos >= scalar @input 0 46 46
691 }
692 434 return [$c, 'TK_OPERATOR'];
693 }
694 50 return [$c, 'TK_UNKNOWN'];
695 }
696  
697 2 1;
698 __END__
↑ Summary Build »