2015-12-16 00:07:31 -05:00
|
|
|
# frozen_string_literal: false
|
2010-09-17 09:14:14 -04:00
|
|
|
require 'test/unit'
|
|
|
|
require 'rexml/document'
|
|
|
|
|
2014-05-27 08:07:40 -04:00
|
|
|
module REXMLTests
|
2014-05-27 09:10:55 -04:00
|
|
|
class TestXPathAttribute < Test::Unit::TestCase
|
|
|
|
def setup
|
|
|
|
@xml = <<-XML
|
2014-02-22 09:03:25 -05:00
|
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
|
|
<root>
|
|
|
|
<child name="one">child1</child>
|
|
|
|
<child name="two">child2</child>
|
|
|
|
<child name="three">child3</child>
|
|
|
|
</root>
|
2014-05-27 09:10:55 -04:00
|
|
|
XML
|
|
|
|
@document = REXML::Document.new(@xml)
|
|
|
|
end
|
2011-05-15 07:55:52 -04:00
|
|
|
|
2014-05-27 09:10:55 -04:00
|
|
|
def test_elements
|
|
|
|
root = @document.elements["root"]
|
|
|
|
second_child = root.elements["child[@name='two']"]
|
|
|
|
assert_equal("child2", second_child.text)
|
|
|
|
end
|
2011-05-15 07:55:52 -04:00
|
|
|
|
2014-05-27 09:10:55 -04:00
|
|
|
def test_xpath_each
|
|
|
|
children = REXML::XPath.each(@document, "/root/child[@name='two']")
|
|
|
|
assert_equal(["child2"], children.collect(&:text))
|
|
|
|
end
|
2010-09-17 09:14:14 -04:00
|
|
|
end
|
|
|
|
end
|