| 1 | package Mock::Data::Regex; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 12 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 12 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 12 | ▶ | use Mock::Data::Charset; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 12 | ▶ | use Mock::Data::Util qw( _parse_context _escape_str ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 12 | require Carp; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 12 | require Scalar::Util; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 12 | require List::Util; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 12 | require Hash::Util; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 12 | require Mock::Data::Generator; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 12 | our @ISA= ( 'Mock::Data::Generator' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | # ABSTRACT: Generator that uses a Regex as a template to generate strings | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 12 | our $VERSION = '0.04'; # VERSION | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 24 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=19 SCAR=44.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 24 | my $class= shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | my %self= @_ == 1 && (!ref $_[0] || ref $_[0] eq 'Regexp')? ( regex => $_[0] ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 0 | ▶ | : @_ == 1? %{$_[0]} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition50%3/6
@_ == 1 and !ref($_[0]) || ref $_[0] eq "Regexp"
not ref $_[0] or ref $_[0] eq "Regexp"
MC/DC33%1/3
@_ == 1 and !ref($_[0]) || ref $_[0] eq "Regexp"
@_ == 1
not ref $_[0]
ref $_[0] eq "Regexp"
Truth table50%2/4
A and not(B) or C
A= @_ == 1B= not ref $_[0]C= ref $_[0] eq "Regexp"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | : @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | # If called on an object, carry over some settings | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 24 | ▶ | if (ref $class) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | %self= ( %$class, %self ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | # Make sure we didn't copy a regex without a matching regex_parse_tree, or vice versa | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | ▶ | if ($self{regex} == $class->{regex} xor $self{regex_parse_tree} == $class->{regex_parse_tree}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/4
$self{"regex"} == $class->{"regex"} xor $self{"regex_parse_tree"} == $class->{"regex_parse_tree"}
MC/DC0%0/2
$self{"regex"} == $class->{"regex"} xor $self{"regex_parse_tree"} == $class->{"regex_parse_tree"}
$self{"regex"} == $class->{"regex"}
$self{"regex_parse_tree"} == $class->{"regex_parse_tree"}
Truth table0%0/4
A xor B
A= $self{"regex"} == $class->{"regex"}B= $self{"regex_parse_tree"} == $class->{"regex_parse_tree"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | ▶ | delete $self{regex_parse_tree} if $self{regex_parse_tree} == $class->{regex_parse_tree}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | ▶ | delete $self{regex} if $self{regex} == $class->{regex}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | $class= ref $class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 24 | ▶ | defined $self{regex} or Carp::croak "Attribute 'regex' is required"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 24 | ▶ | $self{regex}= qr/$self{regex}/ unless ref $self{regex} eq 'Regexp'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | # Must be parsed eventually, so might as well do it now and see the errors right away | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 24 | ▶ | $self{regex_parse_tree} ||= $class->parse($self{regex}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$self{"regex_parse_tree"} ||= $class->parse($self{"regex"})
MC/DC0%0/2
$self{"regex_parse_tree"} ||= $class->parse($self{"regex"})
$self{"regex_parse_tree"}
$class->parse($self{"regex"})
Truth table33%1/3
A ||= B
A= $self{"regex_parse_tree"}B= $class->parse($self{"regex"})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 24 | ▶ | $self{max_codepoint} //= 0x7F if $self{regex_parse_tree}->flags->{a}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$self{"max_codepoint"} //= 127
MC/DC100%1/1
$self{"max_codepoint"} //= 127
$self{"max_codepoint"}
Truth table100%2/2
A
A= $self{"max_codepoint"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 24 | ▶ | $self{prefix} //= Mock::Data::Util::coerce_generator($self{prefix}) if defined $self{prefix}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self{"prefix"} //= Mock::Data::Util::coerce_generator($self{"prefix"})
MC/DC0%0/2
$self{"prefix"} //= Mock::Data::Util::coerce_generator($self{"prefix"})
$self{"prefix"}
Mock::Data::Util::coerce_generator($self{"prefix"})
Truth table0%0/3
A //= B
A= $self{"prefix"}B= Mock::Data::Util::coerce_generator($self{"prefix"})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 24 | ▶ | $self{suffix} //= Mock::Data::Util::coerce_generator($self{suffix}) if defined $self{suffix}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self{"suffix"} //= Mock::Data::Util::coerce_generator($self{"suffix"})
MC/DC0%0/2
$self{"suffix"} //= Mock::Data::Util::coerce_generator($self{"suffix"})
$self{"suffix"}
Mock::Data::Util::coerce_generator($self{"suffix"})
Truth table0%0/3
A //= B
A= $self{"suffix"}B= Mock::Data::Util::coerce_generator($self{"suffix"})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 24 | return bless \%self, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | ▶ | sub regex { $_[0]{regex} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
regex: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 209 | ▶ | sub regex_parse_tree { $_[0]{regex_parse_tree} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
regex_parse_tree: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 207 | ▶ | sub min_codepoint { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
min_codepoint: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | $_[0]{min_codepoint} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 207 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 207 | ▶ | sub max_codepoint { $_[0]{max_codepoint} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
max_codepoint: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 209 | ▶ | sub max_repetition { $_[0]{max_repetition} || '+8' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
max_repetition: called CC=2 SCAR=7.6
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | ▶ | sub prefix { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
prefix: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | if (@_ > 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | $_[0]{prefix}= Mock::Data::Util::coerce_generator($_[1]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | $_[0]{prefix} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | sub suffix { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
suffix: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | ▶ | if (@_ > 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | $_[0]{suffix}= Mock::Data::Util::coerce_generator($_[1]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | $_[0]{suffix} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 209 | ▶ | sub generate { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
generate: called CC=21 SCAR=32.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 209 | my ($self, $mockdata)= (shift,shift); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 209 | ▶ | my %opts= ref $_[0] eq 'HASH'? %{$_[0]} : (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 209 | ▶ | $opts{max_codepoint} //= $self->max_codepoint; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$opts{"max_codepoint"} //= $self->max_codepoint
MC/DC100%2/2
$opts{"max_codepoint"} //= $self->max_codepoint
$opts{"max_codepoint"}
$self->max_codepoint
Truth table100%3/3
A //= B
A= $opts{"max_codepoint"}B= $self->max_codepoint
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 209 | ▶ | $opts{min_codepoint} //= $self->min_codepoint; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$opts{"min_codepoint"} //= $self->min_codepoint
MC/DC100%2/2
$opts{"min_codepoint"} //= $self->min_codepoint
$opts{"min_codepoint"}
$self->min_codepoint
Truth table100%3/3
A //= B
A= $opts{"min_codepoint"}B= $self->min_codepoint
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 209 | ▶ | $opts{max_repetition} //= $self->max_repetition; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$opts{"max_repetition"} //= $self->max_repetition
MC/DC0%0/2
$opts{"max_repetition"} //= $self->max_repetition
$opts{"max_repetition"}
$self->max_repetition
Truth table33%1/3
A //= B
A= $opts{"max_repetition"}B= $self->max_repetition
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 209 | my $out= $self->_str_builder($mockdata, \%opts); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | $self->regex_parse_tree->generate($out) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | # is the string allowed to end here? Requirement of '' is generated by $ and \Z | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 209 | ▶ | && (!$out->next_req || (grep $_ eq '', @{ $out->next_req })) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$self->regex_parse_tree->generate($out) and !$out->next_req || grep(($_ eq ""), @{$out->next_req;})
not $out->next_req or grep(($_ eq ""), @{$out->next_req;})
MC/DC0%0/3
$self->regex_parse_tree->generate($out) and !$out->next_req || grep(($_ eq ""), @{$out->next_req;})
$self->regex_parse_tree->generate($out)
not $out->next_req
grep(($_ eq ""), @{$out->next_req;})
Truth table50%2/4
A and not(B) or C
A= $self->regex_parse_tree->generate($out)B= not $out->next_reqC= grep(($_ eq ""), @{$out->next_req;})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | or Carp::croak "Regex assertions could not be met (such as '^' or '\$'). Final attempt was: \""._escape_str($out->str)."\""; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 209 | ▶ | my $prefix= $opts{prefix} // $self->{prefix}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$opts{"prefix"} // $self->{"prefix"}
MC/DC50%1/2
$opts{"prefix"} // $self->{"prefix"}
$opts{"prefix"}
$self->{"prefix"}
Truth table66%2/3
A // B
A= $opts{"prefix"}B= $self->{"prefix"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 209 | ▶ | my $suffix= $opts{suffix} // $self->{suffix}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$opts{"suffix"} // $self->{"suffix"}
MC/DC50%1/2
$opts{"suffix"} // $self->{"suffix"}
$opts{"suffix"}
$self->{"suffix"}
Truth table66%2/3
A // B
A= $opts{"suffix"}B= $self->{"suffix"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 209 | ▶ | return $out->str unless defined $prefix || defined $suffix; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $prefix or defined $suffix
MC/DC50%1/2
defined $prefix or defined $suffix
defined $prefix
defined $suffix
Truth table66%2/3
A or B
A= defined $prefixB= defined $suffix
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 19 | my $str= $out->str; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | # A prefix can only be added if there was not a beginning-of-string assertion, or if | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | # it was a ^/m assertion (flagged as "LF") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 19 | ▶ | if ($prefix && (!$out->start || $out->start eq 'LF')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$prefix and !$out->start || $out->start eq "LF"
not $out->start or $out->start eq "LF"
MC/DC0%0/3
$prefix and !$out->start || $out->start eq "LF"
$prefix
not $out->start
$out->start eq "LF"
Truth table50%2/4
A and not(B) or C
A= $prefixB= not $out->startC= $out->start eq "LF"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 19 | my $p= Mock::Data::Util::coerce_generator($prefix)->generate($mockdata); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 19 | ▶ | $p .= "\n" if $out->start; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 19 | $str= $p . $str; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | # A suffix can only be added if there was not an end-of-string assertion, or if | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | # the next assertion allows "\n" and there is no assertion after that. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 19 | ▶ | if ($suffix && (!$out->next_req || (grep $_ eq "\n", @{ $out->next_req }) && !$out->require->[1])) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition77%7/9
$suffix and !$out->next_req || grep(($_ eq "\n"), @{$out->next_req;}) && !$out->require->[1]
not $out->next_req or grep(($_ eq "\n"), @{$out->next_req;}) and not $out->require->[1]
grep(($_ eq "\n"), @{$out->next_req;}) and not $out->require->[1]
MC/DC50%2/4
$suffix and !$out->next_req || grep(($_ eq "\n"), @{$out->next_req;}) && !$out->require->[1]
$suffix
not $out->next_req
grep(($_ eq "\n"), @{$out->next_req;})
not $out->require->[1]
Truth table60%3/5
A and not(B) or C and not(D)
A= $suffixB= not $out->next_reqC= grep(($_ eq "\n"), @{$out->next_req;})D= not $out->require->[1]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 18 | ▶ | $str .= "\n" if $out->next_req; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 18 | $str .= Mock::Data::Util::coerce_generator($suffix)->generate($mockdata); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 19 | return $str; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 43 | ▶ | sub parse { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 43 | my ($self, $regex)= @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 43 | return $self->_parse_regex({}) for "$regex"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | ▶ | sub get_charset { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_charset: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | my $self= shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | my $p= $self->regex_parse_tree->pattern; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | ▶ | return Scalar::Util::blessed($p) && $p->isa('Mock::Data::Charset')? $p : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
builtin::blessed($p) and $p->isa("Mock::Data::Charset")
MC/DC0%0/2
builtin::blessed($p) and $p->isa("Mock::Data::Charset")
builtin::blessed($p)
$p->isa("Mock::Data::Charset")
Truth table0%0/3
A and B
A= builtin::blessed($p)B= $p->isa("Mock::Data::Charset")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | our %_regex_syntax_unsupported= ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 12 | '' => { map { $_ => 1 } qw( $ ) }, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 12 | '\\' => { map { $_ => 1 } qw( B b A Z z G g K k ) }, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | our %_parse_regex_backslash= ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 12 | map +( $_ => $Mock::Data::Charset::_parse_charset_backslash{$_} ), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | qw( a b c e f n N o r t x 0 1 2 3 4 5 6 7 8 9 ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 105 | ▶ | sub _parse_regex { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_regex: called CC=48 SCAR=40.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 105 | my $self= shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 105 | ▶ | my $flags= shift || {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() || {}
MC/DC0%0/1
shift() || {}
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 105 | my $expr= []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 105 | my @or; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 105 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | # begin parenthetical sub-expression? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 357 | ▶ | if (/\G \( /gcx) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 7 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 62 | my $sub_flags= $flags; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 62 | ▶ | if (/\G \? /gcx) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | # leading question mark means regex flags. This only supports the ^...: one: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 43 | ▶ | if (/\G \^ ( \w* ) : /gcx) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 43 | $sub_flags= {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 43 | ++$sub_flags->{$_} for split '', $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | ▶ | } elsif ($] < 5.020 and /\G (\w*)-\w* : /gcx) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$] < "5.02" and /\G (\w*)-\w* : /cgx
MC/DC0%0/2
$] < "5.02" and /\G (\w*)-\w* : /cgx
$] < "5.02"
/\G (\w*)-\w* : /cgx
Truth table0%0/3
A and B
A= $] < "5.02"B= /\G (\w*)-\w* : /cgx
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | $sub_flags= {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | ++$sub_flags->{$_} for split '', $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | Carp::croak("Unsupported regex feature '(?".substr($_,pos,1)."'"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 62 | my $pos= -1+pos; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 62 | push @$expr, $self->_parse_regex($sub_flags); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 62 | ▶ | /\G \) /gcx | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | or die "Missing end-parenthesee, started at "._parse_context($pos); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | # end sub-expression? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | elsif (/\G(?= \) )/gcx) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 62 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | # next alternation of 'or'? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | elsif (/\G \| /gcx) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | # else begin next piece of @or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 11 | push @or, $self->_node($expr, $flags); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 11 | $expr= []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | # character class? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | elsif (/\G ( \[ | \\w | \\W | \\s | \\S | \\d | \\D | \\N | \\Z | \. | \^ | \$ ) /gcx) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 31 | ▶ | if ($1 eq '[') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | # parse function continues to operate on $_ at pos() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 5 | my $parse= Mock::Data::Charset::_parse_charset($flags); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 5 | push @$expr, $self->_charset_node($parse, $flags); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | elsif (ord $1 == ord '\\') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 11 | ▶ | if ($1 eq "\\Z") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 1 | push @$expr, $self->_assertion_node(end => 1, flags => $flags); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 10 | push @$expr, $self->_charset_node(notation => $1, $flags); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | elsif ($1 eq '.') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 2 | ▶ | push @$expr, $self->_charset_node(classes => [ $flags->{s}? 'Any' : '\\N' ], $flags); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | elsif ($1 eq '$') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 7 | ▶ | push @$expr, $self->_assertion_node(end => ($flags->{m}? 'LF' : 'FinalLF'), flags => $flags); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | elsif ($1 eq '^') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 6 | ▶ | push @$expr, $self->_assertion_node(start => ($flags->{m}? 'LF' : 1 ), flags => $flags); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | # repetition? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | elsif (/\G ( \? | \* \?? | \+ \?? | \{ ([0-9]+)? (,)? ([0-9]+)? \} ) /gcx) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 30 | my @rep; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 30 | ▶ | if ($1 eq '?') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 1 | @rep= (0,1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | elsif (ord $1 == ord '*') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 5 | @rep= (0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | elsif (ord $1 == ord '+') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 19 | @rep= (1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 5 | ▶ | @rep= $3? ($2||0,$4) : ($2||0,$2); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition75%3/4
$2 or 0
$2 or 0
MC/DC100%1/1
$2 or 0
$2
MC/DC0%0/1
$2 or 0
$2
Truth table100%2/2
A
A= $2
Truth table50%1/2
A
A= $2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | # What came before this? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 30 | ▶ | if (!@$expr) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | die "Found quantifier '$1' before anything to quantify at "._parse_context; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | elsif (!ref $expr->[-1]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | # If the string is composed of more than one character, split the final one | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | # into its own node so that it can have a repetition applied to it. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 6 | ▶ | if (length $expr->[-1] > 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 2 | push @$expr, $self->_node([ substr($expr->[-1], -1) ], $flags); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 2 | substr($expr->[-2], -1)= ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | # else its one character, wrap it in a node | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 4 | $expr->[-1]= $self->_node([ $expr->[-1] ], $flags); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 30 | $expr->[-1]->repetition(\@rep) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | ▶ | elsif ($flags->{x} && /\G ( \s | [#].* ) /gcx) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$flags->{"x"} and /\G ( \s | [#].* ) /cgx
MC/DC0%0/2
$flags->{"x"} and /\G ( \s | [#].* ) /cgx
$flags->{"x"}
/\G ( \s | [#].* ) /cgx
Truth table33%1/3
A and B
A= $flags->{"x"}B= /\G ( \s | [#].* ) /cgx
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | # ignore whitespace and comments under /x mode | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | elsif (/\G (\\)? (.) /gcxs) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | # Tell users about unsupported features | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 118 | ▶ | die "Unsupported notation: '$1$2'" if $_regex_syntax_unsupported{$1||''}{$2}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$1 || ''
MC/DC100%1/1
$1 || ''
$1
Truth table100%2/2
A
A= $1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 118 | my $ch; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 118 | ▶ | if ($1 && defined (my $equiv= $_parse_regex_backslash{$2})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$1 and defined(my $equiv = $Mock::Data::Regex::_parse_regex_backslash{$2})
MC/DC100%2/2
$1 and defined(my $equiv = $Mock::Data::Regex::_parse_regex_backslash{$2})
$1
defined(my $equiv = $Mock::Data::Regex::_parse_regex_backslash{$2})
Truth table100%3/3
A and B
A= $1B= defined(my $equiv = $Mock::Data::Regex::_parse_regex_backslash{$2})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 5 | ▶ | $ch= chr(ref $equiv? $equiv->() : $equiv); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 113 | $ch= $2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 118 | ▶ | if ($flags->{i} && (uc $ch ne lc $ch)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
$flags->{"i"} and uc $ch ne lc $ch
MC/DC50%1/2
$flags->{"i"} and uc $ch ne lc $ch
$flags->{"i"}
uc $ch ne lc $ch
Truth table66%2/3
A and B
A= $flags->{"i"}B= uc $ch ne lc $ch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 3 | push @$expr, $self->_charset_node(chars => [uc $ch, lc $ch], $flags); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | ▶ | elsif (@$expr && !ref $expr->[-1]) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
@$expr and not ref $expr->[-1]
MC/DC100%2/2
@$expr and not ref $expr->[-1]
@$expr
not ref $expr->[-1]
Truth table100%3/3
A and not(B)
A= @$exprB= not ref $expr->[-1]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 53 | $expr->[-1] .= $ch; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 62 | push @$expr, $ch; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 43 | last; # end of string | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 105 | ▶ | return @or? do { push @or, $self->_node($expr, $flags) if @$expr; $self->_or_node(\@or, $flags) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition100%3/3
@$expr > 1 or not ref $expr->[0]
MC/DC100%2/2
@$expr > 1 or not ref $expr->[0]
@$expr > 1
not ref $expr->[0]
Truth table100%3/3
A or not(B)
A= @$expr > 1B= not ref $expr->[0]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | : (@$expr > 1 || !ref $expr->[0])? $self->_node($expr, $flags) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | : $expr->[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | #---------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | # Factory Functions for Parse Nodes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 60 | ▶ | sub _node { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_node: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 60 | my ($self, $pattern, $flags)= @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 60 | Mock::Data::Regex::ParseNode->new({ pattern => $pattern, flags => $flags }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 5 | ▶ | sub _or_node { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_or_node: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 5 | my ($self, $or_list, $flags)= @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 5 | Mock::Data::Regex::ParseNode::Or->new({ pattern => $or_list, flags => $flags }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 20 | ▶ | sub _charset_node { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_charset_node: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 20 | my $self= shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 20 | my $flags= pop; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 20 | ▶ | Mock::Data::Regex::ParseNode::Charset->new({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | pattern => @_ > 1? { @_ } : shift, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | flags => $flags | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 14 | ▶ | sub _assertion_node { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_assertion_node: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 14 | my $self= shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 14 | Mock::Data::Regex::ParseNode::Assertion->new({ @_ }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 209 | ▶ | sub _str_builder { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_str_builder: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 209 | my ($self, $mockdata, $opts)= @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 209 | Mock::Data::Regex::StrBuilder->new({ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | mockdata => $mockdata, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | generator => $self, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | opts => $opts, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 60 | ▶ | sub _fake_inc { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_fake_inc: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 60 | (my $pkg= caller) =~ s,::,/,g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 60 | $INC{$pkg.'.pm'}= $INC{'Mock/Data/Generator/Regex.pm'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | # ------------------------------ Regex Parse Node ------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | # The regular parse nodes hold a "pattern" which is an arrayref of literal strings | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | # or nested parse nodes. It supports a "repetition" flag to handle min/max repetitions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | # of the node as a whole. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | # Other subclasses are used to handle OR-lists, charsets, and zero-width assertions. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | package # Do not index | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | Mock::Data::Regex::ParseNode; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 12 | Mock::Data::Regex::_fake_inc(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 79 | ▶ | sub new { bless $_[1], $_[0] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 24 | ▶ | sub flags { $_[0]{flags} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
flags: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 469 | ▶ | sub repetition { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
repetition: called CC=6 SCAR=22.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 469 | ▶ | if (@_ > 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | # If a quantifier is being applied to a thing that already had a quantifier | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | # (such as /(X*){2}/ ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | # multiply them | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 30 | my $val= $_[1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 30 | ▶ | if (my $rep= $_[0]{repetition}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | $rep->[$_]= (defined $rep->[$_] && defined $val->[$_]? $rep->[$_] * $val->[$_] : undef) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 0 | ▶ | for 0, 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $rep->[$_] and defined $val->[$_]
MC/DC0%0/2
defined $rep->[$_] and defined $val->[$_]
defined $rep->[$_]
defined $val->[$_]
Truth table0%0/3
A and B
A= defined $rep->[$_]B= defined $val->[$_]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 30 | $_[0]{repetition}= $_[1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | return $_[0]{repetition} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 469 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 0 | ▶ | sub min_repetition { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
min_repetition: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | ▶ | $_[0]{repetition}? $_[0]{repetition}[0] : 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | ▶ | sub max_repetition { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
max_repetition: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 0 | ▶ | $_[0]{repetition}? $_[0]{repetition}[1] : 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 235 | ▶ | sub pattern { $_[0]{pattern} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pattern: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 346 | ▶ | sub generate { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
generate: called CC=12 SCAR=24.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 346 | my ($self, $out)= @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 346 | ▶ | if (my $rep= $self->repetition) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 84 | my ($min, $n)= ($rep->[0], $out->_random_rep_count($rep)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 84 | for (1 .. $n) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 320 | ▶ | my $origin= $_ > $min? $out->mark : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | # Plain nodes expect the pattern to be an arrayref where each item is a parse node or a literal | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 320 | my $success= 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 320 | for (@{ $self->{pattern} }) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 357 | ▶ | $success &&= ref $_? $_->generate($out) : $out->append($_); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$success &&= ref $_ ? $_->generate($out) : $out->append($_)
MC/DC100%2/2
$success &&= ref $_ ? $_->generate($out) : $out->append($_)
$success
ref $_ ? $_->generate($out) : $out->append($_)
Truth table100%3/3
A &&= B
A= $successB= ref $_ ? $_->generate($out) : $out->append($_)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 320 | ▶ | next if $success; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | # This repetition failed, but did we meet the requirement already? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 17 | ▶ | if ($origin) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 17 | $out->reset($origin); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 17 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | # Plain nodes expect the pattern to be an arrayref where each item is a parse node or a literal | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 262 | for (@{ $self->{pattern} }) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 451 | ▶ | return 0 unless ref $_? $_->generate($out) : $out->append($_); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 308 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | # --------------------------------- Regex "OR" Parse Node ---------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | # This parse holds a list of options in ->pattern. It chooses one of the options at | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | # random, but then can backtrack if inner parse nodes were not able to match. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | package # Do not index | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | Mock::Data::Regex::ParseNode::Or; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 12 | Mock::Data::Regex::_fake_inc(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 12 | our @ISA= ('Mock::Data::Regex::ParseNode'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 32 | ▶ | sub generate { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
generate: called CC=9 SCAR=24.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 32 | my ($self, $out)= @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 32 | my ($min, $n)= (1,1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 32 | ▶ | if (my $rep= $self->{repetition}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 30 | $min= $rep->[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 30 | $n= $out->_random_rep_count($rep); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 32 | rep: for (1 .. $n) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | # OR nodes expect the pattern to be an arrayref where each item is an option | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | # for what could be appended. Need to reset the output after each attempt. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 118 | my $origin= $out->mark; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | # Pick one at random. It will almost always work on the first try, unless the user | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | # has anchor constraints in the pattern. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 118 | my $or= $self->pattern; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 118 | my $pick= $or->[ rand scalar @$or ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 118 | ▶ | next rep if ref $pick? $pick->generate($out) : $out->append($pick); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | # if it fails, try all the others in random order | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 21 | for (List::Util::shuffle(grep { $_ != $pick } @$or)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | # reset output | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 21 | $out->reset($origin); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | # append something new | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 21 | ▶ | next rep if ref $_? $_->generate($out) : $out->append($_); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | # None of the options succeeded. Did we get enough reps already? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 0 | ▶ | if ($_ > $min) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 0 | $out->reset($origin); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 32 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | # -------------------------------- Regex Charset Parse Node --------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | # This node's ->pattern is an instance of Charset. It returns one character | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | # from the set, but also has an optimized handling of the ->repetition flag that generates | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | # multiple characters at once. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | package # Do not index | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | Mock::Data::Regex::ParseNode::Charset; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 12 | Mock::Data::Regex::_fake_inc(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 12 | our @ISA= ('Mock::Data::Regex::ParseNode'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 20 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 20 | my ($class, $self)= @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 20 | ▶ | if (ref $self->{pattern} eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 20 | ▶ | $self->{pattern}{max_codepoint}= 0x7F if $self->{flags}{a}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 20 | $self->{pattern}= Mock::Data::Util::charset($self->{pattern}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 20 | bless $self, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 84 | ▶ | sub generate { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
generate: called CC=10 SCAR=42.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 84 | my ($self, $out)= @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | # Check whether output has a restriction in effect: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 84 | ▶ | if (my $req= $out->next_req) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | # pick the first requirement which can be matched by this charset | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 0 | for (@$req) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 0 | ▶ | if (!ref) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | # At \Z, can still match if rep count is 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 0 | ▶ | return 1 if length == 0 && $self->min_repetition == 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
length $_ == 0 and $self->min_repetition == 0
MC/DC0%0/2
length $_ == 0 and $self->min_repetition == 0
length $_ == 0
$self->min_repetition == 0
Truth table0%0/3
A and B
A= length $_ == 0B= $self->min_repetition == 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 0 | ▶ | return $out->append($_) if | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/9
length $_ == 1 and $self->pattern->has_member($_) or length $_ > 1 and not grep((!$self->pattern->has_member($_)), split(//, $_, 0))
length $_ == 1 and $self->pattern->has_member($_)
length $_ > 1 and not grep((!$self->pattern->has_member($_)), split(//, $_, 0))
MC/DC0%0/4
length $_ == 1 and $self->pattern->has_member($_) or length $_ > 1 and not grep((!$self->pattern->has_member($_)), split(//, $_, 0))
length $_ == 1
$self->pattern->has_member($_)
length $_ > 1
not grep((!$self->pattern->has_member($_)), split(//, $_, 0))
Truth table0%0/7
A and B or C and not(D)
A= length $_ == 1B= $self->pattern->has_member($_)C= length $_ > 1D= not grep((!$self->pattern->has_member($_)), split(//, $_, 0))
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | length == 1 && $self->pattern->has_member($_) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | or length > 1 && !(grep !$self->pattern->has_member($_), split //); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 84 | my $n= $out->_random_rep_count($self->repetition); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 84 | return $out->append($self->pattern->generate($out->mockdata, $out->opts, $n)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | # ----------------------------- Regex Assertion Parse Node ------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | # This node doesn't have a ->pattern, and instead holds constraints about what characters | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | # must occur around the current position. Right now it only handles '^' and '$' and '\Z' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | package # Do not index | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | Mock::Data::Regex::ParseNode::Assertion; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 12 | Mock::Data::Regex::_fake_inc(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 12 | our @ISA= ('Mock::Data::Regex::ParseNode'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 0 | ▶ | sub start { $_[0]{start} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
start: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 0 | ▶ | sub end { $_[0]{end} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
end: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 94 | ▶ | sub generate { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
generate: called CC=10 SCAR=23.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | 94 | my ($self, $out)= @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 94 | ▶ | if ($self->{start}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | # Previous character must either be start of string or a newline | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | length $out->str == 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | 55 | ▶ | or ($self->{start} eq 'LF' && substr($out->str,-1) eq "\n") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
length $out->str == 0 or $self->{"start"} eq "LF" and substr($out->str, -1) eq "\n"
$self->{"start"} eq "LF" and substr($out->str, -1) eq "\n"
MC/DC66%2/3
length $out->str == 0 or $self->{"start"} eq "LF" and substr($out->str, -1) eq "\n"
length $out->str == 0
$self->{"start"} eq "LF"
substr($out->str, -1) eq "\n"
Truth table75%3/4
A or B and C
A= length $out->str == 0B= $self->{"start"} eq "LF"C= substr($out->str, -1) eq "\n"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | or return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | # Set flag on entire output if this is the first assertion | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 34 | ▶ | $out->start($self->{start}) if length $out->str == 0 && !$out->start; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
length $out->str == 0 and not $out->start
MC/DC50%1/2
length $out->str == 0 and not $out->start
length $out->str == 0
not $out->start
Truth table66%2/3
A and not(B)
A= length $out->str == 0B= not $out->start
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 73 | ▶ | if ($self->{end}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | # Next character must be a newline, or end of the output | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | # end=1 results from \Z and does not allow the newline | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 39 | ▶ | $out->require(['',"\n"]) unless $self->{end} eq 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | # If end=LF, the end of string is no longer mandatory once "\n" has been matched. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 39 | ▶ | $out->require(['']) unless $self->{end} eq 'LF'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | 73 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | # ------------------------ String Builder ----------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | # This class constructs an output string in ->{str}, and also performs checks | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | # needed by the assertions like ^ and $. It also has the ability to mark a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | # position and then revert to that position, without copying the entire string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | # each time. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | package # Do not index | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | Mock::Data::Regex::StrBuilder; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 12 | Mock::Data::Regex::_fake_inc(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | 209 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 209 | my ($class, $self)= @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 209 | ▶ | $self->{str} //= ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{"str"} //= ""
MC/DC0%0/1
$self->{"str"} //= ""
$self->{"str"}
Truth table50%1/2
A
A= $self->{"str"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | 209 | bless $self, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | 84 | ▶ | sub mockdata { $_[0]{mockdata} } # Mock::Data instance | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mockdata: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 0 | ▶ | sub generator { $_[0]{generator} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
generator: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | 216 | ▶ | sub opts { $_[0]{opts} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
opts: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | 449 | ▶ | sub start { $_[0]{start}= $_[1] if @_ > 1; $_[0]{start} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
start: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | 334 | ▶ | sub str { $_[0]{str} } # string being built | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
str: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | 198 | ▶ | sub _random_rep_count { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_random_rep_count: called CC=6 SCAR=20.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 198 | my ($self, $rep)= @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | 198 | ▶ | return 1 unless defined $rep; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 158 | ▶ | return $rep->[0] + int rand($rep->[1] - $rep->[0] + 1) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | if defined $rep->[1]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | 132 | ▶ | my $range= $self->opts->{max_repetition} // '+8'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->opts->{"max_repetition"} // "+8"
MC/DC0%0/1
$self->opts->{"max_repetition"} // "+8"
$self->opts->{"max_repetition"}
Truth table50%1/2
A
A= $self->opts->{"max_repetition"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | 132 | ▶ | return $rep->[0] + int rand($range+1) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | if ord $range == ord '+'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | 0 | $range -= $rep->[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 0 | ▶ | return $range > 0? $rep->[0] + int rand($range+1) : $rep->[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | 61 | ▶ | sub require { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
require: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | 61 | ▶ | push @{ $_[0]{require} }, $_[1] if @_ > 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | 61 | return $_[0]{require}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | 1039 | ▶ | sub next_req { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
next_req: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | 1039 | ▶ | return $_[0]{require} && $_[0]{require}[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$_[0]{'require'} && $_[0]{'require'}[0]
MC/DC50%1/2
$_[0]{'require'} && $_[0]{'require'}[0]
$_[0]{'require'}
$_[0]{'require'}[0]
Truth table66%2/3
A && B
A= $_[0]{'require'}B= $_[0]{'require'}[0]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | 667 | ▶ | sub append { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
append: called CC=6 SCAR=20.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | 667 | my ($self, $content)= @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | 667 | ▶ | if (my $req= $self->next_req) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | # the provided output must be coerced to one of these options, if possible | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | # TODO: need new ideas for this code. Or just give up on the plan of supporting | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | # lookaround assertions and focus on a simple implemention of "\n" checks for ^/$ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | 17 | for (@$req) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | 34 | ▶ | if (!ref) { # next text must match a literal string. '' means end-of-string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | 34 | ▶ | if (length && $content eq $_) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
length $_ and $content eq $_
MC/DC0%0/2
length $_ and $content eq $_
length $_
$content eq $_
Truth table66%2/3
A and B
A= length $_B= $content eq $_
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | 0 | $self->{str} .= $content; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | 0 | shift @{ $self->require }; # requirement complete | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | # TODO: support for "lookaround" assertions, will require regex match | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | 0 | die "Unimplemented: zero-width lookaround assertions"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | 17 | return 0; # no match found for the restriction in effect | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | 650 | $self->{str} .= $content; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | 650 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | 372 | ▶ | sub mark { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mark: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | 372 | my $self= shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | 372 | my $len= $self->{lastmark}= length $self->{str}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | 372 | my $req= $self->{require}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | 372 | ▶ | return [ \$self->{str}, $len, $req? [ @$req ] : undef, $self->start ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | 38 | ▶ | sub reset { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
reset: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | 38 | my ($self, $origin)= @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | # If the string is a different instance than before, go back to that instance | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | 0 | Hash::Util::hv_store(%$self, 'str', ${$origin->[0]}) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | 38 | ▶ | unless \$self->{str} == $origin->[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | # Reset the string to the original length | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | 38 | substr($self->{str}, $origin->[1])= ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | 38 | $self->{require}= $origin->[2]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | 38 | $self->{start}= $origin->[3]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | 12 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||