File: 44test_compare.t

package info (click to toggle)
libxml-xpath-perl 1.48-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 608 kB
  • sloc: perl: 4,444; xml: 34; makefile: 10
file content (27 lines) | stat: -rw-r--r-- 871 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/perl

use strict;
use warnings;
use XML::XPath;
use Test::More;

my $xml='<root att="root_att"><daughter att="3"/><daughter att="4"/><daughter att="5"/></root>';
my %results= ( '/root/daughter[@att<"4"]' => 'daughter[3]',
               '/root/daughter[@att<4]'   => 'daughter[3]',
               '//daughter[@att<4]'       => 'daughter[3]',
               '/root/daughter[@att>4]'   => 'daughter[5]',
               '/root/daughter[@att>5]'   => '',
               '/root/daughter[@att<3]'   => '',
             );

plan tests => scalar keys %results;

my $xpath  = XML::XPath->new( xml => $xml);
foreach my $path ( keys %results) {
    my @xpath_result = $xpath->findnodes( $path);
    is( dump_nodes( @xpath_result) => $results{$path}, "path: $path");
}

sub dump_nodes {
    return join '-', map { $_->getName . "[" . $_->getAttribute( 'att') . "]" } @_
}