#!/usr/bin/perl -w use strict; # $Id: /xmltwig/trunk/t/test_unique_xpath.t 4 2007-03-16T12:16:25.259192Z mrodrigu $ use File::Spec; use lib File::Spec->catdir(File::Spec->curdir,"t"); use tools; use XML::Twig; print "1..65\n"; my $t= XML::Twig->new->parse( \*DATA); foreach my $c ($t->descendants( 'c')) { is( $c->xpath, $c->text, "xpath"); is( $t->findvalue( $c->text), $c->text, "findvalue (>0)"); } foreach my $d ($t->descendants( 'd')) { is( $t->findvalue( $d->text), $d->text, "findvalue (<0)"); } foreach( 1..4) { is( $_, $t->root->first_child( "[$_]")->att( 'pos'), "first_child[$_]"); is( 5-$_, $t->root->first_child( "[-$_]")->att( 'pos'), "first_child[-$_]"); is( $_, $t->root->first_child( "b[$_]")->att( 'pos'), "first_child b[$_]"); is( 5-$_, $t->root->first_child( "b[-$_]")->att( 'pos'), "first_child b[-$_]"); } my $e= $t->get_xpath( '/a/b[-1]/e', 0); foreach( 1..4) { is( $_, $e->first_child( "f[$_]")->att( 'fpos'), "first_child f[$_]"); is( 5-$_, $e->first_child( "f[-$_]")->att( 'fpos'), "first_child f[-$_]"); is( $_, $e->first_child( "g[$_]")->att( 'gpos'), "first_child g[$_]"); is( 5-$_, $e->first_child( "g[-$_]")->att( 'gpos'), "first_child g[-$_]"); } foreach( 1..8) { is( $_, $e->first_child( "[$_]")->att( 'pos'), "first_child [$_]"); is( 9-$_, $e->first_child( "[-$_]")->att( 'pos'), "first_child [-$_]"); } exit 0; __DATA__ /a/b[1]/c[1] /a/b[1]/c[2] /a/b[-4]/d[-2] /a/b[-4]/d[-1] /a/b[2]/c[1] /a/b[-3]/d[-2] /a/b[-3]/d[-1] tata /a/b[2]/c[2] /a/b[3]/c titi /a/b[4]/c /a/b[4]/d[-1] tutu