Update of /cvsroot/perl-xml/XML-LibXML-XPathContext/t
In directory sc8-pr-cvs1:/tmp/cvs-serv27421/t
Modified Files:
02-functions.t 01-variables.t 00-xpathcontext.t
Log Message:
* simplified variable lookup code to use a C structure instead of
a perl AV*
* made XPathContext reentrant (by saving the state before
a callback and restoring it afterwards).
* added get/setContextSize, get/setContextPosition
* added getVarLookupFunc
* added some tests and documentation for the new features
* applied last LibXML patch for perl-libxml-mm.c
Index: 02-functions.t
===================================================================
RCS file: /cvsroot/perl-xml/XML-LibXML-XPathContext/t/02-functions.t,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- 02-functions.t 29 Mar 2003 15:45:48 -0000 1.7
+++ 02-functions.t 3 Nov 2003 18:09:38 -0000 1.8
@@ -1,6 +1,6 @@
# -*- cperl -*-
use Test;
-BEGIN { plan tests => 28 };
+BEGIN { plan tests => 32 };
use XML::LibXML;
use XML::LibXML::XPathContext;
@@ -67,17 +67,19 @@
eval { $xc->findvalue('foo:copy("bar")') };
ok ($@);
-# test context locking mechanism
-$xc->registerFunction('test-lock1', sub { $xc->find('1') });
-$xc->registerFunction('test-lock2', sub { $xc->findnodes('1') });
-eval { $xc->find('test-lock1()') };
-ok($@);
-eval { $xc->findnodes('test-lock1()') };
-ok($@);
-eval { $xc->find('test-lock2()') };
-ok($@);
-eval { $xc->findnodes('test-lock2()') };
-ok($@);
+# test context reentrance
+$xc->registerFunction('test-lock1', sub { $xc->find('string(//node())') });
+$xc->registerFunction('test-lock2', sub { $xc->findnodes('//bar') });
+ok($xc->find('test-lock1()') eq $xc->find('string(//node())'));
+ok($xc->find('count(//bar)=2'));
+ok($xc->find('count(test-lock2())=count(//bar)'));
+ok($xc->find('count(test-lock2()|//bar)=count(//bar)'));
+ok($xc->findnodes('test-lock2()[2]')->pop()->isSameNode($xc->findnodes('//bar[2]')));
+
+$xc->registerFunction('test-lock3', sub { $xc->findnodes('test-lock2(//bar)') });
+ok($xc->find('count(test-lock2())=count(test-lock3())'));
+ok($xc->find('count(test-lock3())=count(//bar)'));
+ok($xc->find('count(test-lock3()|//bar)=count(//bar)'));
# function creating new nodes
$xc->registerFunction('new-foo',
Index: 01-variables.t
===================================================================
RCS file: /cvsroot/perl-xml/XML-LibXML-XPathContext/t/01-variables.t,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- 01-variables.t 4 Apr 2003 18:42:57 -0000 1.4
+++ 01-variables.t 3 Nov 2003 18:09:38 -0000 1.5
@@ -1,6 +1,6 @@
# -*- cperl -*-
use Test;
-BEGIN { plan tests => 33 };
+BEGIN { plan tests => 35 };
use XML::LibXML;
use XML::LibXML::XPathContext;
@@ -51,6 +51,7 @@
my $h2=\%variables;
ok("$h1" eq "$h2" );
ok($h1 eq $xc->getVarLookupData);
+ok(\&get_variable eq $xc->getVarLookupFunc);
# test values returned by XPath queries
ok($xc->find('$a') == 2);
@@ -76,6 +77,7 @@
$xc->unregisterVarLookupFunc();
eval { $xc->find('$a') };
ok($@);
+ok(!defined($xc->getVarLookupFunc()));
my $foo='foo';
$xc->registerVarLookupFunc(sub {},$foo);
Index: 00-xpathcontext.t
===================================================================
RCS file: /cvsroot/perl-xml/XML-LibXML-XPathContext/t/00-xpathcontext.t,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- 00-xpathcontext.t 22 Sep 2003 08:08:03 -0000 1.11
+++ 00-xpathcontext.t 3 Nov 2003 18:09:38 -0000 1.12
@@ -1,5 +1,5 @@
use Test;
-BEGIN { plan tests => 30 };
+BEGIN { plan tests => 54 };
use XML::LibXML;
use XML::LibXML::XPathContext;
@@ -99,3 +99,46 @@
$xc5->setContextNode($doc);
$xc5->findnodes('/');
ok(1);
+
+# check setting context position and size
+ok($xc4->getContextPosition() == -1);
+ok($xc4->getContextSize() == -1);
+eval { $xc4->setContextPosition(4); };
+ok($@);
+eval { $xc4->setContextPosition(-4); };
+ok($@);
+eval { $xc4->setContextSize(-4); };
+ok($@);
+eval { $xc4->findvalue('position()') };
+ok($@);
+eval { $xc4->findvalue('last()') };
+ok($@);
+
+$xc4->setContextSize(0);
+ok($xc4->getContextSize() == 0);
+ok($xc4->getContextPosition() == 0);
+ok($xc4->findvalue('position()')==0);
+ok($xc4->findvalue('last()')==0);
+
+$xc4->setContextSize(4);
+ok($xc4->getContextSize() == 4);
+ok($xc4->getContextPosition() == 1);
+ok($xc4->findvalue('last()')==4);
+ok($xc4->findvalue('position()')==1);
+eval { $xc4->setContextPosition(5); };
+ok($@);
+ok($xc4->findvalue('position()')==1);
+ok($xc4->getContextSize() == 4);
+$xc4->setContextPosition(4);
+ok($xc4->findvalue('position()')==4);
+ok($xc4->findvalue('position()=last()'));
+
+$xc4->setContextSize(-1);
+ok($xc4->getContextPosition() == -1);
+ok($xc4->getContextSize() == -1);
+eval { $xc4->findvalue('position()') };
+ok($@);
+eval { $xc4->findvalue('last()') };
+ok($@);
+
+
|