From: Petr P. <pa...@us...> - 2003-03-26 15:26:52
|
Update of /cvsroot/perl-xml/XML-LibXML-XPathContext/t In directory sc8-pr-cvs1:/tmp/cvs-serv10352/t Modified Files: 02-functions.t 01-variables.t Log Message: - support for unregisering - extension functions can be registered by name - POD update Index: 02-functions.t =================================================================== RCS file: /cvsroot/perl-xml/XML-LibXML-XPathContext/t/02-functions.t,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- 02-functions.t 21 Mar 2003 20:11:02 -0000 1.5 +++ 02-functions.t 26 Mar 2003 15:26:46 -0000 1.6 @@ -1,6 +1,6 @@ # -*- cperl -*- use Test; -BEGIN { plan tests => 23 }; +BEGIN { plan tests => 27 }; use XML::LibXML; use XML::LibXML::XPathContext; @@ -33,6 +33,22 @@ $xc->registerFunction('dummy', sub { 'DUMMY' }); ok($xc->findvalue('dummy()') eq 'DUMMY'); +# unregister it +$xc->unregisterFunction('dummy'); +eval { $xc->findvalue('dummy()') }; +ok ($@); + +# retister by name +sub dummy2 { 'DUMMY2' }; +$xc->registerFunction('dummy2', 'dummy2'); +ok($xc->findvalue('dummy2()') eq 'DUMMY2'); + +# unregister +$xc->unregisterFunction('dummy2'); +eval { $xc->findvalue('dummy2()') }; +ok ($@); + + # a mix of different arguments types $xc->registerFunction('join', sub { join shift, @@ -44,6 +60,11 @@ ok($xc->findvalue('join("","a","b","c")') eq 'abc'); ok($xc->findvalue('join("-","a",/foo,//*)') eq 'a-foo-foo-bar-bar'); ok($xc->findvalue('join("-",foo:copy(//*))') eq 'foo-bar-bar'); + +# unregister foo:copy +$xc->unregisterFunctionNS('copy','urn:foo'); +eval { $xc->findvalue('foo:copy("bar")') }; +ok ($@); # test context locking mechanism $xc->registerFunction('test-lock1', sub { $xc->find('1') }); Index: 01-variables.t =================================================================== RCS file: /cvsroot/perl-xml/XML-LibXML-XPathContext/t/01-variables.t,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- 01-variables.t 14 Mar 2003 16:26:08 -0000 1.2 +++ 01-variables.t 26 Mar 2003 15:26:47 -0000 1.3 @@ -1,6 +1,6 @@ # -*- cperl -*- use Test; -BEGIN { plan tests => 30 }; +BEGIN { plan tests => 31 }; use XML::LibXML; use XML::LibXML::XPathContext; @@ -46,7 +46,7 @@ my $xc = XML::LibXML::XPathContext->new($doc); ok(!defined($xc->getVarLookupData)); $xc->registerVarLookupFunc(\&get_variable,\%variables); -ok(defined($xc->getVarLookupData)); +ok(defined($xc->getVarLookupData)); my $h1=$xc->getVarLookupData; my $h2=\%variables; ok("$h1" eq "$h2" ); @@ -71,3 +71,8 @@ ok($xc->findnodes('$f')->pop->nodeName eq 'a'); ok($xc->findnodes('$f')->pop->isSameNode($variables{f})); ok($xc->findnodes('$g')->pop->isSameNode($variables{g})); + +# unregiser variable lookup +$xc->unregisterVarLookupFunc(); +eval { $xc->find('$a') }; +ok($@); |