| 1 | package Test::Mojo::Role::ElementCounter; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 2 | ▶ | use Mojo::Base -base; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 2 | ▶ | use Encode; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 2 | ▶ | use Carp qw/croak/; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 2 | ▶ | use Role::Tiny; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | 2 | our $VERSION = '1.001009'; # VERSION | |||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 2 | has _counter_selector_prefix => ''; | |||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 5 | ▶ | sub dive_in { | ||||||||||||||||||
|
Subroutine
dive_in: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 13 | 5 | my ( $self, $selector ) = @_; | |||||||||||||||||||
| 14 | 5 | $self->_counter_selector_prefix( | |||||||||||||||||||
| 15 | $self->_counter_selector_prefix . $selector | ||||||||||||||||||||
| 16 | ); | ||||||||||||||||||||
| 17 | } | ||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | 3 | ▶ | sub dive_out { | ||||||||||||||||||
|
Subroutine
dive_out: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 20 | 3 | my ( $self, $remove ) = @_; | |||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | 3 | ▶ | $remove = qr/\Q$remove\E$/ unless ref $remove eq 'Regexp'; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 23 | 3 | $self->_counter_selector_prefix( | |||||||||||||||||||
| 24 | $self->_counter_selector_prefix =~ s/$remove//r, | ||||||||||||||||||||
| 25 | ); | ||||||||||||||||||||
| 26 | } | ||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | 1 | ▶ | sub dive_up { | ||||||||||||||||||
|
Subroutine
dive_up: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 29 | 1 | shift->dive_out(qr/\S+\s*$/); | |||||||||||||||||||
| 30 | } | ||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | 2 | ▶ | sub dive_reset { | ||||||||||||||||||
|
Subroutine
dive_reset: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 33 | 2 | shift->_counter_selector_prefix(''); | |||||||||||||||||||
| 34 | } | ||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | 4 | ▶ | sub dived_text_is { | ||||||||||||||||||
|
Subroutine
dived_text_is: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 37 | 4 | my $self = shift; | |||||||||||||||||||
| 38 | 4 | my @in = @_; # can't modify in-place | |||||||||||||||||||
| 39 | 4 | $in[0] = $self->_counter_selector_prefix . $in[0]; | |||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | # Since Mojolicious 7.0 stupidly decided to stop trimming whitespace, | ||||||||||||||||||||
| 42 | # we work around it by using text_like instead with a regex that | ||||||||||||||||||||
| 43 | # does exact match, but ignores trailing/leading whitespace | ||||||||||||||||||||
| 44 | 4 | $in[1] = qr/ ^ \s* \Q$in[1]\E \s* $ /x; | |||||||||||||||||||
| 45 | 4 | $self->text_like( @in ); | |||||||||||||||||||
| 46 | } | ||||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | 37 | ▶ | sub element_count_is { | ||||||||||||||||||
|
Subroutine
element_count_is: called CC=5 SCAR=16.2
Pod
documented
| |||||||||||||||||||||
| 49 | 37 | my ($self, $selector, $wanted_count, $desc) = @_; | |||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | 37 | ▶ | croak 'You gave me an undefined element count that you want' | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 52 | unless defined $wanted_count; | ||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | 36 | my $pref = $self->_counter_selector_prefix; | |||||||||||||||||||
| 55 | 36 | $selector = join ',', map "$pref$_", split /,/,$selector; | |||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | 36 | ▶ | $desc ||= encode 'UTF-8', qq{element count for selector "$selector"}; | ||||||||||||||||||
|
Condition33%1/3
$desc ||= &encode("UTF-8", qq[element count for selector "$selector"])
MC/DC0%0/2
$desc ||= &encode("UTF-8", qq[element count for selector "$selector"])
$desc
&encode("UTF-8", qq[element count for selector "$selector"])
Truth table33%1/3
A ||= B
A= $descB= &encode("UTF-8", qq[element count for selector "$selector"])
| |||||||||||||||||||||
| 58 | 36 | ▶ | my $operator = $wanted_count =~ tr/<//d ? '<' | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 59 | : $wanted_count =~ tr/>//d ? '>' : '=='; | ||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | 36 | my $count = $self->tx->res->dom->find($selector)->size; | |||||||||||||||||||
| 62 | 36 | return $self->test('cmp_ok', $count, $operator, $wanted_count, $desc); | |||||||||||||||||||
| 63 | } | ||||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | 2 | q| | |||||||||||||||||||
| 67 | <Zoffix> GumbyBRAIN, Q: What did the computer do at lunchtime? | ||||||||||||||||||||
| 68 | A: Had a byte! | ||||||||||||||||||||
| 69 | <GumbyBRAIN> So even that's only one byte undefined in the | ||||||||||||||||||||
| 70 | thing I ever had. Where is beer the reason siv didn't walk straight. | ||||||||||||||||||||
| 71 | |; | ||||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | __END__ | ||||||||||||||||||||