File: attr.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 (41 lines) | stat: -rw-r--r-- 863 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
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 'set many attrs at the same time' => sub {
        my $doc = wq( '<div>hi</div>' );

        $doc->attr(
            foo => 1,
            bar => 'baz',
        );

        is $doc->attr('foo') => 1, 'foo is set';
        is $doc->attr('bar') => 'baz', 'bar is set';
    };

    subtest 'code ref as setter' => sub {
        my $doc = wq( '<div><img /><img alt="kitten" /></div>' );

        $doc->find('img')->attr(alt => sub{ $_ ||= 'A picture' });

        is [ $doc->find('img')->attr('alt') ],
            [ 'A picture', 'kitten' ];
    }


}