File: bug-text-contents.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 (40 lines) | stat: -rw-r--r-- 668 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
# see https://github.com/tokuhirom/Web-Query/issues/47

use strict;
use warnings;

use Test2::V0;

use lib 't/lib';
use WQTest;

my $html = <<'HTML';
<html>
    <p>Hello</p>
    <p>World</p>
</html>
HTML

WQTest::test {
    my $q = $_[0]->new($html);

    isa_ok $q, 'Web::Query';

    my @text;
    my @contents;

    $q->find('p')->each(sub {
        my ($i, $elem) = @_;
        push @text, $elem->text;
        push @contents, $elem->contents;
    });

    is \@text, [qw/ Hello World /], 'elements';

    is @contents, 2, 'two contents';

    isa_ok $_, 'Web::Query' for @contents;;

    is $contents[0]->text => 'Hello';
    is $contents[1]->text => 'World';
};