File: test_preceding.t

package info (click to toggle)
libhtml-treebuilder-xpath-perl 0.14-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 108 kB
  • sloc: perl: 507; makefile: 2
file content (32 lines) | stat: -rw-r--r-- 727 bytes parent folder | download | duplicates (5)
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
#!/usr/bin/perl

use strict;
use warnings;

use HTML::TreeBuilder::XPath;
use Test::More tests => 3;

my $html=q{
<html>
  <head />
  <body>
    <a name="a1">foo</a>
    <p class="c1" id="ip1">p1</p>
    <p id="ip2">f1</p>
    <p class="c1" id="ip3">p2</p>
    <p id="ip4">f2</p>
    <p id="ip5">f3</p>
  </body>
</html>};

my $tree  = HTML::TreeBuilder->new_from_content( $html);

test_q( $tree, q{//p[@class="c1"][2]/preceding::p[1]}, "f1");
test_q( $tree, q{//p[@class="c1"][2]/preceding::p[2]}, "p1");
test_q( $tree, q{//p[@class="c1"][2]/preceding::p}, "p1f1");

sub test_q
  { my( $tree, $query, $expected)= @_;
    my $class= ref( $tree);
    is( $tree->findvalue( $query), $expected, "$class: $query ($expected)");
  }