summaryrefslogtreecommitdiff
path: root/test/rexml/test_xpathtext.rb
diff options
context:
space:
mode:
authorkou <kou@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-09-17 13:14:14 +0000
committerkou <kou@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-09-17 13:14:14 +0000
commit91ed484f92040e5c2006a3a00ec77a54d552cf37 (patch)
tree03fd6677a85aaad516d0c9464b1273ea107231b7 /test/rexml/test_xpathtext.rb
parent045491d5be06b615d66d3f66cca2b5d2bc3c1929 (diff)
* test/rexml/: import REXML tests from
http://www.germane-software.com/repos/rexml/trunk/test/. Many tests are failed temporary. I'll fix them quickly. Sorry. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29282 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/rexml/test_xpathtext.rb')
-rw-r--r--test/rexml/test_xpathtext.rb72
1 files changed, 72 insertions, 0 deletions
diff --git a/test/rexml/test_xpathtext.rb b/test/rexml/test_xpathtext.rb
new file mode 100644
index 0000000..0ae48ac
--- /dev/null
+++ b/test/rexml/test_xpathtext.rb
@@ -0,0 +1,72 @@
+require 'test/unit'
+require 'rexml/document'
+require 'rexml/element'
+require 'rexml/xpath'
+
+class XpathTestCase < Test::Unit::TestCase
+ def setup
+ @doc = REXML::Document.new
+ end
+
+ def tear_down
+ end
+
+ def test_text_as_element
+ node1 = REXML::Element.new('a', @doc)
+ node2 = REXML::Element.new('b', node1)
+ textnode = REXML::Text.new('test', false, node2)
+ assert_equal(1, @doc.elements.size, "doc owns 1 element node1")
+ assert_same(node1, @doc.elements[1], "doc owns 1 element node1")
+ assert_equal(1, node1.elements.size, "node1 owns 1 element node2")
+ assert_same(node2, node1.elements[1], "node1 owns 1 element node2")
+ assert_equal(1, node2.size, "node2 owns 1 text element")
+ end
+
+ def test_text_in_xpath_query
+ node1 = REXML::Element.new('a', @doc)
+ node2 = REXML::Element.new('b', node1)
+ textnode = REXML::Text.new('test', false, node2)
+ textnode.parent = node2 # should be unnecessary
+ nodes = @doc.get_elements('//b')
+ assert_equal(1, nodes.size, "document has one element")
+ # why doesn't this query work right?
+ nodes = REXML::XPath.match(@doc, '//text()')
+ assert_equal(1, nodes.size, "//text() should yield one Text element")
+ assert_equal(REXML::Text, nodes[0].class)
+ end
+
+ def test_comment_in_xpath_query
+ node1 = REXML::Element.new('a', @doc)
+ node2 = REXML::Element.new('b', node1)
+ commentnode = REXML::Comment.new('test', node2)
+ nodes = REXML::XPath.match(@doc, '//comment()')
+ assert_equal(1, nodes.size, "//comment() should yield one Comment element")
+ assert_same commentnode, nodes[0]
+ end
+
+ def test_parentage
+ node1 = REXML::Element.new('a', @doc)
+ assert_same(@doc, node1.parent, "node1 parent is document")
+ node2 = REXML::Element.new('b', node1)
+ assert_same(node1, node2.parent, "node2 parent is node1")
+ textnode = REXML::Text.new('test', false, node2)
+ # why isn't the text's parent node2?
+ # Also look at Comment, etc.
+ assert_same(node2, textnode.parent)
+ comment = REXML::Comment.new('Test comment', node2)
+ assert_same(node2, comment.parent)
+ end
+
+ def test_ancestors
+ node1 = REXML::Element.new('a', @doc)
+ node2 = REXML::Element.new('b', node1)
+ textnode = REXML::Text.new('test', false, node2)
+ #textnode.parent = node2 # should be unnecessary
+ assert_same node2, textnode.parent
+ nodes = @doc.get_elements('//b/ancestor::*')
+ assert_equal(1, nodes.size, "<b> has one element ancestor")
+ nodes = @doc.get_elements('//b/ancestor::node()')
+ assert_equal(2, nodes.size, "<b> has two node ancestors")
+ assert nodes[1].kind_of?(REXML::Document)
+ end
+end