~ubuntu-branches/ubuntu/wily/libhtml-selector-xpath-perl/wily

« back to all changes in this revision

Viewing changes to t/02_html.t

  • Committer: Package Import Robot
  • Author(s): gregor herrmann, gregor herrmann, Salvatore Bonaccorso
  • Date: 2014-10-26 13:39:37 UTC
  • mfrom: (1.1.9)
  • Revision ID: package-import@ubuntu.com-20141026133937-8fuyc8bqvu5fvhy9
Tags: 0.18-1
[ gregor herrmann ]
* Strip trailing slash from metacpan URLs.

[ Salvatore Bonaccorso ]
* Update Vcs-Browser URL to cgit web frontend

[ gregor herrmann ]
* Add debian/upstream/metadata
* Import upstream version 0.18
* Update years of packaging copyright.
* Mark package as autopkgtest-able.
* Declare compliance with Debian Policy 3.9.6.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
use strict;
2
2
use Test::Base;
3
3
use HTML::Selector::XPath;
 
4
use Encode qw(decode);
4
5
 
5
6
eval { require HTML::TreeBuilder::XPath };
6
7
plan skip_all => "HTML::TreeBuilder::XPath is not installed." if $@;
8
9
filters { selector => 'chomp', expected => [ 'lines', 'array' ] };
9
10
plan tests => 1 * blocks;
10
11
 
 
12
binmode STDOUT, ':encoding(UTF-8)'; # because our test names contain UTF-8
 
13
binmode STDERR, ':encoding(UTF-8)'; # because our test names contain UTF-8
 
14
# But it seems that Test::More or Test::Base or whoever mess with STDOUT/STDERR
 
15
# on their own.
 
16
 
11
17
run {
12
18
    my $block = shift;
13
19
    my $tree = HTML::TreeBuilder::XPath->new;
14
 
    $tree->parse($block->input);
 
20
    my $input= decode( 'UTF-8', $block->input);
 
21
    $tree->parse($input);
15
22
    $tree->eof;
16
23
 
 
24
    my $sel= decode( 'UTF-8', scalar $block->selector );
17
25
    my $expr;
18
26
    if ($block->selector =~ m!^/!) {
19
 
        $expr = $block->selector;
 
27
        $expr = $sel;
20
28
    } else {
21
 
        $expr = HTML::Selector::XPath->new($block->selector)->to_xpath
 
29
        $expr = HTML::Selector::XPath->new($sel)->to_xpath
22
30
    };
23
31
    my @nodes = $tree->findnodes( $expr );
24
 
    is_deeply [ map $_->as_XML, @nodes ], $block->expected,
25
 
        $block->selector . " -> $expr";
 
32
    my $expected= [ map { decode( 'UTF-8', $_ )} @{ $block->expected } ];
 
33
    my $got= [ map $_->as_XML, @nodes ];
 
34
    is_deeply $got, $expected,
 
35
        $sel . " -> $expr";
26
36
}
27
37
 
28
38
__END__
418
428
<em>here</em>
419
429
<em>everywhere</em>
420
430
<em>nowhere</em>
 
431
===
 
432
--- input
 
433
<body>
 
434
<div class="小飼弾">小飼弾</div>
 
435
<div class="bar">foo</div>
 
436
</body>
 
437
--- selector
 
438
div.小飼弾
 
439
--- expected
 
440
<div class="小飼弾">小飼弾</div>
 
441