File: tests_3_23.t

package info (click to toggle)
libxml-twig-perl 1%3A3.52-3
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 4,952 kB
  • sloc: perl: 21,221; xml: 423; makefile: 9
file content (37 lines) | stat: -rwxr-xr-x 1,063 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
36
37
#!/usr/bin/perl -w
use strict;

use Carp;

use XML::Twig;

use File::Spec;
use lib File::Spec->catdir(File::Spec->curdir,"t");
use tools;

my $DEBUG=0;
print "1..6\n";

if( _use( 'XML::XPathEngine') || _use( 'XML::XPath') )
  { _use( 'XML::Twig::XPath');
    my $t= XML::Twig::XPath->nparse( q{<d>
    <s a="sa1"><e a="ea1">foo</e><e a="ea2">bar</e></s>
    <s a="sa2"><e a="ea3">baz</e><e a="ea4">foobar</e></s>
</d>});
    is( $t->findvalue( '//e[.="foo"]/@a'), "ea1", 'xpath on attributes');
    is( $t->findvalue( '//s[./e="foo"]/@a'), "sa1", 'xpath with elt content test');
    is( $t->findvalue( '/d/s[e="foo"]/@a'), "sa1", 'xpath with elt content test (short form)');
  }
else
  { skip( 3); }

{ my $t= XML::Twig->nparse( '<doc/>');
  my @xpath_result= $t->get_xpath( '/');
  is( ref( $xpath_result[0]), 'XML::Twig', "get_xpath( '/')");
  @xpath_result= $t->get_xpath( '/doc[1]');
  is( $xpath_result[0]->tag, 'doc', "get_xpath( '/doc[1]')");
  @xpath_result= $t->get_xpath( '/notdoc[1]');
  is( scalar( @xpath_result), 0, "get_xpath( '/notdoc[1]')");
}