File: next.t

package info (click to toggle)
libweb-query-perl 1.01-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 424 kB
  • sloc: perl: 984; xml: 329; makefile: 2
file content (58 lines) | stat: -rw-r--r-- 1,251 bytes parent folder | download
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
use strict;
use warnings;
use Test2::V0;
use Web::Query;

test('Web::Query');
test('Web::Query::LibXML') if eval "require Web::Query::LibXML; 1";

done_testing;

sub test {
    my $class = shift;
    diag "testing $class";
    no warnings 'redefine';
    *wq = \&{$class . "::wq"};

    my $wq = wq(<<HTML);

    <div class="container">
      <div class="d1">Hello</div>
      <div class="d2">World</div>
    </div>

    <div class="container">
      <div class="d1">Hello</div>
      <div class="d2">World</div>
    </div>
HTML

    my $elem = $wq->find('.d1')->next;
    is $elem->size, 2;
    is $elem->attr('class'), 'd2', 'next';

    subtest 'next->as_html' => sub {
        plan tests => 6;

        $wq = wq( q{
            <div>
                <b>one</b>
                two
                <i>three</i></div>
        } );

        my @expected = (
            [ b       => qr/one/ ],
            [ '#text' => qr/two/ ],
            [ 'i'     => qr/three/ ],
        );

        my $next = $wq->find('b');
        while( $next->size ) {
            my $exp = shift @expected;
            is $next->tagname => $exp->[0], 'tagname';
            like $next->as_html => $exp->[1], 'as_html';
            $next = $next->next;
        };
    };
}