summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@baserock.org>2003-01-26 19:35:03 +0000
committer <>2015-02-23 10:18:26 +0000
commita2d12bc84fb2af87dd1c0c6e5bc854554902cd67 (patch)
tree7665979c7c281b21971de576d93246a022bff649 /t
downloadperl-xml-xpath-master.tar.gz
Imported from /home/lorry/working-area/delta_perl-xml-xpath/XML-XPath-1.13.tar.gz.HEADXML-XPath-1.13master
Diffstat (limited to 't')
-rw-r--r--t/01basic.t33
-rw-r--r--t/02descendant.t23
-rw-r--r--t/03star.t26
-rw-r--r--t/04pos.t22
-rw-r--r--t/05attrib.t28
-rw-r--r--t/06attrib_val.t25
-rw-r--r--t/07count.t27
-rw-r--r--t/08name.t25
-rw-r--r--t/09a_string_length.t30
-rw-r--r--t/09string_length.t28
-rw-r--r--t/10pipe.t27
-rw-r--r--t/11axischild.t18
-rw-r--r--t/12axisdescendant.t27
-rw-r--r--t/13axisparent.t19
-rw-r--r--t/14axisancestor.t22
-rw-r--r--t/15axisfol_sib.t24
-rw-r--r--t/16axisprec_sib.t44
-rw-r--r--t/17axisfollowing.t45
-rw-r--r--t/18axispreceding.t39
-rw-r--r--t/19axisd_or_s.t22
-rw-r--r--t/20axisa_or_s.t22
-rw-r--r--t/21allnodes.t60
-rw-r--r--t/22name_select.t23
-rw-r--r--t/23func.t41
-rw-r--r--t/24namespaces.t56
-rw-r--r--t/25scope.t27
-rw-r--r--t/26predicate.t26
-rw-r--r--t/27asxml.t13
-rw-r--r--t/28ancestor2.t37
-rw-r--r--t/29desc_with_predicate.t21
-rw-r--r--t/30lang.t20
-rw-r--r--t/insert.t53
-rw-r--r--t/rdf.t59
-rw-r--r--t/remove.t44
-rw-r--r--t/stress.t57
35 files changed, 1113 insertions, 0 deletions
diff --git a/t/01basic.t b/t/01basic.t
new file mode 100644
index 0000000..1c68c12
--- /dev/null
+++ b/t/01basic.t
@@ -0,0 +1,33 @@
+use Test;
+BEGIN { plan tests => 5 }
+
+use XML::XPath;
+
+ok(1);
+my $xp = XML::XPath->new(ioref => *DATA);
+ok($xp);
+
+my @root = $xp->findnodes('/AAA');
+ok(@root, 1);
+
+my @ccc = $xp->findnodes('/AAA/CCC');
+ok(@ccc, 3);
+
+my @bbb = $xp->findnodes('/AAA/DDD/BBB');
+ok(@bbb, 2);
+
+__DATA__
+<AAA>
+ <BBB/>
+ <CCC/>
+ <BBB/>
+ <CCC/>
+ <BBB/>
+ <!-- comment -->
+ <DDD>
+ <BBB/>
+ Text
+ <BBB/>
+ </DDD>
+ <CCC/>
+</AAA>
diff --git a/t/02descendant.t b/t/02descendant.t
new file mode 100644
index 0000000..6c83e46
--- /dev/null
+++ b/t/02descendant.t
@@ -0,0 +1,23 @@
+use Test;
+BEGIN { plan tests => 4 }
+
+use XML::XPath;
+ok(1);
+
+my $xp = XML::XPath->new(ioref => *DATA);
+ok($xp);
+
+my @bbb = $xp->findnodes('//BBB');
+ok(@bbb, 5);
+
+my @subbbb = $xp->findnodes('//DDD/BBB');
+ok(@subbbb, 3);
+
+__DATA__
+<AAA>
+<BBB/>
+<CCC/>
+<BBB/>
+<DDD><BBB/></DDD>
+<CCC><DDD><BBB/><BBB/></DDD></CCC>
+</AAA>
diff --git a/t/03star.t b/t/03star.t
new file mode 100644
index 0000000..8fc6a4e
--- /dev/null
+++ b/t/03star.t
@@ -0,0 +1,26 @@
+use Test;
+BEGIN { plan tests => 5 }
+
+use XML::XPath;
+ok(1);
+
+my $xp = XML::XPath->new(ioref => *DATA);
+ok($xp);
+
+my @nodes;
+
+@nodes = $xp->findnodes('/AAA/CCC/DDD/*');
+ok(@nodes, 4);
+
+@nodes = $xp->findnodes('/*/*/*/BBB');
+ok(@nodes, 5);
+
+@nodes = $xp->findnodes('//*');
+ok(@nodes, 17);
+
+__DATA__
+<AAA>
+<XXX><DDD><BBB/><BBB/><EEE/><FFF/></DDD></XXX>
+<CCC><DDD><BBB/><BBB/><EEE/><FFF/></DDD></CCC>
+<CCC><BBB><BBB><BBB/></BBB></BBB></CCC>
+</AAA>
diff --git a/t/04pos.t b/t/04pos.t
new file mode 100644
index 0000000..8552ab2
--- /dev/null
+++ b/t/04pos.t
@@ -0,0 +1,22 @@
+use Test;
+BEGIN { plan tests => 4 }
+
+use XML::XPath;
+ok(1);
+
+my $xp = XML::XPath->new(ioref => *DATA);
+ok($xp);
+
+my $first = $xp->findvalue('/AAA/BBB[1]/@id');
+ok($first, "first");
+
+my $last = $xp->findvalue('/AAA/BBB[last()]/@id');
+ok($last, "last");
+
+__DATA__
+<AAA>
+<BBB id="first"/>
+<BBB/>
+<BBB/>
+<BBB id="last"/>
+</AAA>
diff --git a/t/05attrib.t b/t/05attrib.t
new file mode 100644
index 0000000..62c7370
--- /dev/null
+++ b/t/05attrib.t
@@ -0,0 +1,28 @@
+use Test;
+BEGIN { plan tests => 6 }
+
+use XML::XPath;
+ok(1);
+
+my $xp = XML::XPath->new(ioref => *DATA);
+ok($xp);
+
+my @ids = $xp->findnodes('//BBB[@id]');
+ok(@ids, 2);
+
+my @names = $xp->findnodes('//BBB[@name]');
+ok(@names, 1);
+
+my @attribs = $xp->findnodes('//BBB[@*]');
+ok(@attribs, 3);
+
+my @noattribs = $xp->findnodes('//BBB[not(@*)]');
+ok(@noattribs, 1);
+
+__DATA__
+<AAA>
+<BBB id='b1'/>
+<BBB id='b2'/>
+<BBB name='bbb'/>
+<BBB/>
+</AAA>
diff --git a/t/06attrib_val.t b/t/06attrib_val.t
new file mode 100644
index 0000000..b659bf5
--- /dev/null
+++ b/t/06attrib_val.t
@@ -0,0 +1,25 @@
+use Test;
+BEGIN { plan tests => 5 }
+
+use XML::XPath;
+ok(1);
+
+my $xp = XML::XPath->new(ioref => *DATA);
+ok($xp);
+
+my @nodes;
+@nodes = $xp->findnodes('//BBB[@id = "b1"]');
+ok(@nodes, 1);
+
+@nodes = $xp->findnodes('//BBB[@name = "bbb"]');
+ok(@nodes, 1);
+
+@nodes = $xp->findnodes('//BBB[normalize-space(@name) = "bbb"]');
+ok(@nodes, 2);
+
+__DATA__
+<AAA>
+<BBB id='b1'/>
+<BBB name=' bbb '/>
+<BBB name='bbb'/>
+</AAA>
diff --git a/t/07count.t b/t/07count.t
new file mode 100644
index 0000000..6c0cae9
--- /dev/null
+++ b/t/07count.t
@@ -0,0 +1,27 @@
+use Test;
+BEGIN { plan tests => 7 }
+
+use XML::XPath;
+ok(1);
+
+my $xp = XML::XPath->new(ioref => *DATA);
+ok($xp);
+
+my @nodes;
+@nodes = $xp->findnodes('//*[count(BBB) = 2]');
+ok($nodes[0]->getName, "DDD");
+
+@nodes = $xp->findnodes('//*[count(*) = 2]');
+ok(@nodes, 2);
+
+@nodes = $xp->findnodes('//*[count(*) = 3]');
+ok(@nodes, 2);
+ok($nodes[0]->getName, "AAA");
+ok($nodes[1]->getName, "CCC");
+
+__DATA__
+<AAA>
+<CCC><BBB/><BBB/><BBB/></CCC>
+<DDD><BBB/><BBB/></DDD>
+<EEE><CCC/><DDD/></EEE>
+</AAA>
diff --git a/t/08name.t b/t/08name.t
new file mode 100644
index 0000000..15eb7fb
--- /dev/null
+++ b/t/08name.t
@@ -0,0 +1,25 @@
+use Test;
+BEGIN { plan tests => 5 }
+
+use XML::XPath;
+ok(1);
+
+my $xp = XML::XPath->new(ioref => *DATA);
+ok($xp);
+
+my @nodes;
+@nodes = $xp->findnodes('//*[name() = "BBB"]');
+ok(@nodes, 5);
+
+@nodes = $xp->findnodes('//*[starts-with(name(), "B")]');
+ok(@nodes, 7);
+
+@nodes = $xp->findnodes('//*[contains(name(), "C")]');
+ok(@nodes, 3);
+
+__DATA__
+<AAA>
+<BCC><BBB/><BBB/><BBB/></BCC>
+<DDB><BBB/><BBB/></DDB>
+<BEC><CCC/><DBD/></BEC>
+</AAA>
diff --git a/t/09a_string_length.t b/t/09a_string_length.t
new file mode 100644
index 0000000..0a1b806
--- /dev/null
+++ b/t/09a_string_length.t
@@ -0,0 +1,30 @@
+use Test;
+BEGIN { plan tests => 5 }
+
+use XML::XPath;
+
+my $doc_one = qq|<doc><para>para one</para></doc>|;
+
+my $xp = XML::XPath->new(xml => $doc_one);
+ok($xp);
+
+my $doc_one_chars = $xp->find('string-length(/doc/text())');
+ok($doc_one_chars == 0, 1);
+
+my $doc_two = qq|
+<doc>
+ <para>para one has <b>bold</b> text</para>
+</doc>
+|;
+
+$xp = undef;
+
+$xp = XML::XPath->new(xml => $doc_two);
+ok($xp);
+
+my $doc_two_chars = $xp->find('string-length(/doc/text())');
+ok($doc_two_chars == 3, 1);
+
+my $doc_two_para_chars = $xp->find('string-length(/doc/para/text())');
+ok($doc_two_para_chars == 13, 1);
+
diff --git a/t/09string_length.t b/t/09string_length.t
new file mode 100644
index 0000000..b08bee4
--- /dev/null
+++ b/t/09string_length.t
@@ -0,0 +1,28 @@
+use Test;
+BEGIN { plan tests => 5 }
+
+use XML::XPath;
+ok(1);
+
+my $xp = XML::XPath->new(ioref => *DATA);
+ok($xp);
+
+my @nodes;
+@nodes = $xp->findnodes('//*[string-length(name()) = 3]');
+ok(@nodes, 2);
+
+@nodes = $xp->findnodes('//*[string-length(name()) < 3]');
+ok(@nodes, 2);
+
+@nodes = $xp->findnodes('//*[string-length(name()) > 3]');
+ok(@nodes, 3);
+
+__DATA__
+<AAA>
+<Q/>
+<SSSS/>
+<BB/>
+<CCC/>
+<DDDDDDDD/>
+<EEEE/>
+</AAA>
diff --git a/t/10pipe.t b/t/10pipe.t
new file mode 100644
index 0000000..85a2677
--- /dev/null
+++ b/t/10pipe.t
@@ -0,0 +1,27 @@
+use Test;
+BEGIN { plan tests => 6, todo => [] }
+
+use XML::XPath;
+ok(1);
+
+my $xp = XML::XPath->new(ioref => *DATA);
+ok($xp);
+
+my @nodes;
+@nodes = $xp->findnodes('//CCC | //BBB');
+ok(@nodes, 3);
+ok($nodes[0]->getName, "BBB"); # test document order
+
+@nodes = $xp->findnodes('/AAA/EEE | //BBB');
+ok(@nodes, 2);
+
+@nodes = $xp->findnodes('/AAA/EEE | //DDD/CCC | /AAA | //BBB');
+ok(@nodes, 4);
+
+__DATA__
+<AAA>
+<BBB/>
+<CCC/>
+<DDD><CCC/></DDD>
+<EEE/>
+</AAA>
diff --git a/t/11axischild.t b/t/11axischild.t
new file mode 100644
index 0000000..58058a1
--- /dev/null
+++ b/t/11axischild.t
@@ -0,0 +1,18 @@
+use Test;
+BEGIN { plan tests => 6 }
+
+use XML::XPath::Parser;
+
+ok(1);
+
+my $xp = XML::XPath::Parser->new();
+ok($xp);
+
+ok($xp->parse('/AAA')->as_string, "(/child::AAA)");
+
+ok($xp->parse('/AAA/BBB')->as_string, "(/child::AAA/child::BBB)");
+
+ok($xp->parse('/child::AAA/child::BBB')->as_string,
+ "(/child::AAA/child::BBB)");
+
+ok($xp->parse('/child::AAA/BBB')->as_string, "(/child::AAA/child::BBB)");
diff --git a/t/12axisdescendant.t b/t/12axisdescendant.t
new file mode 100644
index 0000000..e08992b
--- /dev/null
+++ b/t/12axisdescendant.t
@@ -0,0 +1,27 @@
+use Test;
+BEGIN { plan tests => 6 }
+
+use XML::XPath;
+ok(1);
+
+my $xp = XML::XPath->new(ioref => *DATA);
+ok($xp);
+
+my @nodes;
+@nodes = $xp->findnodes('/descendant::*');
+ok(@nodes, 11);
+
+@nodes = $xp->findnodes('/AAA/BBB/descendant::*');
+ok(@nodes, 4);
+
+@nodes = $xp->findnodes('//CCC/descendant::*');
+ok(@nodes, 6);
+
+@nodes = $xp->findnodes('//CCC/descendant::DDD');
+ok(@nodes, 3);
+
+__DATA__
+<AAA>
+<BBB><DDD><CCC><DDD/><EEE/></CCC></DDD></BBB>
+<CCC><DDD><EEE><DDD><FFF/></DDD></EEE></DDD></CCC>
+</AAA>
diff --git a/t/13axisparent.t b/t/13axisparent.t
new file mode 100644
index 0000000..21d7706
--- /dev/null
+++ b/t/13axisparent.t
@@ -0,0 +1,19 @@
+use Test;
+BEGIN { plan tests => 4 }
+
+use XML::XPath;
+ok(1);
+
+my $xp = XML::XPath->new(ioref => *DATA);
+ok($xp);
+
+my @nodes;
+@nodes = $xp->findnodes('//DDD/parent::*');
+ok(@nodes, 4);
+ok($nodes[3]->getName, "EEE");
+
+__DATA__
+<AAA>
+<BBB><DDD><CCC><DDD/><EEE/></CCC></DDD></BBB>
+<CCC><DDD><EEE><DDD><FFF/></DDD></EEE></DDD></CCC>
+</AAA>
diff --git a/t/14axisancestor.t b/t/14axisancestor.t
new file mode 100644
index 0000000..c10e5b5
--- /dev/null
+++ b/t/14axisancestor.t
@@ -0,0 +1,22 @@
+use Test;
+BEGIN { plan tests => 5 }
+
+use XML::XPath;
+ok(1);
+
+my $xp = XML::XPath->new(ioref => *DATA);
+ok($xp);
+
+my @nodes;
+@nodes = $xp->findnodes('/AAA/BBB/DDD/CCC/EEE/ancestor::*');
+ok(@nodes, 4);
+ok($nodes[1]->getName, "BBB"); # test document order
+
+@nodes = $xp->findnodes('//FFF/ancestor::*');
+ok(@nodes, 5);
+
+__DATA__
+<AAA>
+<BBB><DDD><CCC><DDD/><EEE/></CCC></DDD></BBB>
+<CCC><DDD><EEE><DDD><FFF/></DDD></EEE></DDD></CCC>
+</AAA>
diff --git a/t/15axisfol_sib.t b/t/15axisfol_sib.t
new file mode 100644
index 0000000..494f326
--- /dev/null
+++ b/t/15axisfol_sib.t
@@ -0,0 +1,24 @@
+use Test;
+BEGIN { plan tests => 6 }
+
+use XML::XPath;
+ok(1);
+
+my $xp = XML::XPath->new(ioref => *DATA);
+ok($xp);
+
+my @nodes;
+@nodes = $xp->findnodes('/AAA/BBB/following-sibling::*');
+ok(@nodes, 2);
+ok($nodes[1]->getName, "CCC"); # test document order
+
+@nodes = $xp->findnodes('//CCC/following-sibling::*');
+ok(@nodes, 3);
+ok($nodes[1]->getName, "FFF");
+
+__DATA__
+<AAA>
+<BBB><CCC/><DDD/></BBB>
+<XXX><DDD><EEE/><DDD/><CCC/><FFF/><FFF><GGG/></FFF></DDD></XXX>
+<CCC><DDD/></CCC>
+</AAA>
diff --git a/t/16axisprec_sib.t b/t/16axisprec_sib.t
new file mode 100644
index 0000000..b1bbc6e
--- /dev/null
+++ b/t/16axisprec_sib.t
@@ -0,0 +1,44 @@
+use Test;
+BEGIN { plan tests => 7 }
+
+use XML::XPath;
+ok(1);
+
+my $xp = XML::XPath->new(ioref => *DATA);
+ok($xp);
+
+my @nodes;
+@nodes = $xp->findnodes('/AAA/XXX/preceding-sibling::*');
+ok(@nodes, 1);
+ok($nodes[0]->getName, "BBB");
+
+@nodes = $xp->findnodes('//CCC/preceding-sibling::*');
+ok(@nodes, 4);
+
+@nodes = $xp->findnodes('/AAA/CCC/preceding-sibling::*[1]');
+ok($nodes[0]->getName, "XXX");
+
+@nodes = $xp->findnodes('/AAA/CCC/preceding-sibling::*[2]');
+ok($nodes[0]->getName, "BBB");
+
+__DATA__
+<AAA>
+ <BBB>
+ <CCC/>
+ <DDD/>
+ </BBB>
+ <XXX>
+ <DDD>
+ <EEE/>
+ <DDD/>
+ <CCC/>
+ <FFF/>
+ <FFF>
+ <GGG/>
+ </FFF>
+ </DDD>
+ </XXX>
+ <CCC>
+ <DDD/>
+ </CCC>
+</AAA>
diff --git a/t/17axisfollowing.t b/t/17axisfollowing.t
new file mode 100644
index 0000000..e85322c
--- /dev/null
+++ b/t/17axisfollowing.t
@@ -0,0 +1,45 @@
+use Test;
+BEGIN { plan tests => 4 }
+
+use XML::XPath;
+ok(1);
+
+my $xp = XML::XPath->new(ioref => *DATA);
+ok($xp);
+
+my @nodes;
+@nodes = $xp->findnodes('/AAA/XXX/following::*');
+ok(@nodes, 2);
+
+@nodes = $xp->findnodes('//ZZZ/following::*');
+ok(@nodes, 12);
+
+__DATA__
+<AAA>
+<BBB>
+ <CCC/>
+ <ZZZ>
+ <DDD/>
+ <DDD>
+ <EEE/>
+ </DDD>
+ </ZZZ>
+ <FFF>
+ <GGG/>
+ </FFF>
+</BBB>
+<XXX>
+ <DDD>
+ <EEE/>
+ <DDD/>
+ <CCC/>
+ <FFF/>
+ <FFF>
+ <GGG/>
+ </FFF>
+ </DDD>
+</XXX>
+<CCC>
+ <DDD/>
+</CCC>
+</AAA>
diff --git a/t/18axispreceding.t b/t/18axispreceding.t
new file mode 100644
index 0000000..97e4e18
--- /dev/null
+++ b/t/18axispreceding.t
@@ -0,0 +1,39 @@
+use Test;
+BEGIN { plan tests => 4 }
+
+use XML::XPath;
+ok(1);
+
+my $xp = XML::XPath->new(ioref => *DATA);
+ok($xp);
+
+my @nodes;
+@nodes = $xp->findnodes('/AAA/XXX/preceding::*');
+ok(@nodes, 4);
+
+@nodes = $xp->findnodes('//GGG/preceding::*');
+ok(@nodes, 8);
+
+__DATA__
+<AAA>
+ <BBB>
+ <CCC/>
+ <ZZZ>
+ <DDD/>
+ </ZZZ>
+ </BBB>
+ <XXX>
+ <DDD>
+ <EEE/>
+ <DDD/>
+ <CCC/>
+ <FFF/>
+ <FFF>
+ <GGG/>
+ </FFF>
+ </DDD>
+ </XXX>
+ <CCC>
+ <DDD/>
+ </CCC>
+</AAA>
diff --git a/t/19axisd_or_s.t b/t/19axisd_or_s.t
new file mode 100644
index 0000000..8fc455d
--- /dev/null
+++ b/t/19axisd_or_s.t
@@ -0,0 +1,22 @@
+use Test;
+BEGIN { plan tests => 4 }
+
+use XML::XPath;
+ok(1);
+
+my $xp = XML::XPath->new(ioref => *DATA);
+ok($xp);
+
+my @nodes;
+@nodes = $xp->findnodes('/AAA/XXX/descendant-or-self::*');
+ok(@nodes, 8);
+
+@nodes = $xp->findnodes('//CCC/descendant-or-self::*');
+ok(@nodes, 4);
+
+__DATA__
+<AAA>
+<BBB><CCC/><ZZZ><DDD/></ZZZ></BBB>
+<XXX><DDD><EEE/><DDD/><CCC/><FFF/><FFF><GGG/></FFF></DDD></XXX>
+<CCC><DDD/></CCC>
+</AAA>
diff --git a/t/20axisa_or_s.t b/t/20axisa_or_s.t
new file mode 100644
index 0000000..d5e767a
--- /dev/null
+++ b/t/20axisa_or_s.t
@@ -0,0 +1,22 @@
+use Test;
+BEGIN { plan tests => 4 }
+
+use XML::XPath;
+ok(1);
+
+my $xp = XML::XPath->new(ioref => *DATA);
+ok($xp);
+
+my @nodes;
+@nodes = $xp->findnodes('/AAA/XXX/DDD/EEE/ancestor-or-self::*');
+ok(@nodes, 4);
+
+@nodes = $xp->findnodes('//GGG/ancestor-or-self::*');
+ok(@nodes, 5);
+
+__DATA__
+<AAA>
+<BBB><CCC/><ZZZ><DDD/></ZZZ></BBB>
+<XXX><DDD><EEE/><DDD/><CCC/><FFF/><FFF><GGG/></FFF></DDD></XXX>
+<CCC><DDD/></CCC>
+</AAA>
diff --git a/t/21allnodes.t b/t/21allnodes.t
new file mode 100644
index 0000000..1010538
--- /dev/null
+++ b/t/21allnodes.t
@@ -0,0 +1,60 @@
+use Test;
+BEGIN { plan tests => 11 }
+
+use XML::XPath;
+ok(1);
+
+my $xp = XML::XPath->new(ioref => *DATA);
+ok($xp);
+
+my @nodes;
+@nodes = $xp->findnodes('//GGG/ancestor::*');
+ok(@nodes, 4);
+
+@nodes = $xp->findnodes('//GGG/descendant::*');
+ok(@nodes, 3);
+
+@nodes = $xp->findnodes('//GGG/following::*');
+ok(@nodes, 3);
+ok($nodes[0]->getName, "VVV");
+
+@nodes = $xp->findnodes('//GGG/preceding::*');
+ok(@nodes, 5);
+ok($nodes[0]->getName, "BBB"); # document order, not HHH
+
+@nodes = $xp->findnodes('//GGG/self::*');
+ok(@nodes, 1);
+ok($nodes[0]->getName, "GGG");
+
+@nodes = $xp->findnodes('//GGG/ancestor::* |
+ //GGG/descendant::* |
+ //GGG/following::* |
+ //GGG/preceding::* |
+ //GGG/self::*');
+ok(@nodes, 16);
+
+__DATA__
+<AAA>
+ <BBB>
+ <CCC/>
+ <ZZZ/>
+ </BBB>
+ <XXX>
+ <DDD>
+ <EEE/>
+ <FFF>
+ <HHH/>
+ <GGG> <!-- Watch this node -->
+ <JJJ>
+ <QQQ/>
+ </JJJ>
+ <JJJ/>
+ </GGG>
+ <VVV/>
+ </FFF>
+ </DDD>
+ </XXX>
+ <CCC>
+ <DDD/>
+ </CCC>
+</AAA>
diff --git a/t/22name_select.t b/t/22name_select.t
new file mode 100644
index 0000000..5977540
--- /dev/null
+++ b/t/22name_select.t
@@ -0,0 +1,23 @@
+use Test;
+BEGIN { plan tests => 4 }
+
+use XML::XPath;
+ok(1);
+
+my $xp = XML::XPath->new(ioref => *DATA);
+ok($xp);
+
+my @nodes;
+@nodes = $xp->findnodes('//*[name() = /AAA/SELECT]');
+ok(@nodes, 2);
+ok($nodes[0]->getName, "BBB");
+
+__DATA__
+<AAA>
+<SELECT>BBB</SELECT>
+<BBB/>
+<CCC/>
+<DDD>
+<BBB/>
+</DDD>
+</AAA>
diff --git a/t/23func.t b/t/23func.t
new file mode 100644
index 0000000..e2514c3
--- /dev/null
+++ b/t/23func.t
@@ -0,0 +1,41 @@
+use Test;
+BEGIN { plan tests => 5 }
+
+use XML::XPath;
+ok(1);
+
+my $xp = XML::XPath->new(ioref => *DATA);
+ok($xp);
+
+my @nodes;
+@nodes = $xp->findnodes('//BBB[position() mod 2 = 0 ]');
+ok(@nodes, 4);
+
+@nodes = $xp->findnodes('//BBB
+ [ position() = floor(last() div 2 + 0.5)
+ or
+ position() = ceiling(last() div 2 + 0.5) ]');
+
+ok(@nodes, 2);
+
+@nodes = $xp->findnodes('//CCC
+ [ position() = floor(last() div 2 + 0.5)
+ or
+ position() = ceiling(last() div 2 + 0.5) ]');
+
+ok(@nodes, 1);
+
+__DATA__
+<AAA>
+ <BBB/>
+ <BBB/>
+ <BBB/>
+ <BBB/>
+ <BBB/>
+ <BBB/>
+ <BBB/>
+ <BBB/>
+ <CCC/>
+ <CCC/>
+ <CCC/>
+</AAA>
diff --git a/t/24namespaces.t b/t/24namespaces.t
new file mode 100644
index 0000000..b77f9dc
--- /dev/null
+++ b/t/24namespaces.t
@@ -0,0 +1,56 @@
+use Test;
+BEGIN { plan tests => 9 }
+
+use XML::XPath;
+ok(1);
+
+my $xp = XML::XPath->new(ioref => *DATA);
+ok($xp);
+
+my @nodes;
+
+# Don't set namespace prefixes - uses element context namespaces
+
+@nodes = $xp->findnodes('//foo:foo'); # should find foobar.com foos
+ok(@nodes, 3);
+
+@nodes = $xp->findnodes('//goo:foo'); # should find no foos
+ok(@nodes, 0);
+
+@nodes = $xp->findnodes('//foo'); # should find default NS foos
+ok(@nodes, 2);
+
+# Set namespace mappings.
+
+$xp->set_namespace("foo" => "flubber.example.com");
+$xp->set_namespace("goo" => "foobar.example.com");
+
+# warn "TEST 6\n";
+@nodes = $xp->findnodes('//foo:foo'); # should find flubber.com foos
+# warn "found: ", scalar @nodes, "\n";
+ok(@nodes, 2);
+
+@nodes = $xp->findnodes('//goo:foo'); # should find foobar.com foos
+ok(@nodes, 3);
+
+@nodes = $xp->findnodes('//foo'); # should find default NS foos
+ok(@nodes, 2);
+
+ok($xp->findvalue('//attr:node/@attr:findme'), 'someval');
+
+__DATA__
+<xml xmlns:foo="foobar.example.com"
+ xmlns="flubber.example.com">
+ <foo>
+ <bar/>
+ <foo/>
+ </foo>
+ <foo:foo>
+ <foo:foo/>
+ <foo:bar/>
+ <foo:bar/>
+ <foo:foo/>
+ </foo:foo>
+ <attr:node xmlns:attr="attribute.example.com"
+ attr:findme="someval"/>
+</xml>
diff --git a/t/25scope.t b/t/25scope.t
new file mode 100644
index 0000000..df58f0b
--- /dev/null
+++ b/t/25scope.t
@@ -0,0 +1,27 @@
+use Test;
+BEGIN { plan tests => 4 }
+
+use XML::XPath;
+ok(1);
+
+eval
+{
+ # Removing the 'my' makes this work?!?
+ my $xp = XML::XPath->new(xml => '<test/>');
+ ok($xp);
+
+ $xp->findnodes('/test');
+
+ ok(1);
+
+ die "This should be caught\n";
+
+};
+
+if ($@)
+{
+ ok(1);
+}
+else {
+ ok(0);
+}
diff --git a/t/26predicate.t b/t/26predicate.t
new file mode 100644
index 0000000..8312c0a
--- /dev/null
+++ b/t/26predicate.t
@@ -0,0 +1,26 @@
+use Test;
+BEGIN { plan tests => 4 }
+
+use XML::XPath;
+ok(1);
+
+my $xp = XML::XPath->new(ioref => *DATA);
+ok($xp);
+
+my @bbb = $xp->findnodes('//a/b[2]');
+ok(@bbb, 2);
+
+@bbb = $xp->findnodes('(//a/b)[2]');
+ok(@bbb, 1);
+
+__DATA__
+<xml>
+ <a>
+ <b>some 1</b>
+ <b>value 1</b>
+ </a>
+ <a>
+ <b>some 2</b>
+ <b>value 2</b>
+ </a>
+</xml>
diff --git a/t/27asxml.t b/t/27asxml.t
new file mode 100644
index 0000000..d2a887c
--- /dev/null
+++ b/t/27asxml.t
@@ -0,0 +1,13 @@
+use Test;
+BEGIN { plan tests => 3 }
+
+use XML::XPath;
+ok(1);
+
+my $parser = XML::XPath::Parser->new();
+ok($parser);
+
+my $path = $parser->parse('/foo[position() < 1]/bar[$variable = 3]');
+ok($path);
+
+# warn("Path: ", $path->as_xml(), "\n");
diff --git a/t/28ancestor2.t b/t/28ancestor2.t
new file mode 100644
index 0000000..1b90f15
--- /dev/null
+++ b/t/28ancestor2.t
@@ -0,0 +1,37 @@
+use Test;
+BEGIN { plan tests => 5 }
+
+use XML::XPath;
+ok(1);
+
+my $xp = XML::XPath->new(ioref => *DATA);
+ok($xp);
+
+my @nodes;
+@nodes = $xp->findnodes('//Footnote');
+ok(@nodes, 1);
+
+my $footnote = $nodes[0];
+
+@nodes = $footnote->findnodes('ancestor::*');
+ok(@nodes, 3);
+
+@nodes = $footnote->findnodes('ancestor::text:footnote');
+ok(@nodes, 1);
+
+__DATA__
+<foo xmlns:text="http://example.com/text">
+<text:footnote text:id="ftn2">
+<text:footnote-citation>2</text:footnote-citation>
+<text:footnote-body>
+<Footnote style="font-size: 10pt; margin-left: 0.499cm;
+margin-right: 0cm; text-indent: -0.499cm; font-family: ; ">AxKit
+is very flexible in how it lets you transform the XML on the
+server, and there are many modules you can plug in to AxKit to
+allow you to do these transformations. For this reason, the AxKit
+installation does not mandate any particular modules to use,
+instead it will simply suggest modules that might help when you
+install AxKit.</Footnote>
+</text:footnote-body>
+</text:footnote>
+</foo>
diff --git a/t/29desc_with_predicate.t b/t/29desc_with_predicate.t
new file mode 100644
index 0000000..b6675ba
--- /dev/null
+++ b/t/29desc_with_predicate.t
@@ -0,0 +1,21 @@
+use Test;
+BEGIN { plan tests => 4 }
+
+use XML::XPath;
+ok(1);
+
+my $xp = XML::XPath->new(ioref => *DATA);
+ok($xp);
+
+my @bbb = $xp->findnodes('/descendant::BBB[1]');
+ok(@bbb, 1);
+ok($bbb[0]->string_value, "OK");
+
+__DATA__
+<AAA>
+<BBB>OK</BBB>
+<CCC/>
+<BBB/>
+<DDD><BBB/></DDD>
+<CCC><DDD><BBB/><BBB>NOT OK</BBB></DDD></CCC>
+</AAA>
diff --git a/t/30lang.t b/t/30lang.t
new file mode 100644
index 0000000..a8c5dc6
--- /dev/null
+++ b/t/30lang.t
@@ -0,0 +1,20 @@
+use Test;
+BEGIN { plan tests => 4 }
+
+use XML::XPath;
+ok(1);
+
+my $xp = XML::XPath->new(ioref => *DATA);
+ok($xp);
+
+my @en = $xp->findnodes('//*[lang("en")]');
+ok(@en, 2);
+
+my @de = $xp->findnodes('//content[lang("de")]');
+ok(@de, 1);
+
+__DATA__
+<page xml:lang="en">
+ <content>Here we go...</content>
+ <content xml:lang="de">und hier deutschsprachiger Text :-)</content>
+</page>
diff --git a/t/insert.t b/t/insert.t
new file mode 100644
index 0000000..d9b0e59
--- /dev/null
+++ b/t/insert.t
@@ -0,0 +1,53 @@
+#!/usr/bin/perl
+
+use Test;
+BEGIN { plan tests => 8 }
+
+use XML::XPath;
+use XML::XPath::Node::Comment;
+#$XML::XPath::SafeMode = 1;
+
+ok(1);
+my $xp = XML::XPath->new(ioref => *DATA);
+ok($xp);
+
+my ($root) = $xp->findnodes('/');
+
+ok($root);
+
+($root) = $root->getChildNodes;
+my @nodes = $root->findnodes('//Cart');
+
+ok(@nodes, 2);
+
+my $comment = XML::XPath::Node::Comment->new("Before Comment");
+
+$root->insertBefore($comment, $nodes[0]);
+
+my $other_comment = XML::XPath::Node::Comment->new("After Comment");
+
+$root->insertAfter($other_comment, $nodes[0]);
+
+@nodes = $xp->findnodes('/Shop/node()');
+
+# foreach (@nodes) {
+# print STDERR $_->toString;
+# }
+
+ok($nodes[1]->isCommentNode);
+ok($nodes[3]->isCommentNode);
+
+my ($before) = $xp->findnodes('/Shop/comment()[contains( string() , "Before")]');
+ok($before->get_pos, 1);
+
+my ($after) = $xp->findnodes('/Shop/comment()[contains( string() , "After")]');
+ok($after->get_pos, 3);
+
+
+__DATA__
+<Shop id="mod3838" hello="you">
+<Cart id="1" crap="crap">
+ <Item id="11" crap="crap"/>
+</Cart>
+<Cart id="2" crap="crap"/>
+</Shop>
diff --git a/t/rdf.t b/t/rdf.t
new file mode 100644
index 0000000..a477a03
--- /dev/null
+++ b/t/rdf.t
@@ -0,0 +1,59 @@
+use Test;
+BEGIN { plan tests => 5 }
+
+use XML::XPath;
+
+#$XML::XPath::Debug = 1;
+#$XML::XPath::SafeMode = 1;
+
+my $xp = XML::XPath->new(ioref => *DATA);
+ok($xp);
+
+my $nodeset = $xp->find('/rdf:RDF/channel//@rdf:*');
+ok($nodeset);
+
+ok($nodeset->size);
+
+ok(4);
+ok(5);
+
+__DATA__
+<?xml version="1.0"?>
+<rdf:RDF
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ xmlns="http://purl.org/rss/1.0/"
+>
+
+ <channel rdf:about="http://meerkat.oreillynet.com/?_fl=rss1.0">
+ <title>Meerkat</title>
+ <link>http://meerkat.oreillynet.com</link>
+ <description>Meerkat: An Open Wire Service</description>
+ </channel>
+
+ <image
+rdf:about="http://meerkat.oreillynet.com/icons/meerkat-powered.jpg">
+ <inchannel rdf:resource="http://meerkat.oreillynet.com/?_fl=rss1.0" />
+ <title>Meerkat Powered!</title>
+ <url>http://meerkat.oreillynet.com/icons/meerkat-powered.jpg</url>
+ <link>http://meerkat.oreillynet.com</link>
+ </image>
+
+ <item rdf:about="http://c.moreover.com/click/here.pl?r123" position="1">
+ <inchannel rdf:resource="http://meerkat.oreillynet.com/?_fl=rss1.0" />
+ <title>XML: A Disruptive Technology</title>
+ <link>http://c.moreover.com/click/here.pl?r123</link>
+ <description>
+ XML is placing increasingly heavy loads on the existing technical
+ infrastructure of the Internet.
+ </description>
+ </item>
+
+ <textinput rdf:about="http://search.xml.com">
+ <inchannel rdf:resource="http://meerkat.oreillynet.com/?_fl=rss1.0" />
+ <title>Search XML.com</title>
+ <description>Search XML.com's XML collection</description>
+ <name>s</name>
+ <link>http://search.xml.com</link>
+ </textinput>
+
+</rdf:RDF>
diff --git a/t/remove.t b/t/remove.t
new file mode 100644
index 0000000..ac09453
--- /dev/null
+++ b/t/remove.t
@@ -0,0 +1,44 @@
+#!/usr/bin/perl
+
+use Test;
+BEGIN { plan tests => 7 }
+
+use XML::XPath;
+use XML::XPath::XMLParser;
+$XML::XPath::SafeMode = 1;
+
+ok(1);
+my $xp = XML::XPath->new(ioref => *DATA);
+ok($xp);
+
+my ($root) = $xp->findnodes('/');
+
+ok($root);
+
+($root) = $root->getChildNodes;
+my @nodes = $xp->findnodes('//Cart',$root);
+
+ok(@nodes, 2);
+
+$root->removeChild($nodes[0]);
+
+@nodes = $xp->findnodes('//Cart', $root);
+ok(@nodes, 1);
+
+my $cart = $nodes[0];
+
+@nodes = $xp->findnodes('//Cart/@*', $root);
+ok(@nodes, 2);
+
+$cart->removeAttribute('crap');
+@nodes = $xp->findnodes('//Cart/@*', $root);
+
+ok(@nodes, 1);
+
+__DATA__
+<Shop id="mod3838" hello="you">
+<Cart id="1" crap="crap">
+ <Item id="11" crap="crap"/>
+</Cart>
+<Cart id="2" crap="crap"/>
+</Shop>
diff --git a/t/stress.t b/t/stress.t
new file mode 100644
index 0000000..1f9b351
--- /dev/null
+++ b/t/stress.t
@@ -0,0 +1,57 @@
+# $Id: stress.t,v 1.3 2000/04/17 17:08:58 matt Exp $
+
+print "1..7\n";
+my $x; $x++;
+use XML::XPath;
+use XML::XPath::Parser;
+
+my $xp = XML::XPath->new( filename => 'examples/test.xml' );
+
+print "ok $x\n" if $xp;
+print "not ok $x\n" unless $xp;
+$x++;
+
+my $pp = XML::XPath::Parser->new();
+
+print "ok $x\n" if $pp;
+print "not ok $x\n" unless $pp;
+$x++;
+
+# test path parse time
+for (1..5000) {
+ $pp->parse('//project/wednesday');
+}
+
+print "ok $x\n" if $pp;
+print "not ok $x\n" unless $pp;
+$x++;
+
+my $parser = XML::XPath::XMLParser->new(
+ filename => 'examples/test.xml'
+ );
+
+print "ok $x\n" if $parser;
+print "not ok $x\n" unless $parser;
+$x++;
+
+my $root = $parser->parse;
+
+print "ok $x\n" if $root;
+print "not ok $x\n" unless $root;
+$x++;
+
+# test evaluation time
+my $path = $pp->parse('/timesheet/projects/project/wednesday');
+
+print "ok $x\n" if $path;
+print "not ok $x\n" unless $path;
+$x++;
+
+for (1..1000) {
+ $path->evaluate($root);
+}
+
+print "ok $x\n";
+$x++;
+
+