Gherkin/Line.pm

filter: Statementstmt 42.5% 43 / 101 Branchbran 16.6% 5 / 30 Conditioncond 55.5% 5 / 9 MC/DCmcdc 33.3% 2 / 6 Subroutinesub 75.0% 12 / 16 Podpod 0.0% 0 / 8 totaltotal 39.4% 67 / 170 CC 20 SCAR 28.5
CC
20
Cov
38%
__ANON__
56.0
tags
30.0
table_cells
6.0
CRAP 17.3
« Gherkin/Pickles/Compiler.pm ↑ Summary Gherkin/MarkdownTokenMatcher.pm »
1 package Gherkin::Line;
2 2 $Gherkin::Line::VERSION = '42.0.1';
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use Class::XSAccessor accessors =>
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 [ qw/line_text line_number indent _trimmed_line_text _tag_error/, ];
8  
9 2 ▶use Gherkin::Exceptions;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 38 ▶sub new {
Subroutine new: called CC=3 SCAR=11.2
Pod undocumented
12 38 my ( $class, $options ) = @_;
13 38 my $self = bless $options, $class;
14  
15 38 ▶ $self->{'_trimmed_line_text'} ||= $self->_build__trimmed_line_text;
Condition66%2/3
$self->{"_trimmed_line_text"} ||= $self->_build__trimmed_line_text
l!l&&r!l&&!r
02513
MC/DC50%1/2
$self->{"_trimmed_line_text"} ||= $self->_build__trimmed_line_text
$self->{"_trimmed_line_text"} $self->_build__trimmed_line_text
Truth table66%2/3
A ||= B
A= $self->{"_trimmed_line_text"}B= $self->_build__trimmed_line_text
ABresult
1X1
011
000
16 38 ▶ $self->{'indent'} ||= $self->_build_indent;
Condition66%2/3
$self->{"indent"} ||= $self->_build_indent
l!l&&r!l&&!r
0326
MC/DC50%1/2
$self->{"indent"} ||= $self->_build_indent
$self->{"indent"} $self->_build_indent
Truth table66%2/3
A ||= B
A= $self->{"indent"}B= $self->_build_indent
ABresult
1X1
011
000
17  
18 38 return $self;
19 }
20  
21 38 ▶sub _build__trimmed_line_text {
Subroutine _build__trimmed_line_text: called CC=2 SCAR=7.0
22 38 my $self = shift;
23 38 my $trimmed = $self->line_text;
24 38 ▶ $trimmed =~ s/^\s+// if defined $trimmed;
Branch: 1 branch
BranchTrueFalseTotal
if defined $trimmed 38 0 38
25 38 return $trimmed;
26 }
27  
28 38 ▶sub _build_indent {
Subroutine _build_indent: called CC=1 SCAR=0.0
29 38 my $self = shift;
30 38 return length( $self->line_text ) - length( $self->_trimmed_line_text );
31 }
32  
33 21 ▶sub get_rest_trimmed {
Subroutine get_rest_trimmed: called CC=1 SCAR=0.0
Pod undocumented
34 21 my ( $self, $from ) = @_;
35 21 my $rest = substr( $self->_trimmed_line_text, $from );
36 21 $rest =~ s/^\s*//;
37 21 $rest =~ s/\s*$//;
38 21 return $rest;
39 }
40  
41 5 ▶sub get_line_text {
Subroutine get_line_text: called CC=4 SCAR=16.4
Pod undocumented
42 5 my ( $self, $indent_to_remove ) = @_;
43 5 ▶ $indent_to_remove = -1 unless defined $indent_to_remove;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $indent_to_remove 5 0 5
44  
45 5 ▶ if ( $indent_to_remove < 0 or $indent_to_remove > $self->indent ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($indent_to_remove < 0 or $indent_to_remove > $self->indent) { } 5 0 5
Condition33%1/3
$indent_to_remove < 0 or $indent_to_remove > $self->indent
l!l&&r!l&&!r
500
MC/DC0%0/2
$indent_to_remove < 0 or $indent_to_remove > $self->indent
$indent_to_remove < 0 $indent_to_remove > $self->indent
Truth table33%1/3
A or B
A= $indent_to_remove < 0B= $indent_to_remove > $self->indent
ABresult
1X1
011
000
46 5 return $self->_trimmed_line_text;
47 } else {
48 0 return substr( $self->line_text, $indent_to_remove );
49 }
50 }
51  
52 24 ▶sub is_empty {
Subroutine is_empty: called CC=1 SCAR=0.0
Pod undocumented
53 24 my $self = shift;
54 24 return !$self->_trimmed_line_text;
55 }
56  
57 264 ▶sub startswith {
Subroutine startswith: called CC=2 SCAR=7.1
Pod undocumented
58 264 my ( $self, $prefix ) = @_;
59 264 ▶ return unless defined $self->_trimmed_line_text;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->_trimmed_line_text 0 264 264
60 264 return !index( $self->_trimmed_line_text, $prefix );
61 }
62  
63 75 ▶sub startswith_title_keyword {
Subroutine startswith_title_keyword: called CC=2 SCAR=7.1
Pod undocumented
64 75 my ( $self, $prefix ) = @_;
65 75 ▶ return unless defined $self->_trimmed_line_text;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->_trimmed_line_text 0 75 75
66 75 return !index( $self->_trimmed_line_text, $prefix . ':' );
67 }
68  
69 0 ▶sub _split_table_cells_iterator {
Subroutine _split_table_cells_iterator: not called CC=1 SCAR=6.9
70 0 my ( $self, $row ) = @_;
71 0 my $col = 0;
72 0 my $first_cell = 1;
73  
74 0 ▶ return sub {
Subroutine __ANON__: not called CC=7 SCAR=40.3
75 0 my $cell = '';
76 0 my $start_col = $col + 1 + $first_cell;
77  
78 0 while (1) {
79 0 ▶ ( $row =~ s/^(.)// ) || return;
Branch: 1 branch
BranchTrueFalseTotal
$row =~ s/^(.)// or return 0 0 0
80 0 my $char = $1;
81 0 $col += 1;
82 0 ▶ if ( $char eq '|' ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($char eq '|') { } 0 0 0
elsif ($char eq '\\') { } 0 0 0
elsif (defined $char) { } 0 0 0
83 0 ▶ if ($first_cell) {
Branch: 1 branch
BranchTrueFalseTotal
if ($first_cell) { } 0 0 0
84 0 $first_cell = 0;
85 } else {
86 0 return ( $cell, $start_col );
87 }
88 } elsif ( $char eq "\\" ) {
89 0 ▶ if ($row =~ s/^(.)//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($row =~ s/^(.)//) { } 0 0 0
90 0 $col += 1;
91 0 $cell .= '\\' . $1;
92 } else {
93 0 $cell .= '\\';
94 }
95 } elsif ( defined $char ) {
96 0 $cell .= $char;
97 } else {
98 0 die "WHAT?";
99 }
100 }
101 }
102 0 }
103  
104 2 my %unescape_map = ( '\\\\' => '\\', '\\|' => '|', '\\n' => "\n" );
105  
106 0 ▶sub table_cells {
Subroutine table_cells: not called CC=2 SCAR=17.9
Pod undocumented
107 0 my ($self) = @_;
108 0 my $cells = [];
109 0 my $text = $self->_trimmed_line_text;
110 0 $text =~ s/^\s*//;
111 0 $text =~ s/\s*$//;
112  
113 0 my $i = $self->_split_table_cells_iterator($text);
114 0 while (1) {
115 0 my ( $cell, $col ) = $i->();
116 0 ▶ last unless defined $col;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $col 0 0 0
117  
118 0 my $stripped_cell = $cell;
119 0 $stripped_cell =~ s/^\s+//;
120 0 my $cell_indent = length($cell) - length($stripped_cell);
121 0 $stripped_cell =~ s/\s+$//;
122 0 $stripped_cell =~ s/(\\\\|\\\||\\n)/$unescape_map{$1}/g;
123 push(
124 0 @{$cells},
125 {
126 column => $col + $self->indent + $cell_indent,
127 text => $stripped_cell
128 }
129 );
130 }
131  
132 0 return $cells;
133 }
134  
135 0 ▶sub tags {
Subroutine tags: not called CC=5 SCAR=34.0
Pod undocumented
136 0 my $self = shift;
137 0 my $column = $self->indent + 1;
138 0 my $items_line = $self->_trimmed_line_text;
139 0 $items_line =~ s/\s+(#.*)?$//;
140  
141 0 my @tags;
142 my @errors;
143 0 my @items = split( /@/, $items_line );
144 0 shift(@items); # Blank first item
145  
146 0 for my $untrimmed (@items) {
147 0 my $item = $untrimmed;
148 0 $item =~ s/^\s*//;
149 0 $item =~ s/\s*$//;
150 0 ▶ next if length($item) == 0;
Branch: 1 branch
BranchTrueFalseTotal
if length $item == 0 0 0 0
151  
152 0 ▶ if ($item !~ /^\S+$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($item =~ /^\S+$/) 0 0 0
153 0 push @errors,
154 Gherkin::Exceptions::SingleParser->new(
155 detailed_message => 'A tag may not contain whitespace',
156 location => {
157 line => $self->line_number,
158 column => $column,
159 },
160 );
161 }
162 0 push @tags, {
163 column => $column,
164 text => '@' . $item,
165 };
166  
167 0 $column += length($untrimmed) + 1;
168 }
169  
170 0 my $err;
171 0 ▶ if (@errors) {
Branch: 1 branch
BranchTrueFalseTotal
if (@errors) 0 0 0
172 0 $err = Gherkin::Exceptions::CompositeParser->new(@errors);
173 }
174  
175 0 return (\@tags, $err);
176 }
177  
178 2 1;
« Gherkin/Pickles/Compiler.pm ↑ Summary Gherkin/MarkdownTokenMatcher.pm »