File: 01-xpath-query-builder.t

package info (click to toggle)
libtest-html-content-perl 0.13-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 328 kB
  • sloc: perl: 1,393; makefile: 2
file content (35 lines) | stat: -rwxr-xr-x 975 bytes parent folder | download | duplicates (7)
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
#!/usr/bin/perl -w
use strict;
use Test::More;
use lib 't';
use testlib;

# This test file tests the generation of the XPath queries
# The XPath queries have to work for both, XML::XPath
# and XML::LibXML, so not all features of XML::XPath
# can be used ...

my (@cases);
BEGIN {
  @cases=(
  [ tag => {href => 'http://www.perl.com', alt =>"foo"} => '//tag[@alt = "foo" and @href = "http://www.perl.com"]' ],
  [ tag => {href => qr'http://', alt =>"foo"} => '//tag[@alt = "foo" and @href]' ],
  [ tag => {href => qr'http://', alt => undef} => '//tag[not(@alt) and @href]' ],
  [ tag2 => {href => qr'http://', alt => undef} => '//tag2[not(@alt) and @href]' ],
  );
  # plan( tests => scalar @cases +1 );
};

sub run_case {
  my ($tag,$attr,$result) = @_;
  my ($query,$code) = Test::HTML::Content::__build_xpath_query("//".$tag,$attr);
  is( $query, $result, $query );
};

sub run {
  for my $case (@cases) {
    run_case( @$case );
  };
};

runtests( scalar @cases, \&run );