File Coverage

blib/lib/Test/Mojo/Trim.pm
Criterion Covered Total %
statement 12 29 41.3
branch 0 8 0.0
condition 0 8 0.0
subroutine 4 6 66.6
pod 1 1 100.0
total 17 52 32.6


line stmt bran cond sub pod time code
1             package Test::Mojo::Trim;
2              
3 1     1   14477 use strict;
  1         2  
  1         31  
4              
5 1     1   497 use Mojo::DOM;
  1         60250  
  1         39  
6 1     1   9 use Mojo::Base 'Test::Mojo';
  1         6  
  1         4  
7 1     1   183973 use Mojo::Util 'squish';
  1         2  
  1         327  
8              
9             our $VERSION = '0.0904'; # VERSION
10             # ABSTRACT: Trim strings for Test::Mojo
11              
12             sub trimmed_content_is {
13 0     0 1   my $self = shift;
14 0           my $value = squish(Mojo::DOM->new(shift)->to_string);
15 0           my $desc = shift;
16              
17 0           my $dom = $self->tx->res->dom;
18 0           my $got = squish($dom->to_string);
19 0 0         my $error = defined $dom->at('#error') ? $dom->at('#error')->text : undef;
20 0 0         chomp $error if $error;
21              
22 0           $value =~ s{> <}{><}g;
23 0           $got =~ s{> <}{><}g;
24 0   0       $desc ||= 'exact match for trimmed content';
25              
26 0 0 0       if(defined $error && length $error) {
27 0 0 0       $desc .= (defined $error && length $error ? " (Error: $error)" : '');
28             my $table = $dom->find('#context table')->each(sub {
29 0     0     $desc .= $_->find('td')->map(sub { $_->text })->join(' ');
  0            
30 0           });
31 0           $got = '';
32             }
33              
34 0           return $self->_test('is', $got, $value, $desc);
35             }
36              
37             1;
38              
39             __END__