File: 07_remove.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 (61 lines) | stat: -rw-r--r-- 1,689 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
59
60
61
# -*- perl -*-
use strict;
use warnings;
use utf8;
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" };

    subtest "remove and size" => sub {
        my $q = wq('t/data/foo.html');
        $q->find('.foo')->remove();
        is $q->find('.foo')->size() => 0, "all .foo are removed and cannot be found.";
    };
    
    subtest "remove and html" => sub {
        my $q = wq('t/data/foo.html');
        $q->find('.foo, .bar')->remove();
        my $result = $q->html;
        $result =~ s/\s//g;

        like $result, qr{^<head><title>test1</title></head><body>\s*</body>$}, ".foo and .bar are removed and not showing in html";
    };
    
    subtest "\$q->remove->end->html" => sub {
        my $q = wq('t/data/foo.html');
        my $result = $q->find('.foo, .bar')->remove->end->html;
        $result =~ s/\s//g;
        like(
            $result, 
            qr{^<head><title>test1</title></head><body></body>$},
            "The chaining works."
        );
    };
    
    subtest "remove root elements" => sub {
        my $q = wq('t/data/foo.html');
        $q->remove;
        is $q->size, 0, "size 0 after remove";
        is join('', $q->as_html), '', "html '' after remove"; # not '<></>'
    };
    
    subtest "remove elements via each()" => sub {
        my $q = wq('t/data/foo.html');
        $q->each(sub{ $_->remove });
        is $q->size, 0, "size 0 after remove";
        is join('', $q->as_html), '', "html '' after remove"; # not '<></>'
    };

}