File: 09_as_html.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 (42 lines) | stat: -rw-r--r-- 977 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
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 $inner = "<head></head><body><p>Hi there</p><p>How is life?</p></body>";
    my $html = "<html>$inner</html>";
    
    my $q = Web::Query->new($html);
    
    is $q->html => $inner, "html() returns inner html";
    is $q->as_html => $html, "as_html() returns element itself";
    
    my $scalar = $q->find('p')->as_html;
    my @array = $q->find('p')->as_html;
    
    is $scalar => '<p>Hi there</p>', 'called in scalar context';
    is \@array => [ '<p>Hi there</p>', q{<p>How is life?</p>} ],
        'called in list context';

    subtest 'join' => sub {
        is $q->find('p')->as_html(join => '!')
            => '<p>Hi there</p>!<p>How is life?</p>';
    };

}