1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
use strict;
use warnings;
use lib 't/lib';
use Test2::V0;
use Web::Query;
use WQTest;
my $doc = <<'END';
<div>
<p>stuff</p>
<h1>alpha</h1>
<p>aaa</p>
<h1>beta></h1>
<h1>gamma</h1>
<p>bbb<p>
<p>ccc</p>
</div>
END
WQTest::test {
my $class = shift;
subtest 'straight split' => sub {
my @splitted = $class->new($doc)->split( 'h1' );
is scalar @splitted => 4;
like $splitted[0]->as_html(join => ''),
qr/stuff/;
like $splitted[1]->as_html(join => ''),
qr/alpha.*aaa/s;
like $splitted[2]->as_html(join => ''),
qr/beta/;
like $splitted[3]->as_html(join => ''),
qr/gamma.*ccc/s;
};
subtest 'split in pairs' => sub {
my @splitted = $class->new($doc)->split( 'h1', pairs => 1 );
is scalar @splitted => 4;
like $splitted[0][1]->as_html(join => ''),
qr/stuff/;
like $splitted[1][0]->as_html(join => ''),
qr/alpha/;
like $splitted[1][1]->as_html(join => ''),
qr/aaa/;
};
subtest 'skip leading' => sub {
my @splitted = $class->new($doc)->split( 'h1', pairs => 1, skip_leading => 1 );
is scalar @splitted => 3;
like $splitted[0][0]->as_html( join => '' ),
qr/alpha/;
like $splitted[0][1]->as_html( join => '' ),
qr/aaa/;
};
}
|