summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorkou <kou@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-09-17 13:46:56 +0000
committerkou <kou@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-09-17 13:46:56 +0000
commit2a15d25a5941301b5be6bc29eb4ac97d5aafe3dc (patch)
tree32ed30c63502d98c54555945ded41a4d0161c662 /test
parent146bf4fdafefc780d65f20c983d65f9cbe3bfe2d (diff)
* test/rexml/: untabify.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29285 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/rexml/test_attributes.rb288
-rw-r--r--test/rexml/test_attributes_mixin.rb4
-rw-r--r--test/rexml/test_contrib.rb698
-rw-r--r--test/rexml/test_core.rb52
-rw-r--r--test/rexml/test_elements.rb168
-rw-r--r--test/rexml/test_encoding.rb2
-rw-r--r--test/rexml/test_encoding_2.rb80
-rw-r--r--test/rexml/test_entity.rb248
-rw-r--r--test/rexml/test_functions.rb388
-rw-r--r--test/rexml/test_functions_number.rb2
-rw-r--r--test/rexml/test_jaxen.rb38
-rw-r--r--test/rexml/test_light.rb162
-rw-r--r--test/rexml/test_lightparser.rb12
-rw-r--r--test/rexml/test_listener.rb184
-rw-r--r--test/rexml/test_martin_fowler.rb29
-rw-r--r--test/rexml/test_preceding_sibling.rb2
-rw-r--r--test/rexml/test_stream.rb2
-rw-r--r--test/rexml/test_xpath.rb1146
-rw-r--r--test/rexml/test_xpath_attribute_query.rb56
-rw-r--r--test/rexml/test_xpath_msw.rb14
-rw-r--r--test/rexml/test_xpath_pred.rb2
-rw-r--r--test/rexml/test_xpathtext.rb6
22 files changed, 1787 insertions, 1796 deletions
diff --git a/test/rexml/test_attributes.rb b/test/rexml/test_attributes.rb
index 56b4557..51a7774 100644
--- a/test/rexml/test_attributes.rb
+++ b/test/rexml/test_attributes.rb
@@ -2,152 +2,152 @@ require 'test/unit/testcase'
require 'rexml/document'
class AttributesTester < Test::Unit::TestCase
- include REXML
- def test_accessor
- doc = Document.new("<a xmlns:foo='a' xmlns:bar='b' foo:att='1' bar:att='2' att='3'/>")
- assert_equal '3', doc.root.attributes['att']
- assert_equal '2', doc.root.attributes['bar:att']
- doc.root.attributes['att'] = 5
- assert_equal '5', doc.root.attributes['att']
- end
-
- def test_each_attribute
- doc = Document.new('<a x="1" y="2"/>')
- doc.root.attributes.each_attribute {|attr|
- if attr.expanded_name == 'x'
- assert_equal '1', attr.value
- elsif attr.expanded_name == 'y'
- assert_equal '2', attr.value
- else
- assert_fail "No such attribute!!"
- end
- }
- end
-
- def test_each
- doc = Document.new('<a x="1" y="2"/>')
- doc.root.attributes.each {|name, value|
- if name == 'x'
- assert_equal '1', value
- elsif name == 'y'
- assert_equal '2', value
- else
- assert_fail "No such attribute!!"
- end
- }
- end
-
- def test_get_attribute
- doc = Document.new('<a xmlns:x="a" x:foo="1" foo="2" bar="3"/>')
- assert_equal '2', doc.root.attributes.get_attribute("foo").value
- assert_equal '1', doc.root.attributes.get_attribute("x:foo").value
- end
-
- def test_size
- doc = Document.new("<a xmlns:foo='a' x='1' y='2' foo:x='3'/>")
- assert_equal 4, doc.root.attributes.length
- end
-
- def test_setter
- doc = Document.new("<a xmlns:x='a' x:foo='1' foo='3'/>")
- doc.root.attributes['y:foo'] = '2'
- assert_equal '2', doc.root.attributes['y:foo']
- doc.root.attributes['foo'] = '4'
- assert_equal '4', doc.root.attributes['foo']
- doc.root.attributes['x:foo'] = nil
- assert_equal 3, doc.root.attributes.size
- end
-
- def test_delete
- doc = Document.new("<a xmlns:y='a' xmlns:x='b' xmlns:z='c' y:foo='0' x:foo='1' foo='3' z:foo='4'/>")
- doc.root.attributes.delete 'foo'
- assert_equal 6, doc.root.attributes.size
- assert_equal '1', doc.root.attributes['x:foo']
-
- doc.root.attributes.delete 'x:foo'
- assert_equal 5, doc.root.attributes.size
-
- attr = doc.root.attributes.get_attribute('y:foo')
- doc.root.attributes.delete attr
- assert_equal 4, doc.root.attributes.size
-
- assert_equal '4', doc.root.attributes['z:foo']
- end
-
- def test_prefixes
- doc = Document.new("<a xmlns='foo' xmlns:x='bar' xmlns:y='twee' z='glorp' x:k='gru'/>")
- prefixes = doc.root.attributes.prefixes
- assert_equal 2, prefixes.size
- assert_equal 0, (prefixes - ['x', 'y']).size
- end
-
- # Contributed by Mike Stok
+ include REXML
+ def test_accessor
+ doc = Document.new("<a xmlns:foo='a' xmlns:bar='b' foo:att='1' bar:att='2' att='3'/>")
+ assert_equal '3', doc.root.attributes['att']
+ assert_equal '2', doc.root.attributes['bar:att']
+ doc.root.attributes['att'] = 5
+ assert_equal '5', doc.root.attributes['att']
+ end
+
+ def test_each_attribute
+ doc = Document.new('<a x="1" y="2"/>')
+ doc.root.attributes.each_attribute {|attr|
+ if attr.expanded_name == 'x'
+ assert_equal '1', attr.value
+ elsif attr.expanded_name == 'y'
+ assert_equal '2', attr.value
+ else
+ assert_fail "No such attribute!!"
+ end
+ }
+ end
+
+ def test_each
+ doc = Document.new('<a x="1" y="2"/>')
+ doc.root.attributes.each {|name, value|
+ if name == 'x'
+ assert_equal '1', value
+ elsif name == 'y'
+ assert_equal '2', value
+ else
+ assert_fail "No such attribute!!"
+ end
+ }
+ end
+
+ def test_get_attribute
+ doc = Document.new('<a xmlns:x="a" x:foo="1" foo="2" bar="3"/>')
+ assert_equal '2', doc.root.attributes.get_attribute("foo").value
+ assert_equal '1', doc.root.attributes.get_attribute("x:foo").value
+ end
+
+ def test_size
+ doc = Document.new("<a xmlns:foo='a' x='1' y='2' foo:x='3'/>")
+ assert_equal 4, doc.root.attributes.length
+ end
+
+ def test_setter
+ doc = Document.new("<a xmlns:x='a' x:foo='1' foo='3'/>")
+ doc.root.attributes['y:foo'] = '2'
+ assert_equal '2', doc.root.attributes['y:foo']
+ doc.root.attributes['foo'] = '4'
+ assert_equal '4', doc.root.attributes['foo']
+ doc.root.attributes['x:foo'] = nil
+ assert_equal 3, doc.root.attributes.size
+ end
+
+ def test_delete
+ doc = Document.new("<a xmlns:y='a' xmlns:x='b' xmlns:z='c' y:foo='0' x:foo='1' foo='3' z:foo='4'/>")
+ doc.root.attributes.delete 'foo'
+ assert_equal 6, doc.root.attributes.size
+ assert_equal '1', doc.root.attributes['x:foo']
+
+ doc.root.attributes.delete 'x:foo'
+ assert_equal 5, doc.root.attributes.size
+
+ attr = doc.root.attributes.get_attribute('y:foo')
+ doc.root.attributes.delete attr
+ assert_equal 4, doc.root.attributes.size
+
+ assert_equal '4', doc.root.attributes['z:foo']
+ end
+
+ def test_prefixes
+ doc = Document.new("<a xmlns='foo' xmlns:x='bar' xmlns:y='twee' z='glorp' x:k='gru'/>")
+ prefixes = doc.root.attributes.prefixes
+ assert_equal 2, prefixes.size
+ assert_equal 0, (prefixes - ['x', 'y']).size
+ end
+
+ # Contributed by Mike Stok
def test_values_with_apostrophes
doc = Document.new(%q#<tag h1="1'2'" h2='1"2'/>#)
- s = doc.to_s
- assert(s =~ /h1='1&apos;2&apos;'/)
- assert(s =~ /h2='1"2'/)
- end
-
- # Submitted by Kou
- def test_namespace_conflict
- assert_raise( ParseException,
- "Declaring two attributes with the same namespace should be an error" ) do
- REXML::Document.new <<-XML
- <x xmlns:n1="http://www.w3.org"
- xmlns:n2="http://www.w3.org" >
- <bad n1:a="1" n2:a="2" />
- </x>
- XML
- end
-
- REXML::Document.new("<a xmlns:a='a' xmlns:b='a'></a>")
- end
-
- # Submitted by Kou
- def test_attribute_deletion
- e = REXML::Element.new
- e.add_namespace("a", "http://a/")
- e.add_namespace("b", "http://b/")
- e.add_attributes({"c" => "cc", "a:c" => "cC", "b:c" => "CC"})
-
- e.attributes.delete("c")
- assert_nil(e.attributes.get_attribute("c"))
-
- before_size = e.attributes.size
- e.attributes.delete("c")
- assert_nil(e.attributes.get_attribute("c"))
- assert_equal(before_size, e.attributes.size)
-
- e.attributes.delete(e.attributes.get_attribute("a:c"))
- assert_nil(e.attributes.get_attribute("a:c"))
-
- e.attributes.delete("b:c")
- assert_nil(e.attributes.get_attribute("b:c"))
-
- before_size = e.attributes.size
- e.attributes.delete(e.attributes.get_attribute("b:c"))
- assert_nil(e.attributes.get_attribute("b:c"))
- assert_equal(before_size, e.attributes.size)
-
- before_size = e.attributes.size
- e.attributes.delete("c")
- assert_nil(e.attributes.get_attribute("c"))
- assert_equal(before_size, e.attributes.size)
-
- e.add_attribute("c", "cc")
-
- e.attributes.delete(e.attributes.get_attribute("c"))
- assert_nil(e.attributes.get_attribute("c"))
- end
-
- # Submitted by Kou
- def test_element_usage
- attr = Attribute.new("name", "value")
- elem = Element.new("elem")
- a = Attribute.new(attr, elem)
- assert_equal(elem, a.element)
- end
+ s = doc.to_s
+ assert(s =~ /h1='1&apos;2&apos;'/)
+ assert(s =~ /h2='1"2'/)
+ end
+
+ # Submitted by Kou
+ def test_namespace_conflict
+ assert_raise( ParseException,
+ "Declaring two attributes with the same namespace should be an error" ) do
+ REXML::Document.new <<-XML
+ <x xmlns:n1="http://www.w3.org"
+ xmlns:n2="http://www.w3.org" >
+ <bad n1:a="1" n2:a="2" />
+ </x>
+ XML
+ end
+
+ REXML::Document.new("<a xmlns:a='a' xmlns:b='a'></a>")
+ end
+
+ # Submitted by Kou
+ def test_attribute_deletion
+ e = REXML::Element.new
+ e.add_namespace("a", "http://a/")
+ e.add_namespace("b", "http://b/")
+ e.add_attributes({"c" => "cc", "a:c" => "cC", "b:c" => "CC"})
+
+ e.attributes.delete("c")
+ assert_nil(e.attributes.get_attribute("c"))
+
+ before_size = e.attributes.size
+ e.attributes.delete("c")
+ assert_nil(e.attributes.get_attribute("c"))
+ assert_equal(before_size, e.attributes.size)
+
+ e.attributes.delete(e.attributes.get_attribute("a:c"))
+ assert_nil(e.attributes.get_attribute("a:c"))
+
+ e.attributes.delete("b:c")
+ assert_nil(e.attributes.get_attribute("b:c"))
+
+ before_size = e.attributes.size
+ e.attributes.delete(e.attributes.get_attribute("b:c"))
+ assert_nil(e.attributes.get_attribute("b:c"))
+ assert_equal(before_size, e.attributes.size)
+
+ before_size = e.attributes.size
+ e.attributes.delete("c")
+ assert_nil(e.attributes.get_attribute("c"))
+ assert_equal(before_size, e.attributes.size)
+
+ e.add_attribute("c", "cc")
+
+ e.attributes.delete(e.attributes.get_attribute("c"))
+ assert_nil(e.attributes.get_attribute("c"))
+ end
+
+ # Submitted by Kou
+ def test_element_usage
+ attr = Attribute.new("name", "value")
+ elem = Element.new("elem")
+ a = Attribute.new(attr, elem)
+ assert_equal(elem, a.element)
+ end
def attr_test(attr_name,attr_value)
a1 = REXML::Attribute.new(attr_name,attr_value)
diff --git a/test/rexml/test_attributes_mixin.rb b/test/rexml/test_attributes_mixin.rb
index 44ab4f0..50899d0 100644
--- a/test/rexml/test_attributes_mixin.rb
+++ b/test/rexml/test_attributes_mixin.rb
@@ -5,7 +5,6 @@ require 'test/unit'
require 'rexml/document'
class TestAttributes < Test::Unit::TestCase
-
def setup
@ns_a = "urn:x-test:a"
@ns_b = "urn:x-test:b"
@@ -21,7 +20,7 @@ class TestAttributes < Test::Unit::TestCase
XMLEND
@attributes = REXML::Document.new(element_string).root.attributes
end
-
+
def test_get_attribute_ns
assert_equal("1", @attributes.get_attribute_ns("", "a").value)
assert_equal("2", @attributes.get_attribute_ns("", "b").value)
@@ -30,5 +29,4 @@ class TestAttributes < Test::Unit::TestCase
assert_equal("5", @attributes.get_attribute_ns(@ns_a, "e").value)
assert_equal("6", @attributes.get_attribute_ns(@ns_b, "f").value)
end
-
end
diff --git a/test/rexml/test_contrib.rb b/test/rexml/test_contrib.rb
index 54ec642..785169b 100644
--- a/test/rexml/test_contrib.rb
+++ b/test/rexml/test_contrib.rb
@@ -8,9 +8,9 @@ require "rexml/formatters/default"
class ContribTester < Test::Unit::TestCase
include REXMLTestUtils
- include REXML
+ include REXML
-XML_STRING_01 = <<DELIMITER
+ XML_STRING_01 = <<DELIMITER
<?xml version="1.0" encoding="UTF-8"?>
<biblio>
<entry type="Book">
@@ -31,7 +31,7 @@ XML_STRING_01 = <<DELIMITER
</biblio>
DELIMITER
-XML_STRING_02 = <<DELIMITER
+ XML_STRING_02 = <<DELIMITER
<biblio>
<entry type="Book">
<language>english</language>
@@ -51,129 +51,129 @@ XML_STRING_02 = <<DELIMITER
</biblio>
DELIMITER
- # Tobias Reif <tobiasreif@pinkjuice.com>
- def test_bad_doctype_Tobias
- source = <<-EOF
- <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN"
- "http://www.w3.org/TR/SVG/DTD/svg10.dtd"
- [
- <!-- <!ENTITY % fast-slow "0 0 .5 1">-->
- <!--<!ENTITY % slow-fast ".5 0 1 1">-->
- <!ENTITY hover_ani
- '<animateTransform attributeName="transform"
- type="scale" restart="whenNotActive" values="1;0.96"
- dur="0.5s" calcMode="spline" keySplines="0 0 .5 1"
- fill="freeze" begin="mouseover"/>
- <animateTransform attributeName="transform"
- type="scale" restart="whenNotActive" values="0.96;1"
- dur="0.5s" calcMode="spline" keySplines=".5 0 1 1"
- fill="freeze" begin="mouseover+0.5s"/>'
- >
- ]
- >
- EOF
- doc = REXML::Document.new source
- doc.write(out="")
- assert(out[/>'>/] != nil, "Couldn't find >'>")
- assert(out[/\]>/] != nil, "Couldn't find ]>")
- end
-
- # Peter Verhage
- def test_namespace_Peter
- source = <<-EOF
- <?xml version="1.0"?>
- <config:myprog-config xmlns:config="http://someurl/program/version">
- <!-- main options -->
- <config:main>
- <config:parameter name="name" value="value"/>
- </config:main>
- </config:myprog-config>
- EOF
- doc = REXML::Document.new source
- assert_equal "myprog-config", doc.root.name
- count = 0
- REXML::XPath.each(doc, "x:myprog-config/x:main/x:parameter",
- {"x"=>"http://someurl/program/version"}) { |element|
- assert_equal "name", element.attributes["name"]
- count += 1;
- }
- assert_equal 1, count
- assert_equal "myprog-config", doc.elements["config:myprog-config"].name
- end
-
- # Tobias Reif <tobiasreif@pinkjuice.com>
- def test_complex_xpath_Tobias
- source = <<-EOF
- <root>
- <foo>
- <bar style="baz"/>
- <blah style="baz"/>
- <blam style="baz"/>
- </foo>
- <wax>
- <fudge>
- <noodle/>
- </fudge>
- </wax>
- </root>
- EOF
- # elements that have child elements
- # but not grandchildren
- # and not children that don't have a style attribute
- # and not children that have a unique style attribute
- complex_path = "*[* "+
- "and not(*/node()) "+
- "and not(*[not(@style)]) "+
- "and not(*/@style != */@style)]"
- doc = REXML::Document.new source
- results = REXML::XPath.match( doc.root, complex_path )
- assert(results)
- assert_equal 1, results.size
- assert_equal "foo", results[0].name
- end
-
- # "Chris Morris" <chrismo@charter.net>
- def test_extra_newline_on_read_Chris
- text = 'test text'
- e = REXML::Element.new('Test')
- e.add_text(text)
+ # Tobias Reif <tobiasreif@pinkjuice.com>
+ def test_bad_doctype_Tobias
+ source = <<-EOF
+ <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN"
+ "http://www.w3.org/TR/SVG/DTD/svg10.dtd"
+ [
+ <!-- <!ENTITY % fast-slow "0 0 .5 1">-->
+ <!--<!ENTITY % slow-fast ".5 0 1 1">-->
+ <!ENTITY hover_ani
+ '<animateTransform attributeName="transform"
+ type="scale" restart="whenNotActive" values="1;0.96"
+ dur="0.5s" calcMode="spline" keySplines="0 0 .5 1"
+ fill="freeze" begin="mouseover"/>
+ <animateTransform attributeName="transform"
+ type="scale" restart="whenNotActive" values="0.96;1"
+ dur="0.5s" calcMode="spline" keySplines=".5 0 1 1"
+ fill="freeze" begin="mouseover+0.5s"/>'
+ >
+ ]
+ >
+ EOF
+ doc = REXML::Document.new source
+ doc.write(out="")
+ assert(out[/>'>/] != nil, "Couldn't find >'>")
+ assert(out[/\]>/] != nil, "Couldn't find ]>")
+ end
+
+ # Peter Verhage
+ def test_namespace_Peter
+ source = <<-EOF
+ <?xml version="1.0"?>
+ <config:myprog-config xmlns:config="http://someurl/program/version">
+ <!-- main options -->
+ <config:main>
+ <config:parameter name="name" value="value"/>
+ </config:main>
+ </config:myprog-config>
+ EOF
+ doc = REXML::Document.new source
+ assert_equal "myprog-config", doc.root.name
+ count = 0
+ REXML::XPath.each(doc, "x:myprog-config/x:main/x:parameter",
+ {"x"=>"http://someurl/program/version"}) { |element|
+ assert_equal "name", element.attributes["name"]
+ count += 1;
+ }
+ assert_equal 1, count
+ assert_equal "myprog-config", doc.elements["config:myprog-config"].name
+ end
+
+ # Tobias Reif <tobiasreif@pinkjuice.com>
+ def test_complex_xpath_Tobias
+ source = <<-EOF
+ <root>
+ <foo>
+ <bar style="baz"/>
+ <blah style="baz"/>
+ <blam style="baz"/>
+ </foo>
+ <wax>
+ <fudge>
+ <noodle/>
+ </fudge>
+ </wax>
+ </root>
+ EOF
+ # elements that have child elements
+ # but not grandchildren
+ # and not children that don't have a style attribute
+ # and not children that have a unique style attribute
+ complex_path = "*[* "+
+ "and not(*/node()) "+
+ "and not(*[not(@style)]) "+
+ "and not(*/@style != */@style)]"
+ doc = REXML::Document.new source
+ results = REXML::XPath.match( doc.root, complex_path )
+ assert(results)
+ assert_equal 1, results.size
+ assert_equal "foo", results[0].name
+ end
+
+ # "Chris Morris" <chrismo@charter.net>
+ def test_extra_newline_on_read_Chris
+ text = 'test text'
+ e = REXML::Element.new('Test')
+ e.add_text(text)
REXML::Formatters::Default.new.write(e,out="")
- doc = REXML::Document.new(out)
- outtext = doc.root.text
-
- assert_equal(text, outtext)
- end
-
- # Tobias Reif <tobiasreif@pinkjuice.com>
- def test_other_xpath_Tobias
- schema = <<-DELIM
- <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
- elementFormDefault="qualified">
- <xs:element name="rect">
- <xs:complexType>
- <xs:attribute name="width" type="xs:byte" use="required"/>
- <xs:attribute name="height" type="xs:byte" use="required"/>
- </xs:complexType>
- </xs:element>
- <xs:element name="svg">
- <xs:complexType>
- <xs:sequence>
- <xs:element ref="rect"/>
- </xs:sequence>
- </xs:complexType>
- </xs:element>
- </xs:schema>
- DELIM
-
- doc = REXML::Document.new schema
-
- result = REXML::XPath.first(doc.root, 'xs:element[descendant::xs:element[@ref]]')
- assert result
- assert_equal "svg", result.attributes['name']
- result = REXML::XPath.first(doc, 'element[descendant::element[@ref]]')
- assert_nil result
- end
+ doc = REXML::Document.new(out)
+ outtext = doc.root.text
+
+ assert_equal(text, outtext)
+ end
+
+ # Tobias Reif <tobiasreif@pinkjuice.com>
+ def test_other_xpath_Tobias
+ schema = <<-DELIM
+ <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ elementFormDefault="qualified">
+ <xs:element name="rect">
+ <xs:complexType>
+ <xs:attribute name="width" type="xs:byte" use="required"/>
+ <xs:attribute name="height" type="xs:byte" use="required"/>
+ </xs:complexType>
+ </xs:element>
+ <xs:element name="svg">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element ref="rect"/>
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+ </xs:schema>
+ DELIM
+
+ doc = REXML::Document.new schema
+
+ result = REXML::XPath.first(doc.root, 'xs:element[descendant::xs:element[@ref]]')
+ assert result
+ assert_equal "svg", result.attributes['name']
+ result = REXML::XPath.first(doc, 'element[descendant::element[@ref]]')
+ assert_nil result
+ end
#this first test succeeds, to check if stuff is set up correctly
def test_xpath_01_TobiasReif
@@ -228,8 +228,8 @@ DELIMITER
end
def test_umlaut
- koln_iso = "K\xf6ln"
- koln_utf = "K\xc3\xb6ln"
+ koln_iso = "K\xf6ln"
+ koln_utf = "K\xc3\xb6ln"
source_iso = "<?xml version='1.0' encoding='ISO-8859-1'?><test>#{koln_iso}</test>"
source_utf = "<?xml version='1.0' encoding='UTF-8'?><test>#{koln_utf}</test>"
@@ -240,16 +240,16 @@ DELIMITER
source_utf.force_encoding('utf-8')
end
- doc = REXML::Document.new(source_iso)
- assert_equal('ISO-8859-1', doc.xml_decl.encoding)
- assert_equal(koln_utf, doc.root.text)
- doc.write(out="")
- assert_equal(source_iso, out )
- doc.xml_decl.encoding = 'UTF-8'
- doc.write(out="")
- assert_equal(source_utf, out)
+ doc = REXML::Document.new(source_iso)
+ assert_equal('ISO-8859-1', doc.xml_decl.encoding)
+ assert_equal(koln_utf, doc.root.text)
+ doc.write(out="")
+ assert_equal(source_iso, out )
+ doc.xml_decl.encoding = 'UTF-8'
+ doc.write(out="")
+ assert_equal(source_utf, out)
- doc = Document.new <<-EOF
+ doc = Document.new <<-EOF
<?xml version="1.0" encoding="ISO-8859-1"?>
<intranet>
<position><aktuell datum="01-10-11">Technik</aktuell></position>
@@ -265,228 +265,228 @@ Die Technik ist das Rückgrat der meisten Geschäftsprozesse bei Home of the Brave
</nebenspalte>
</intranet>
EOF
- tn = XPath.first(doc, "//nebenspalte/text()[2]")
- expected_iso = "Nützliches von Flashern für Flasher."
+ tn = XPath.first(doc, "//nebenspalte/text()[2]")
+ expected_iso = "Nützliches von Flashern für Flasher."
expected_utf = expected_iso.unpack('C*').pack('U*')
if expected_utf.respond_to? :encode
- expected_iso.force_encoding("iso-8859-1")
- expected_utf.force_encoding(Encoding::UTF_8)
+ expected_iso.force_encoding("iso-8859-1")
+ expected_utf.force_encoding(Encoding::UTF_8)
end
- assert_equal(expected_utf, tn.to_s.strip)
+ assert_equal(expected_utf, tn.to_s.strip)
f = REXML::Formatters::Default.new
f.write( tn, Output.new(o = "", "ISO-8859-1") )
- assert_equal(expected_iso, o.strip)
+ assert_equal(expected_iso, o.strip)
- doc = Document.new File.new(fixture_path('xmlfile-bug.xml'))
- tn = XPath.first(doc, "//nebenspalte/text()[2]")
- assert_equal(expected_utf, tn.to_s.strip)
+ doc = Document.new File.new(fixture_path('xmlfile-bug.xml'))
+ tn = XPath.first(doc, "//nebenspalte/text()[2]")
+ assert_equal(expected_utf, tn.to_s.strip)
f.write( tn, Output.new(o = "", "ISO-8859-1") )
- assert_equal(expected_iso, o.strip)
+ assert_equal(expected_iso, o.strip)
end
- def test_element_cloning_namespace_Chris
- aDoc = REXML::Document.new '<h1 tpl:content="title" xmlns:tpl="1">Dummy title</h1>'
-
- anElement = anElement = aDoc.elements[1]
- elementAttrPrefix = anElement.attributes.get_attribute('content').prefix
-
- aClone = anElement.clone
- cloneAttrPrefix = aClone.attributes.get_attribute('content').prefix
-
- assert_equal( elementAttrPrefix , cloneAttrPrefix )
- end
-
- def test_namespaces_in_attlist_tobias
- in_string = File.open(fixture_path('foo.xml'), 'r') do |file|
- file.read
- end
-
- doc = Document.new in_string
-
- assert_nil XPath.first(doc,'//leg')
- assert_equal 'http://www.foo.com/human', doc.root.elements[1].namespace
- assert_equal 'human leg',
- XPath.first(doc, '//x:leg/text()', {'x'=>'http://www.foo.com/human'}).to_s
- end
-
- # Alun ap Rhisiart
- def test_less_than_in_element_content
- source = File.new(fixture_path('ProductionSupport.xml'))
- h = Hash.new
- doc = REXML::Document.new source
- doc.elements.each("//CommonError") { |el|
- h[el.elements['Key'].text] = 'okay'
- }
- assert(h.include?('MotorInsuranceContract(Object)>>#error:'))
- end
-
- # XPaths provided by Thomas Sawyer
- def test_various_xpath
- #@doc = REXML::Document.new('<r a="1"><p><c b="2"/></p></r>')
- doc = REXML::Document.new('<r a="1"><p><c b="2">3</c></p></r>')
-
- [['/r', REXML::Element],
- ['/r/p/c', REXML::Element],
- ['/r/attribute::a', Attribute],
- ['/r/@a', Attribute],
- ['/r/attribute::*', Attribute],
- ['/r/@*', Attribute],
- ['/r/p/c/attribute::b', Attribute],
- ['/r/p/c/@b', Attribute],
- ['/r/p/c/attribute::*', Attribute],
- ['/r/p/c/@*', Attribute],
- ['//c/attribute::b', Attribute],
- ['//c/@b', Attribute],
- ['//c/attribute::*', Attribute],
- ['//c/@*', Attribute],
- ['.//node()', REXML::Node ],
- ['.//node()[@a]', REXML::Element ],
- ['.//node()[@a="1"]', REXML::Element ],
- ['.//node()[@b]', REXML::Element ], # no show, why?
- ['.//node()[@b="2"]', REXML::Element ]
- ].each do |xpath,kind|
- begin
- REXML::XPath.each( doc, xpath ) do |what|
- assert_kind_of( kind, what, "\n\nWrong type (#{what.class}) returned for #{xpath} (expected #{kind.name})\n\n" )
- end
- rescue Exception
- puts "PATH WAS: #{xpath}"
- raise
- end
- end
-
- [
- ['/r', 'attribute::a', Attribute ],
- ['/r', '@a', Attribute ],
- ['/r', 'attribute::*', Attribute ],
- ['/r', '@*', Attribute ],
- ['/r/p/c', 'attribute::b', Attribute ],
- ['/r/p/c', '@b', Attribute ],
- ['/r/p/c', 'attribute::*', Attribute ],
- ['/r/p/c', '@*', Attribute ]
- ].each do |nodepath, xpath, kind|
- begin
- context = REXML::XPath.first(doc, nodepath)
- REXML::XPath.each( context, xpath ) do |what|
- assert_kind_of kind, what, "Wrong type (#{what.class}) returned for #{xpath} (expected #{kind.name})\n"
- end
- rescue Exception
- puts "PATH WAS: #{xpath}"
- raise
- end
- end
- end
-
- def test_entities_Holden_Glova
- document = <<-EOL
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE rubynet [
- <!ENTITY rbconfig.MAJOR "1">
- <!ENTITY rbconfig.MINOR "7">
- <!ENTITY rbconfig.TEENY "2">
- <!ENTITY rbconfig.ruby_version "&rbconfig.MAJOR;.&rbconfig.MINOR;">
- <!ENTITY rbconfig.arch "i386-freebsd5">
- <!ENTITY rbconfig.prefix "/usr/local">
- <!ENTITY rbconfig.libdir "&rbconfig.prefix;/lib">
- <!ENTITY rbconfig.includedir "&rbconfig.prefix;/include">
- <!ENTITY rbconfig.sitedir "&rbconfig.prefix;/lib/ruby/site_ruby">
- <!ENTITY rbconfig.sitelibdir "&rbconfig.sitedir;/&rbconfig.ruby_version;">
- <!ENTITY rbconfig.sitearchdir "&rbconfig.sitelibdir;/&rbconfig.arch;">
- ]>
- <rubynet>
- <pkg version="version1.0">
- <files>
- <file>
- <filename>uga.rb</filename>
- <mode>0444</mode>
- <path>&rbconfig.libdir;/rexml</path>
- <content encoding="xml">... the file here</content>
- </file>
- <file>
- <filename>booga.h</filename>
- <mode>0444</mode>
- <path>&rbconfig.includedir;</path>
- <content encoding="xml">... the file here</content>
- </file>
- <file>
- <filename>foo.so</filename>
- <mode>0555</mode>
- <path>&rbconfig.sitearchdir;/rexml</path>
- <content encoding="mime64">Li4uIHRoZSBmaWxlIGhlcmU=\n</content>
- </file>
- </files>
- </pkg>
- </rubynet>
- EOL
-
- file_xpath = '/rubynet/pkg/files/file'
-
- root = REXML::Document.new(document)
-
- root.elements.each(file_xpath) do |metadata|
- text = metadata.elements['path'].get_text.value
- assert text !~ /&rbconfig/, "'#{text}' failed"
- end
-
- #Error occurred in test_package_file_opens(TC_PackageInstall):
- # ArgumentError:
- #illegal access mode &rbconfig.prefix;/lib/rexml
- #
- #[synack@Evergreen] src $ ruby --version
- #ruby 1.6.7 (2002-03-01) [i686-linux-gnu]
- #
- #It looks like it expanded the first entity, but didn't reparse it for more
- #entities. possible bug - or have I mucked this up?
- end
-
- def test_whitespace_after_xml_decl
- d = Document.new <<EOL
+ def test_element_cloning_namespace_Chris
+ aDoc = REXML::Document.new '<h1 tpl:content="title" xmlns:tpl="1">Dummy title</h1>'
+
+ anElement = anElement = aDoc.elements[1]
+ elementAttrPrefix = anElement.attributes.get_attribute('content').prefix
+
+ aClone = anElement.clone
+ cloneAttrPrefix = aClone.attributes.get_attribute('content').prefix
+
+ assert_equal( elementAttrPrefix , cloneAttrPrefix )
+ end
+
+ def test_namespaces_in_attlist_tobias
+ in_string = File.open(fixture_path('foo.xml'), 'r') do |file|
+ file.read
+ end
+
+ doc = Document.new in_string
+
+ assert_nil XPath.first(doc,'//leg')
+ assert_equal 'http://www.foo.com/human', doc.root.elements[1].namespace
+ assert_equal 'human leg',
+ XPath.first(doc, '//x:leg/text()', {'x'=>'http://www.foo.com/human'}).to_s
+ end
+
+ # Alun ap Rhisiart
+ def test_less_than_in_element_content
+ source = File.new(fixture_path('ProductionSupport.xml'))
+ h = Hash.new
+ doc = REXML::Document.new source
+ doc.elements.each("//CommonError") { |el|
+ h[el.elements['Key'].text] = 'okay'
+ }
+ assert(h.include?('MotorInsuranceContract(Object)>>#error:'))
+ end
+
+ # XPaths provided by Thomas Sawyer
+ def test_various_xpath
+ #@doc = REXML::Document.new('<r a="1"><p><c b="2"/></p></r>')
+ doc = REXML::Document.new('<r a="1"><p><c b="2">3</c></p></r>')
+
+ [['/r', REXML::Element],
+ ['/r/p/c', REXML::Element],
+ ['/r/attribute::a', Attribute],
+ ['/r/@a', Attribute],
+ ['/r/attribute::*', Attribute],
+ ['/r/@*', Attribute],
+ ['/r/p/c/attribute::b', Attribute],
+ ['/r/p/c/@b', Attribute],
+ ['/r/p/c/attribute::*', Attribute],
+ ['/r/p/c/@*', Attribute],
+ ['//c/attribute::b', Attribute],
+ ['//c/@b', Attribute],
+ ['//c/attribute::*', Attribute],
+ ['//c/@*', Attribute],
+ ['.//node()', REXML::Node ],
+ ['.//node()[@a]', REXML::Element ],
+ ['.//node()[@a="1"]', REXML::Element ],
+ ['.//node()[@b]', REXML::Element ], # no show, why?
+ ['.//node()[@b="2"]', REXML::Element ]
+ ].each do |xpath,kind|
+ begin
+ REXML::XPath.each( doc, xpath ) do |what|
+ assert_kind_of( kind, what, "\n\nWrong type (#{what.class}) returned for #{xpath} (expected #{kind.name})\n\n" )
+ end
+ rescue Exception
+ puts "PATH WAS: #{xpath}"
+ raise
+ end
+ end
+
+ [
+ ['/r', 'attribute::a', Attribute ],
+ ['/r', '@a', Attribute ],
+ ['/r', 'attribute::*', Attribute ],
+ ['/r', '@*', Attribute ],
+ ['/r/p/c', 'attribute::b', Attribute ],
+ ['/r/p/c', '@b', Attribute ],
+ ['/r/p/c', 'attribute::*', Attribute ],
+ ['/r/p/c', '@*', Attribute ]
+ ].each do |nodepath, xpath, kind|
+ begin
+ context = REXML::XPath.first(doc, nodepath)
+ REXML::XPath.each( context, xpath ) do |what|
+ assert_kind_of kind, what, "Wrong type (#{what.class}) returned for #{xpath} (expected #{kind.name})\n"
+ end
+ rescue Exception
+ puts "PATH WAS: #{xpath}"
+ raise
+ end
+ end
+ end
+
+ def test_entities_Holden_Glova
+ document = <<-EOL
+ <?xml version="1.0" encoding="UTF-8"?>
+ <!DOCTYPE rubynet [
+ <!ENTITY rbconfig.MAJOR "1">
+ <!ENTITY rbconfig.MINOR "7">
+ <!ENTITY rbconfig.TEENY "2">
+ <!ENTITY rbconfig.ruby_version "&rbconfig.MAJOR;.&rbconfig.MINOR;">
+ <!ENTITY rbconfig.arch "i386-freebsd5">
+ <!ENTITY rbconfig.prefix "/usr/local">
+ <!ENTITY rbconfig.libdir "&rbconfig.prefix;/lib">
+ <!ENTITY rbconfig.includedir "&rbconfig.prefix;/include">
+ <!ENTITY rbconfig.sitedir "&rbconfig.prefix;/lib/ruby/site_ruby">
+ <!ENTITY rbconfig.sitelibdir "&rbconfig.sitedir;/&rbconfig.ruby_version;">
+ <!ENTITY rbconfig.sitearchdir "&rbconfig.sitelibdir;/&rbconfig.arch;">
+ ]>
+ <rubynet>
+ <pkg version="version1.0">
+ <files>
+ <file>
+ <filename>uga.rb</filename>
+ <mode>0444</mode>
+ <path>&rbconfig.libdir;/rexml</path>
+ <content encoding="xml">... the file here</content>
+ </file>
+ <file>
+ <filename>booga.h</filename>
+ <mode>0444</mode>
+ <path>&rbconfig.includedir;</path>
+ <content encoding="xml">... the file here</content>
+ </file>
+ <file>
+ <filename>foo.so</filename>
+ <mode>0555</mode>
+ <path>&rbconfig.sitearchdir;/rexml</path>
+ <content encoding="mime64">Li4uIHRoZSBmaWxlIGhlcmU=\n</content>
+ </file>
+ </files>
+ </pkg>
+ </rubynet>
+ EOL
+
+ file_xpath = '/rubynet/pkg/files/file'
+
+ root = REXML::Document.new(document)
+
+ root.elements.each(file_xpath) do |metadata|
+ text = metadata.elements['path'].get_text.value
+ assert text !~ /&rbconfig/, "'#{text}' failed"
+ end
+
+ #Error occurred in test_package_file_opens(TC_PackageInstall):
+ # ArgumentError:
+ #illegal access mode &rbconfig.prefix;/lib/rexml
+ #
+ #[synack@Evergreen] src $ ruby --version
+ #ruby 1.6.7 (2002-03-01) [i686-linux-gnu]
+ #
+ #It looks like it expanded the first entity, but didn't reparse it for more
+ #entities. possible bug - or have I mucked this up?
+ end
+
+ def test_whitespace_after_xml_decl
+ d = Document.new <<EOL
<?xml version='1.0'?>
<blo>
- <wak>
- </wak>
+ <wak>
+ </wak>
</blo>
EOL
- end
+ end
- def test_external_entity
- xp = '//channel/title'
+ def test_external_entity
+ xp = '//channel/title'
- %w{working.rss broken.rss}.each do |path|
- File.open(File.join(fixture_path(path))) do |file|
- doc = REXML::Document.new file.readlines.join('')
+ %w{working.rss broken.rss}.each do |path|
+ File.open(File.join(fixture_path(path))) do |file|
+ doc = REXML::Document.new file.readlines.join('')
- # check to make sure everything is kosher
- assert_equal( doc.root.class, REXML::Element )
- assert_equal( doc.root.elements.class, REXML::Elements )
+ # check to make sure everything is kosher
+ assert_equal( doc.root.class, REXML::Element )
+ assert_equal( doc.root.elements.class, REXML::Elements )
- # get the title of the feed
- assert( doc.root.elements[xp].kind_of?( REXML::Element ) )
- end
- end
- end
+ # get the title of the feed
+ assert( doc.root.elements[xp].kind_of?( REXML::Element ) )
+ end
+ end
+ end
- def test_maintain_dtd
- src = %q{<?xml version="1.0" encoding="UTF-8"?>
+ def test_maintain_dtd
+ src = %q{<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ivattacks SYSTEM "../../ivacm.dtd" [
<!ENTITY % extern-packages SYSTEM "../../ivpackages.dtd">
<!ENTITY % extern-packages SYSTEM "../../common-declarations.dtd">
%extern-packages;
%extern-common;
]>}
- doc = Document.new( src )
- doc.write( out="" )
- src = src.tr('"', "'")
- out = out.tr('"', "'")
- assert_equal( src, out )
- end
-
- def test_text_nodes_nomatch
- source = "<root><child>test</child></root>"
- d = REXML::Document.new( source )
- r = REXML::XPath.match( d, %q{/root/child[text()="no-test"]} )
- assert_equal( 0, r.size )
- end
+ doc = Document.new( src )
+ doc.write( out="" )
+ src = src.tr('"', "'")
+ out = out.tr('"', "'")
+ assert_equal( src, out )
+ end
+
+ def test_text_nodes_nomatch
+ source = "<root><child>test</child></root>"
+ d = REXML::Document.new( source )
+ r = REXML::XPath.match( d, %q{/root/child[text()="no-test"]} )
+ assert_equal( 0, r.size )
+ end
def test_raw_Terje_Elde
f = REXML::Formatters::Default.new
@@ -560,24 +560,24 @@ EOL
=begin
# This is a silly test, and is low priority
def test_namespace_serialization_tobi_reif
- doc = Document.new '<doc xmlns:b="http://www.foo.foo">
+ doc = Document.new '<doc xmlns:b="http://www.foo.foo">
<b:p/>
</doc>'
- ns = 'http://www.foo.foo'
- ns_declaration={'f'=>ns}
- returned = XPath.match(doc,'//f:p',ns_declaration)
- # passes:
- assert( (returned[0].namespace==ns), 'namespace should be '+ns)
- serialized = returned.to_s
- serialized_and_parsed = Document.new(serialized)
- puts 'serialized: '+serialized
- # ... currently brings <b:p/>
- # prefix b is undeclared (!)
- assert( (serialized_and_parsed.namespace==ns),
- 'namespace should still be '+ns.inspect+
- ' and not '+serialized_and_parsed.namespace.inspect)
- # ... currently results in a failure:
- # 'namespace should still be "http://www.foo.foo" and not ""'
+ ns = 'http://www.foo.foo'
+ ns_declaration={'f'=>ns}
+ returned = XPath.match(doc,'//f:p',ns_declaration)
+ # passes:
+ assert( (returned[0].namespace==ns), 'namespace should be '+ns)
+ serialized = returned.to_s
+ serialized_and_parsed = Document.new(serialized)
+ puts 'serialized: '+serialized
+ # ... currently brings <b:p/>
+ # prefix b is undeclared (!)
+ assert( (serialized_and_parsed.namespace==ns),
+ 'namespace should still be '+ns.inspect+
+ ' and not '+serialized_and_parsed.namespace.inspect)
+ # ... currently results in a failure:
+ # 'namespace should still be "http://www.foo.foo" and not ""'
end
=end
end
diff --git a/test/rexml/test_core.rb b/test/rexml/test_core.rb
index 4fd5b07..79c6dd8 100644
--- a/test/rexml/test_core.rb
+++ b/test/rexml/test_core.rb
@@ -1104,9 +1104,9 @@ EOL
end
def test_transitive
- doc = REXML::Document.new( "<a/>")
- s = ""
- doc.write( s, 0, true )
+ doc = REXML::Document.new( "<a/>")
+ s = ""
+ doc.write( s, 0, true )
end
# This is issue #40
@@ -1145,25 +1145,25 @@ EOL
end
- def test_ticket_58
- doc = REXML::Document.new
- doc << REXML::XMLDecl.default
- doc << REXML::Element.new("a")
-
- str = ""
- doc.write(str)
-
- assert_equal("<a/>", str)
+ def test_ticket_58
+ doc = REXML::Document.new
+ doc << REXML::XMLDecl.default
+ doc << REXML::Element.new("a")
+
+ str = ""
+ doc.write(str)
+
+ assert_equal("<a/>", str)
- doc = REXML::Document.new
- doc << REXML::XMLDecl.new("1.0", "UTF-8")
- doc << REXML::Element.new("a")
-
- str = ""
- doc.write(str)
-
- assert_equal("<?xml version='1.0' encoding='UTF-8'?><a/>", str)
- end
+ doc = REXML::Document.new
+ doc << REXML::XMLDecl.new("1.0", "UTF-8")
+ doc << REXML::Element.new("a")
+
+ str = ""
+ doc.write(str)
+
+ assert_equal("<?xml version='1.0' encoding='UTF-8'?><a/>", str)
+ end
# Incomplete tags should generate an error
def test_ticket_53
@@ -1251,9 +1251,9 @@ EOL
def test_ticket_85
xml = <<ENDXML
<foo>
- <bar>
- <bob name='jimmy'/>
- </bar>
+ <bar>
+ <bob name='jimmy'/>
+ </bar>
</foo>
ENDXML
@@ -1276,7 +1276,7 @@ ENDXML
# Output directives should override whitespace directives.
assert_equal( output1, output2 )
- # The base case.
+ # The base case.
d = Document.new(yml)
f.write( d, output3="" )
@@ -1286,7 +1286,7 @@ ENDXML
f.write( d, output4="" )
assert_equal( output3.strip, output4.strip )
- end
+ end
def test_ticket_91
source="<root>
diff --git a/test/rexml/test_elements.rb b/test/rexml/test_elements.rb
index e140214..210004a 100644
--- a/test/rexml/test_elements.rb
+++ b/test/rexml/test_elements.rb
@@ -2,45 +2,45 @@ require 'test/unit/testcase'
require 'rexml/document'
class ElementsTester < Test::Unit::TestCase
- include REXML
- def test_elements_accessor
- doc = Document.new '<a><b/><c id="1"/><c id="2"/><d/></a>'
- assert_equal 'b', doc.root.elements[1].name
- assert_equal '1', doc.root.elements['c'].attributes['id']
- assert_equal '2', doc.root.elements[2,'c'].attributes['id']
- end
+ include REXML
+ def test_elements_accessor
+ doc = Document.new '<a><b/><c id="1"/><c id="2"/><d/></a>'
+ assert_equal 'b', doc.root.elements[1].name
+ assert_equal '1', doc.root.elements['c'].attributes['id']
+ assert_equal '2', doc.root.elements[2,'c'].attributes['id']
+ end
- def test_elements_indexing
- doc = Document.new '<a/>'
- doc.root.elements[10] = Element.new('b')
- assert_equal 'b', doc.root.elements[1].name
- doc.root.elements[1] = Element.new('c')
- assert_equal 'c', doc.root.elements[1].name
- doc.root.elements['c'] = Element.new('d')
- assert_equal 'd', doc.root.elements[1].name
- end
-
- def test_elements_delete
- doc = Document.new '<a><b/><c/><c id="1"/></a>'
- block = proc { |str|
- out = ''
- doc.write out
- assert_equal str, out
- }
- b = doc.root.elements[1]
- doc.root.elements.delete b
- block.call( "<a><c/><c id='1'/></a>" )
- doc.elements.delete("a/c[@id='1']")
- block.call( '<a><c/></a>' )
- doc.root.elements.delete 1
+ def test_elements_indexing
+ doc = Document.new '<a/>'
+ doc.root.elements[10] = Element.new('b')
+ assert_equal 'b', doc.root.elements[1].name
+ doc.root.elements[1] = Element.new('c')
+ assert_equal 'c', doc.root.elements[1].name
+ doc.root.elements['c'] = Element.new('d')
+ assert_equal 'd', doc.root.elements[1].name
+ end
+
+ def test_elements_delete
+ doc = Document.new '<a><b/><c/><c id="1"/></a>'
+ block = proc { |str|
+ out = ''
+ doc.write out
+ assert_equal str, out
+ }
+ b = doc.root.elements[1]
+ doc.root.elements.delete b
+ block.call( "<a><c/><c id='1'/></a>" )
+ doc.elements.delete("a/c[@id='1']")
+ block.call( '<a><c/></a>' )
+ doc.root.elements.delete 1
block.call( '<a/>' )
- end
+ end
- def test_elements_delete_all
- doc = Document.new '<a><c/><c/><c/><c/></a>'
- deleted = doc.elements.delete_all 'a/c'
- assert_equal 4, deleted.size
- end
+ def test_elements_delete_all
+ doc = Document.new '<a><c/><c/><c/><c/></a>'
+ deleted = doc.elements.delete_all 'a/c'
+ assert_equal 4, deleted.size
+ end
def test_ticket_36
doc = Document.new( "<a xmlns:xi='foo'><b><xi:c id='1'/></b><xi:c id='2'/></a>" )
@@ -53,55 +53,55 @@ class ElementsTester < Test::Unit::TestCase
assert_equal( 2, deleted.size )
end
- def test_elements_add
- a = Element.new 'a'
- a.elements.add Element.new('b')
- assert_equal 'b', a.elements[1].name
- a.elements.add 'c'
- assert_equal 'c', a.elements[2].name
- end
+ def test_elements_add
+ a = Element.new 'a'
+ a.elements.add Element.new('b')
+ assert_equal 'b', a.elements[1].name
+ a.elements.add 'c'
+ assert_equal 'c', a.elements[2].name
+ end
- def test_elements_size
- doc = Document.new '<a>sean<b/>elliott<b/>russell<b/></a>'
- assert_equal 6, doc.root.size
- assert_equal 3, doc.root.elements.size
- end
+ def test_elements_size
+ doc = Document.new '<a>sean<b/>elliott<b/>russell<b/></a>'
+ assert_equal 6, doc.root.size
+ assert_equal 3, doc.root.elements.size
+ end
- def test_elements_each
- doc = Document.new '<a><b/><c/><d/>sean<b/><c/><d/></a>'
- count = 0
- block = proc {|e| count += 1}
- doc.root.elements.each(&block)
- assert_equal 6, count
- count = 0
- doc.root.elements.each('b', &block)
- assert_equal 2, count
- count = 0
- doc.root.elements.each('child::node()', &block)
- assert_equal 6, count
- count = 0
- XPath.each(doc.root, 'child::node()', &block)
- assert_equal 7, count
- end
+ def test_elements_each
+ doc = Document.new '<a><b/><c/><d/>sean<b/><c/><d/></a>'
+ count = 0
+ block = proc {|e| count += 1}
+ doc.root.elements.each(&block)
+ assert_equal 6, count
+ count = 0
+ doc.root.elements.each('b', &block)
+ assert_equal 2, count
+ count = 0
+ doc.root.elements.each('child::node()', &block)
+ assert_equal 6, count
+ count = 0
+ XPath.each(doc.root, 'child::node()', &block)
+ assert_equal 7, count
+ end
- def test_elements_to_a
- doc = Document.new '<a>sean<b/>elliott<c/></a>'
- assert_equal 2, doc.root.elements.to_a.size
- assert_equal 2, doc.root.elements.to_a("child::node()").size
- assert_equal 4, XPath.match(doc.root, "child::node()").size
- end
-
- def test_elements_collect
- doc = Document.new( "<a><b id='1'/><b id='2'/></a>" )
- r = doc.elements.collect( "/a/b" ) { |e| e.attributes["id"].to_i }
- assert_equal( [1,2], r )
- end
-
- def test_elements_inject
- doc = Document.new( "<a><b id='1'/><b id='2'/></a>" )
- r = doc.elements.inject( "/a/b", 3 ) { |s, e|
- s + e.attributes["id"].to_i
- }
- assert_equal 6, r
- end
+ def test_elements_to_a
+ doc = Document.new '<a>sean<b/>elliott<c/></a>'
+ assert_equal 2, doc.root.elements.to_a.size
+ assert_equal 2, doc.root.elements.to_a("child::node()").size
+ assert_equal 4, XPath.match(doc.root, "child::node()").size
+ end
+
+ def test_elements_collect
+ doc = Document.new( "<a><b id='1'/><b id='2'/></a>" )
+ r = doc.elements.collect( "/a/b" ) { |e| e.attributes["id"].to_i }
+ assert_equal( [1,2], r )
+ end
+
+ def test_elements_inject
+ doc = Document.new( "<a><b id='1'/><b id='2'/></a>" )
+ r = doc.elements.inject( "/a/b", 3 ) { |s, e|
+ s + e.attributes["id"].to_i
+ }
+ assert_equal 6, r
+ end
end
diff --git a/test/rexml/test_encoding.rb b/test/rexml/test_encoding.rb
index 19896ea..23e4802 100644
--- a/test/rexml/test_encoding.rb
+++ b/test/rexml/test_encoding.rb
@@ -15,7 +15,7 @@ class EncodingTester < Test::Unit::TestCase
end
# Given an encoded document, try to write out to that encoding
- def test_encoded_in_encoded_out
+ def test_encoded_in_encoded_out
doc = Document.new( @encoded )
doc.write( out="" )
out.force_encoding('binary') if out.respond_to? :force_encoding
diff --git a/test/rexml/test_encoding_2.rb b/test/rexml/test_encoding_2.rb
index 5dbe468..2e845b5 100644
--- a/test/rexml/test_encoding_2.rb
+++ b/test/rexml/test_encoding_2.rb
@@ -6,54 +6,54 @@ require "rexml/parseexception"
=begin
# THIS DOESN'T WORK
begin
- require 'iconv'
+ require 'iconv'
- UnixCharsets = open("| iconv -l") do |f|
- f.readlines[5..-1].collect { |x| x.sub(/\/\/\n/,"").delete(' ') }
- end
+ UnixCharsets = open("| iconv -l") do |f|
+ f.readlines[5..-1].collect { |x| x.sub(/\/\/\n/,"").delete(' ') }
+ end
- DATA = <<END
+ DATA = <<END
<?xml version="1.0" encoding='ENC'?>
<Ruby xmlns="http://www.ruby-lang.org/ruby/1.8">
</Ruby>
END
- class IConvTester < Test::Unit::TestCase
-
- def test_iconv
- broken_encodings = 0
- UnixCharsets.each do |enc|
- begin
- puts "Testing encoding #{enc}"
- data = DATA.dup
- data[/ENC/] = enc
- REXML::Document.new(data).root
- rescue REXML::ParseException => e
- broken_encodings += 1
- fail "Encoding #{enc} does not work with REXML: #{e.message}"
- rescue Errno::EINVAL => e
- broken_encodings += 1
- fail "Encoding #{enc} does not work with REXML: #{e.message}"
- rescue ArgumentError => e
- broken_encodings += 1
- fail "Encoding #{enc} does not work with REXML: #{e.message}"
- rescue
- broken_encodings += 1
- fail "Encoding #{enc} does not work with REXML: #{$!.message}"
- end
- end
-
- if broken_encodings > 0
- fail "There were #{broken_encodings} encoding failures out of #{UnixCharsets.size} plus some REXML internal encodings"
- else
- fail "There were no encoding failures"
- end
-
- puts "Full list of registered encodings in REXML:"
- puts REXML::Encoding::ENCODING_CLAIMS.values.join(', ')
- end
- end
+ class IConvTester < Test::Unit::TestCase
+
+ def test_iconv
+ broken_encodings = 0
+ UnixCharsets.each do |enc|
+ begin
+ puts "Testing encoding #{enc}"
+ data = DATA.dup
+ data[/ENC/] = enc
+ REXML::Document.new(data).root
+ rescue REXML::ParseException => e
+ broken_encodings += 1
+ fail "Encoding #{enc} does not work with REXML: #{e.message}"
+ rescue Errno::EINVAL => e
+ broken_encodings += 1
+ fail "Encoding #{enc} does not work with REXML: #{e.message}"
+ rescue ArgumentError => e
+ broken_encodings += 1
+ fail "Encoding #{enc} does not work with REXML: #{e.message}"
+ rescue
+ broken_encodings += 1
+ fail "Encoding #{enc} does not work with REXML: #{$!.message}"
+ end
+ end
+
+ if broken_encodings > 0
+ fail "There were #{broken_encodings} encoding failures out of #{UnixCharsets.size} plus some REXML internal encodings"
+ else
+ fail "There were no encoding failures"
+ end
+
+ puts "Full list of registered encodings in REXML:"
+ puts REXML::Encoding::ENCODING_CLAIMS.values.join(', ')
+ end
+ end
rescue LoadError
end
=end
diff --git a/test/rexml/test_entity.rb b/test/rexml/test_entity.rb
index 3895cdc..3bf310a 100644
--- a/test/rexml/test_entity.rb
+++ b/test/rexml/test_entity.rb
@@ -4,145 +4,145 @@ require 'rexml/entity'
require 'rexml/source'
class EntityTester < Test::Unit::TestCase
- def test_parse_general_decl
- simple = "<!ENTITY foo 'bar'>"
- simple =~ /#{REXML::Entity::GEDECL}/
- assert $&
- assert_equal simple, $&
-
- REXML::Entity::ENTITYDECL =~ simple
- assert REXML::Entity::matches?(simple)
- match = REXML::Entity::ENTITYDECL.match(simple)
- assert_equal 'foo', match[1]
- assert_equal "'bar'", match[2]
+ def test_parse_general_decl
+ simple = "<!ENTITY foo 'bar'>"
+ simple =~ /#{REXML::Entity::GEDECL}/
+ assert $&
+ assert_equal simple, $&
+
+ REXML::Entity::ENTITYDECL =~ simple
+ assert REXML::Entity::matches?(simple)
+ match = REXML::Entity::ENTITYDECL.match(simple)
+ assert_equal 'foo', match[1]
+ assert_equal "'bar'", match[2]
- simple = '<!ENTITY Pub-Status
- "This is a pre-release of the specification.">'
- assert REXML::Entity::matches?(simple)
- match = REXML::Entity::ENTITYDECL.match(simple)
- assert_equal 'Pub-Status', match[1]
- assert_equal '"This is a pre-release of the specification."', match[2]
+ simple = '<!ENTITY Pub-Status
+ "This is a pre-release of the specification.">'
+ assert REXML::Entity::matches?(simple)
+ match = REXML::Entity::ENTITYDECL.match(simple)
+ assert_equal 'Pub-Status', match[1]
+ assert_equal '"This is a pre-release of the specification."', match[2]
- txt = '"This is a
- pre-release of <the> specification."'
- simple = "<!ENTITY Pub-Status
- #{txt}>"
- assert REXML::Entity::matches?(simple)
- match = REXML::Entity::ENTITYDECL.match(simple)
- assert_equal 'Pub-Status', match[1]
- assert_equal txt, match[2]
- end
+ txt = '"This is a
+ pre-release of <the> specification."'
+ simple = "<!ENTITY Pub-Status
+ #{txt}>"
+ assert REXML::Entity::matches?(simple)
+ match = REXML::Entity::ENTITYDECL.match(simple)
+ assert_equal 'Pub-Status', match[1]
+ assert_equal txt, match[2]
+ end
- def test_parse_external_decl
- zero = '<!ENTITY open-hatch SYSTEM "http://www.textuality.com/boilerplate/OpenHatch.xml" >'
- one = '<!ENTITY open-hatch
- SYSTEM "http://www.textuality.com/boilerplate/OpenHatch.xml">'
- two = '<!ENTITY open-hatch
- PUBLIC "-//Textuality//TEXT Standard open-hatch boilerplate//EN"
- "http://www.textuality.com/boilerplate/OpenHatch.xml">'
- three = '<!ENTITY hatch-pic
- SYSTEM "../grafix/OpenHatch.gif"
- NDATA gif >'
- assert REXML::Entity::matches?(zero)
- assert REXML::Entity::matches?(one)
- assert REXML::Entity::matches?(two)
- assert REXML::Entity::matches?(three)
- end
+ def test_parse_external_decl
+ zero = '<!ENTITY open-hatch SYSTEM "http://www.textuality.com/boilerplate/OpenHatch.xml" >'
+ one = '<!ENTITY open-hatch
+ SYSTEM "http://www.textuality.com/boilerplate/OpenHatch.xml">'
+ two = '<!ENTITY open-hatch
+ PUBLIC "-//Textuality//TEXT Standard open-hatch boilerplate//EN"
+ "http://www.textuality.com/boilerplate/OpenHatch.xml">'
+ three = '<!ENTITY hatch-pic
+ SYSTEM "../grafix/OpenHatch.gif"
+ NDATA gif >'
+ assert REXML::Entity::matches?(zero)
+ assert REXML::Entity::matches?(one)
+ assert REXML::Entity::matches?(two)
+ assert REXML::Entity::matches?(three)
+ end
- def test_parse_entity
- one = %q{<!ENTITY % YN '"Yes"'>}
- two = %q{<!ENTITY WhatHeSaid "He said %YN;">}
- assert REXML::Entity::matches?(one)
- assert REXML::Entity::matches?(two)
- end
+ def test_parse_entity
+ one = %q{<!ENTITY % YN '"Yes"'>}
+ two = %q{<!ENTITY WhatHeSaid "He said %YN;">}
+ assert REXML::Entity::matches?(one)
+ assert REXML::Entity::matches?(two)
+ end
- def test_constructor
- one = [ %q{<!ENTITY % YN '"Yes"'>},
- %q{<!ENTITY % YN2 "Yes">},
- %q{<!ENTITY WhatHeSaid "He said %YN;">},
- '<!ENTITY open-hatch
- SYSTEM "http://www.textuality.com/boilerplate/OpenHatch.xml">',
- '<!ENTITY open-hatch2
- PUBLIC "-//Textuality//TEXT Standard open-hatch boilerplate//EN"
- "http://www.textuality.com/boilerplate/OpenHatch.xml">',
- '<!ENTITY hatch-pic
- SYSTEM "../grafix/OpenHatch.gif"
- NDATA gif>' ]
- source = %q{<!DOCTYPE foo [
- <!ENTITY % YN '"Yes"'>
- <!ENTITY % YN2 "Yes">
- <!ENTITY WhatHeSaid "He said %YN;">
- <!ENTITY open-hatch
- SYSTEM "http://www.textuality.com/boilerplate/OpenHatch.xml">
- <!ENTITY open-hatch2
- PUBLIC "-//Textuality//TEXT Standard open-hatch boilerplate//EN"
- "http://www.textuality.com/boilerplate/OpenHatch.xml">
- <!ENTITY hatch-pic
- SYSTEM "../grafix/OpenHatch.gif"
- NDATA gif>
- ]>}
+ def test_constructor
+ one = [ %q{<!ENTITY % YN '"Yes"'>},
+ %q{<!ENTITY % YN2 "Yes">},
+ %q{<!ENTITY WhatHeSaid "He said %YN;">},
+ '<!ENTITY open-hatch
+ SYSTEM "http://www.textuality.com/boilerplate/OpenHatch.xml">',
+ '<!ENTITY open-hatch2
+ PUBLIC "-//Textuality//TEXT Standard open-hatch boilerplate//EN"
+ "http://www.textuality.com/boilerplate/OpenHatch.xml">',
+ '<!ENTITY hatch-pic
+ SYSTEM "../grafix/OpenHatch.gif"
+ NDATA gif>' ]
+ source = %q{<!DOCTYPE foo [
+ <!ENTITY % YN '"Yes"'>
+ <!ENTITY % YN2 "Yes">
+ <!ENTITY WhatHeSaid "He said %YN;">
+ <!ENTITY open-hatch
+ SYSTEM "http://www.textuality.com/boilerplate/OpenHatch.xml">
+ <!ENTITY open-hatch2
+ PUBLIC "-//Textuality//TEXT Standard open-hatch boilerplate//EN"
+ "http://www.textuality.com/boilerplate/OpenHatch.xml">
+ <!ENTITY hatch-pic
+ SYSTEM "../grafix/OpenHatch.gif"
+ NDATA gif>
+ ]>}
- d = REXML::Document.new( source )
- dt = d.doctype
- c = 0
- dt.each do |child|
- if child.kind_of? REXML::Entity
- str = one[c].tr("\r\n\t", ' ').squeeze(" ")
- assert_equal str, child.to_s
- c+=1
- end
- end
- end
+ d = REXML::Document.new( source )
+ dt = d.doctype
+ c = 0
+ dt.each do |child|
+ if child.kind_of? REXML::Entity
+ str = one[c].tr("\r\n\t", ' ').squeeze(" ")
+ assert_equal str, child.to_s
+ c+=1
+ end
+ end
+ end
- def test_replace_entities
- source = "<!DOCTYPE blah [\n<!ENTITY foo \"bar\">\n]><a>&foo;</a>"
- doc = REXML::Document.new(source)
- assert_equal 'bar', doc.root.text
- out = ''
- doc.write out
- assert_equal source, out
- end
+ def test_replace_entities
+ source = "<!DOCTYPE blah [\n<!ENTITY foo \"bar\">\n]><a>&foo;</a>"
+ doc = REXML::Document.new(source)
+ assert_equal 'bar', doc.root.text
+ out = ''
+ doc.write out
+ assert_equal source, out
+ end
- def test_raw
- source = '<!DOCTYPE foo [
+ def test_raw
+ source = '<!DOCTYPE foo [
<!ENTITY ent "replace">
]><a>replace &ent;</a>'
- doc = REXML::Document.new( source, {:raw=>:all})
- assert_equal('replace &ent;', doc.root.get_text.to_s)
- assert_equal(source, doc.to_s)
- end
+ doc = REXML::Document.new( source, {:raw=>:all})
+ assert_equal('replace &ent;', doc.root.get_text.to_s)
+ assert_equal(source, doc.to_s)
+ end
- def test_lazy_evaluation
- source = '<!DOCTYPE foo [
+ def test_lazy_evaluation
+ source = '<!DOCTYPE foo [
<!ENTITY ent "replace">
]><a>replace &ent;</a>'
- doc = REXML::Document.new( source )
- assert_equal(source, doc.to_s)
- assert_equal("replace replace", doc.root.text)
- assert_equal(source, doc.to_s)
- end
+ doc = REXML::Document.new( source )
+ assert_equal(source, doc.to_s)
+ assert_equal("replace replace", doc.root.text)
+ assert_equal(source, doc.to_s)
+ end
- # Contributed (not only test, but bug fix!!) by Kouhei Sutou
- def test_entity_replacement
- source = %q{<!DOCTYPE foo [
- <!ENTITY % YN '"Yes"'>
- <!ENTITY WhatHeSaid "He said %YN;">]>
- <a>&WhatHeSaid;</a>}
+ # Contributed (not only test, but bug fix!!) by Kouhei Sutou
+ def test_entity_replacement
+ source = %q{<!DOCTYPE foo [
+ <!ENTITY % YN '"Yes"'>
+ <!ENTITY WhatHeSaid "He said %YN;">]>
+ <a>&WhatHeSaid;</a>}
- d = REXML::Document.new( source )
- dt = d.doctype
- assert_equal( '"Yes"', dt.entities[ "YN" ].value )
- assert_equal( 'He said "Yes"', dt.entities[ "WhatHeSaid" ].value )
- assert_equal( 'He said "Yes"', d.elements[1].text )
- end
+ d = REXML::Document.new( source )
+ dt = d.doctype
+ assert_equal( '"Yes"', dt.entities[ "YN" ].value )
+ assert_equal( 'He said "Yes"', dt.entities[ "WhatHeSaid" ].value )
+ assert_equal( 'He said "Yes"', d.elements[1].text )
+ end
- # More unit tests from Kouhei. I looove users who give me unit tests.
- def test_entity_insertions
- assert_equal("&amp;", REXML::Text.new("&amp;", false, nil, true).to_s)
- #assert_equal("&", REXML::Text.new("&amp;", false, false).to_s)
- end
+ # More unit tests from Kouhei. I looove users who give me unit tests.
+ def test_entity_insertions
+ assert_equal("&amp;", REXML::Text.new("&amp;", false, nil, true).to_s)
+ #assert_equal("&", REXML::Text.new("&amp;", false, false).to_s)
+ end
- def test_single_pass_unnormalization # ticket 123
- assert_equal '&amp;&', REXML::Text::unnormalize('&#38;amp;&amp;')
- end
+ def test_single_pass_unnormalization # ticket 123
+ assert_equal '&amp;&', REXML::Text::unnormalize('&#38;amp;&amp;')
+ end
end
diff --git a/test/rexml/test_functions.rb b/test/rexml/test_functions.rb
index eac36d5..e0f8a67 100644
--- a/test/rexml/test_functions.rb
+++ b/test/rexml/test_functions.rb
@@ -3,209 +3,209 @@ require "test/unit/testcase"
require "rexml/document"
class FunctionsTester < Test::Unit::TestCase
- include REXML
- def test_functions
- # trivial text() test
- # confuse-a-function
- source = "<a>more <b id='1'/><b id='2'>dumb</b><b id='3'/><c/> text</a>"
- doc = Document.new source
- res = ""
- XPath::each(doc.root, "text()") {|val| res << val.to_s}
- assert_equal "more text", res
-
- res = XPath::first(doc.root, "b[last()]")
- assert_equal '3', res.attributes['id']
- res = XPath::first(doc.root, "b[position()=2]")
- assert_equal '2', res.attributes['id']
- res = XPath::first(doc.root, "*[name()='c']")
- assert_equal "c", res.name
- end
-
- # Contributed by Mike Stok
- def test_starts_with
- source = <<-EOF
- <foo>
- <a href="mailto:a@b.c">a@b.c</a>
- <a href="http://www.foo.com">http://www.foo.com</a>
- </foo>
- EOF
- doc = Document.new source
- mailtos = doc.elements.to_a("//a[starts-with(@href, 'mailto:')]")
- assert_equal 1, mailtos.size
- assert_equal "mailto:a@b.c", mailtos[0].attributes['href']
-
- ailtos = doc.elements.to_a("//a[starts-with(@href, 'ailto:')]")
- assert_equal 0, ailtos.size
- end
+ include REXML
+ def test_functions
+ # trivial text() test
+ # confuse-a-function
+ source = "<a>more <b id='1'/><b id='2'>dumb</b><b id='3'/><c/> text</a>"
+ doc = Document.new source
+ res = ""
+ XPath::each(doc.root, "text()") {|val| res << val.to_s}
+ assert_equal "more text", res
+
+ res = XPath::first(doc.root, "b[last()]")
+ assert_equal '3', res.attributes['id']
+ res = XPath::first(doc.root, "b[position()=2]")
+ assert_equal '2', res.attributes['id']
+ res = XPath::first(doc.root, "*[name()='c']")
+ assert_equal "c", res.name
+ end
+
+ # Contributed by Mike Stok
+ def test_starts_with
+ source = <<-EOF
+ <foo>
+ <a href="mailto:a@b.c">a@b.c</a>
+ <a href="http://www.foo.com">http://www.foo.com</a>
+ </foo>
+ EOF
+ doc = Document.new source
+ mailtos = doc.elements.to_a("//a[starts-with(@href, 'mailto:')]")
+ assert_equal 1, mailtos.size
+ assert_equal "mailto:a@b.c", mailtos[0].attributes['href']
+
+ ailtos = doc.elements.to_a("//a[starts-with(@href, 'ailto:')]")
+ assert_equal 0, ailtos.size
+ end
def test_string_length
- doc = Document.new <<-EOF
- <AAA>
- <Q/>
- <SSSS/>
- <BB/>
- <CCC/>
- <DDDDDDDD/>
- <EEEE/>
- </AAA>
- EOF
- assert doc, "create doc"
-
- set = doc.elements.to_a("//*[string-length(name()) = 3]")
- assert_equal 2, set.size, "nodes with names length = 3"
-
- set = doc.elements.to_a("//*[string-length(name()) < 3]")
- assert_equal 2, set.size, "nodes with names length < 3"
-
- set = doc.elements.to_a("//*[string-length(name()) > 3]")
- assert_equal 3, set.size, "nodes with names length > 3"
- end
-
- # Test provided by Mike Stok
- def test_contains
- source = <<-EOF
- <foo>
- <a href="mailto:a@b.c">a@b.c</a>
- <a href="http://www.foo.com">http://www.foo.com</a>
- </foo>
- EOF
- doc = Document.new source
-
- [['o', 2], ['foo', 1], ['bar', 0]].each { |test|
- search, expected = test
- set = doc.elements.to_a("//a[contains(@href, '#{search}')]")
- assert_equal expected, set.size
- }
- end
-
- # Mike Stok and Sean Russell
- def test_substring
- # examples from http://www.w3.org/TR/xpath#function-substring
- doc = Document.new('<test string="12345" />')
-
- d = Document.new("<a b='1'/>")
- #puts XPath.first(d, 'node()[0 + 1]')
- #d = Document.new("<a b='1'/>")
- #puts XPath.first(d, 'a[0 mod 0]')
- [ [1.5, 2.6, '234'],
- [0, 3, '12'],
- [0, '0 div 0', ''],
- [1, '0 div 0', ''],
- ['-42', '1 div 0', '12345'],
+ doc = Document.new <<-EOF
+ <AAA>
+ <Q/>
+ <SSSS/>
+ <BB/>
+ <CCC/>
+ <DDDDDDDD/>
+ <EEEE/>
+ </AAA>
+ EOF
+ assert doc, "create doc"
+
+ set = doc.elements.to_a("//*[string-length(name()) = 3]")
+ assert_equal 2, set.size, "nodes with names length = 3"
+
+ set = doc.elements.to_a("//*[string-length(name()) < 3]")
+ assert_equal 2, set.size, "nodes with names length < 3"
+
+ set = doc.elements.to_a("//*[string-length(name()) > 3]")
+ assert_equal 3, set.size, "nodes with names length > 3"
+ end
+
+ # Test provided by Mike Stok
+ def test_contains
+ source = <<-EOF
+ <foo>
+ <a href="mailto:a@b.c">a@b.c</a>
+ <a href="http://www.foo.com">http://www.foo.com</a>
+ </foo>
+ EOF
+ doc = Document.new source
+
+ [['o', 2], ['foo', 1], ['bar', 0]].each { |test|
+ search, expected = test
+ set = doc.elements.to_a("//a[contains(@href, '#{search}')]")
+ assert_equal expected, set.size
+ }
+ end
+
+ # Mike Stok and Sean Russell
+ def test_substring
+ # examples from http://www.w3.org/TR/xpath#function-substring
+ doc = Document.new('<test string="12345" />')
+
+ d = Document.new("<a b='1'/>")
+ #puts XPath.first(d, 'node()[0 + 1]')
+ #d = Document.new("<a b='1'/>")
+ #puts XPath.first(d, 'a[0 mod 0]')
+ [ [1.5, 2.6, '234'],
+ [0, 3, '12'],
+ [0, '0 div 0', ''],
+ [1, '0 div 0', ''],
+ ['-42', '1 div 0', '12345'],
['-1 div 0', '1 div 0', '']
- ].each { |start, length, expected|
- set = doc.elements.to_a("//test[substring(@string, #{start}, #{length}) = '#{expected}']")
- assert_equal 1, set.size, "#{start}, #{length}, '#{expected}'"
- }
- end
+ ].each { |start, length, expected|
+ set = doc.elements.to_a("//test[substring(@string, #{start}, #{length}) = '#{expected}']")
+ assert_equal 1, set.size, "#{start}, #{length}, '#{expected}'"
+ }
+ end
def test_substring_angrez
testString = REXML::Functions::substring_after("helloworld","hello")
assert_equal( 'world', testString )
end
- def test_translate
- source = <<-EOF
- <doc>
- <case name='w3c one' result='BAr' /> <!-- w3c -->
- <case name='w3c two' result='AAA' /> <!-- w3c -->
- <case name='alchemy' result="gold" /> <!-- mike -->
- <case name='vbxml one' result='A Space Odyssey' />
- <case name='vbxml two' result='AbCdEf' />
- </doc>
- EOF
-
- doc = Document.new(source)
-
- [ ['bar', 'abc', 'ABC', 'w3c one'],
- ['--aaa--','abc-','ABC', 'w3c two'],
- ['lead', 'dear language', 'doll groover', 'alchemy'],
- ['A Space Odissei', 'i', 'y', 'vbxml one'],
- ['abcdefg', 'aceg', 'ACE', 'vbxml two'],
- ].each { |arg1, arg2, arg3, name|
- translate = "translate('#{arg1}', '#{arg2}', '#{arg3}')"
- set = doc.elements.to_a("//case[@result = #{translate}]")
- assert_equal 1, set.size, translate
- assert_equal name, set[0].attributes['name']
- }
- end
-
- def test_name
- d = REXML::Document.new("<a xmlns:x='foo'><b/><x:b/></a>")
- assert_equal 1, d.root.elements.to_a('*[name() = "b"]').size
- assert_equal 1, d.elements.to_a('//*[name() = "x:b"]').size
- end
-
- def test_local_name
- d = REXML::Document.new("<a xmlns:x='foo'><b/><x:b/></a>")
- assert_equal 2, d.root.elements.to_a('*[local_name() = "b"]').size
- assert_equal 2, d.elements.to_a('//*[local_name() = "b"]').size
- end
-
- def test_substring2
- doc = Document.new('<test string="12345" />')
- assert_equal(1,doc.elements.to_a("//test[substring(@string,2)='2345']").size)
- end
-
- # Submitted by Kouhei
- def test_floor_ceiling_round
- source = "<a><b id='1'/><b id='2'/><b id='3'/></a>"
- doc = REXML::Document.new(source)
-
- id_1 = doc.elements["/a/b[@id='1']"]
- id_2 = doc.elements["/a/b[@id='2']"]
- id_3 = doc.elements["/a/b[@id='3']"]
-
- good = {
- "floor" => [[], [id_1], [id_2], [id_3]],
- "ceiling" => [[id_1], [id_2], [id_3], []],
- "round" => [[id_1], [id_2], [id_3], []]
- }
- good.each do |key, value|
- (0..3).each do |i|
- xpath = "//b[number(@id) = #{key}(#{i+0.5})]"
- assert_equal(value[i], REXML::XPath.match(doc, xpath))
- end
- end
-
- good["round"] = [[], [id_1], [id_2], [id_3]]
- good.each do |key, value|
- (0..3).each do |i|
- xpath = "//b[number(@id) = #{key}(#{i+0.4})]"
- assert_equal(value[i], REXML::XPath.match(doc, xpath))
- end
- end
- end
-
- # Submitted by Kou
- def test_lang
- d = Document.new(<<-XML)
- <a xml:lang="en">
- <b xml:lang="ja">
- <c xml:lang="fr"/>
- <d/>
- <e xml:lang="ja-JP"/>
- <f xml:lang="en-US"/>
- </b>
- </a>
- XML
-
- assert_equal(1, d.elements.to_a("//*[lang('fr')]").size)
- assert_equal(3, d.elements.to_a("//*[lang('ja')]").size)
- assert_equal(2, d.elements.to_a("//*[lang('en')]").size)
- assert_equal(1, d.elements.to_a("//*[lang('en-us')]").size)
-
- d = Document.new(<<-XML)
- <root>
- <para xml:lang="en"/>
- <div xml:lang="en"><para/></div>
- <para xml:lang="EN"/>
- <para xml:lang="en-us"/>
- </root>
- XML
-
- assert_equal(5, d.elements.to_a("//*[lang('en')]").size)
- end
+ def test_translate
+ source = <<-EOF
+ <doc>
+ <case name='w3c one' result='BAr' /> <!-- w3c -->
+ <case name='w3c two' result='AAA' /> <!-- w3c -->
+ <case name='alchemy' result="gold" /> <!-- mike -->
+ <case name='vbxml one' result='A Space Odyssey' />
+ <case name='vbxml two' result='AbCdEf' />
+ </doc>
+ EOF
+
+ doc = Document.new(source)
+
+ [ ['bar', 'abc', 'ABC', 'w3c one'],
+ ['--aaa--','abc-','ABC', 'w3c two'],
+ ['lead', 'dear language', 'doll groover', 'alchemy'],
+ ['A Space Odissei', 'i', 'y', 'vbxml one'],
+ ['abcdefg', 'aceg', 'ACE', 'vbxml two'],
+ ].each { |arg1, arg2, arg3, name|
+ translate = "translate('#{arg1}', '#{arg2}', '#{arg3}')"
+ set = doc.elements.to_a("//case[@result = #{translate}]")
+ assert_equal 1, set.size, translate
+ assert_equal name, set[0].attributes['name']
+ }
+ end
+
+ def test_name
+ d = REXML::Document.new("<a xmlns:x='foo'><b/><x:b/></a>")
+ assert_equal 1, d.root.elements.to_a('*[name() = "b"]').size
+ assert_equal 1, d.elements.to_a('//*[name() = "x:b"]').size
+ end
+
+ def test_local_name
+ d = REXML::Document.new("<a xmlns:x='foo'><b/><x:b/></a>")
+ assert_equal 2, d.root.elements.to_a('*[local_name() = "b"]').size
+ assert_equal 2, d.elements.to_a('//*[local_name() = "b"]').size
+ end
+
+ def test_substring2
+ doc = Document.new('<test string="12345" />')
+ assert_equal(1,doc.elements.to_a("//test[substring(@string,2)='2345']").size)
+ end
+
+ # Submitted by Kouhei
+ def test_floor_ceiling_round
+ source = "<a><b id='1'/><b id='2'/><b id='3'/></a>"
+ doc = REXML::Document.new(source)
+
+ id_1 = doc.elements["/a/b[@id='1']"]
+ id_2 = doc.elements["/a/b[@id='2']"]
+ id_3 = doc.elements["/a/b[@id='3']"]
+
+ good = {
+ "floor" => [[], [id_1], [id_2], [id_3]],
+ "ceiling" => [[id_1], [id_2], [id_3], []],
+ "round" => [[id_1], [id_2], [id_3], []]
+ }
+ good.each do |key, value|
+ (0..3).each do |i|
+ xpath = "//b[number(@id) = #{key}(#{i+0.5})]"
+ assert_equal(value[i], REXML::XPath.match(doc, xpath))
+ end
+ end
+
+ good["round"] = [[], [id_1], [id_2], [id_3]]
+ good.each do |key, value|
+ (0..3).each do |i|
+ xpath = "//b[number(@id) = #{key}(#{i+0.4})]"
+ assert_equal(value[i], REXML::XPath.match(doc, xpath))
+ end
+ end
+ end
+
+ # Submitted by Kou
+ def test_lang
+ d = Document.new(<<-XML)
+ <a xml:lang="en">
+ <b xml:lang="ja">
+ <c xml:lang="fr"/>
+ <d/>
+ <e xml:lang="ja-JP"/>
+ <f xml:lang="en-US"/>
+ </b>
+ </a>
+ XML
+
+ assert_equal(1, d.elements.to_a("//*[lang('fr')]").size)
+ assert_equal(3, d.elements.to_a("//*[lang('ja')]").size)
+ assert_equal(2, d.elements.to_a("//*[lang('en')]").size)
+ assert_equal(1, d.elements.to_a("//*[lang('en-us')]").size)
+
+ d = Document.new(<<-XML)
+ <root>
+ <para xml:lang="en"/>
+ <div xml:lang="en"><para/></div>
+ <para xml:lang="EN"/>
+ <para xml:lang="en-us"/>
+ </root>
+ XML
+
+ assert_equal(5, d.elements.to_a("//*[lang('en')]").size)
+ end
def test_ticket_60
document = REXML::Document.new("<a><b>A</b><b>1</b></a>")
diff --git a/test/rexml/test_functions_number.rb b/test/rexml/test_functions_number.rb
index e569ce4..849b60e 100644
--- a/test/rexml/test_functions_number.rb
+++ b/test/rexml/test_functions_number.rb
@@ -28,5 +28,5 @@ class TC_Rexml_Functions_Number < Test::Unit::TestCase
# telem = REXML::Element.new("elem")
# telem.text="9.13E12"
# assert_equal(9.13E12, REXML::Functions::number(telem))
- #end
+ #end
end
diff --git a/test/rexml/test_jaxen.rb b/test/rexml/test_jaxen.rb
index 0d53962..96c0c7b 100644
--- a/test/rexml/test_jaxen.rb
+++ b/test/rexml/test_jaxen.rb
@@ -47,16 +47,16 @@ class JaxenTester < Test::Unit::TestCase
# processes a tests/document/context node
def handleContext( testDoc, ctxElement)
- testCtx = XPath.match( testDoc, ctxElement.attributes["select"] )[0]
- namespaces = {}
- if testCtx.class == Element
- testCtx.prefixes.each { |pre| handleNamespace( testCtx, pre, namespaces ) }
- end
- variables = {}
- XPath.each( ctxElement, "@*[namespace-uri() = 'http://jaxen.org/test-harness/var']") { |attrib| handleVariable(testCtx, variables, attrib) }
- XPath.each( ctxElement, "valueOf") { |e| handleValueOf(testCtx, variables, namespaces, e) }
- XPath.each( ctxElement, "test[not(@exception) or (@exception != 'true') ]") { |e| handleNominalTest(testCtx,variables, namespaces, e) }
- XPath.each( ctxElement, "test[@exception = 'true']") { |e| handleExceptionalTest(testCtx,variables, namespaces, e) }
+ testCtx = XPath.match( testDoc, ctxElement.attributes["select"] )[0]
+ namespaces = {}
+ if testCtx.class == Element
+ testCtx.prefixes.each { |pre| handleNamespace( testCtx, pre, namespaces ) }
+ end
+ variables = {}
+ XPath.each( ctxElement, "@*[namespace-uri() = 'http://jaxen.org/test-harness/var']") { |attrib| handleVariable(testCtx, variables, attrib) }
+ XPath.each( ctxElement, "valueOf") { |e| handleValueOf(testCtx, variables, namespaces, e) }
+ XPath.each( ctxElement, "test[not(@exception) or (@exception != 'true') ]") { |e| handleNominalTest(testCtx,variables, namespaces, e) }
+ XPath.each( ctxElement, "test[@exception = 'true']") { |e| handleExceptionalTest(testCtx,variables, namespaces, e) }
end
# processes a tests/document/context/valueOf or tests/document/context/test/valueOf node
@@ -99,28 +99,28 @@ class JaxenTester < Test::Unit::TestCase
# processes a tests/document/context/test node ( where @exception is true )
def handleExceptionalTest(ctx, variables, namespaces, testElement)
assert_raise( Exception ) {
- XPath.match( ctx, testElement.attributes["select"], namespaces, variables )
+ XPath.match( ctx, testElement.attributes["select"], namespaces, variables )
}
end
# processes a tests/document node
def handleDocument(docElement)
- puts "- Processing document: #{docElement.attributes['url']}"
- testFile = File.new( docElement.attributes["url"] )
- testDoc = Document.new testFile
- XPath.each( docElement, "context") { |e| handleContext(testDoc, e) }
+ puts "- Processing document: #{docElement.attributes['url']}"
+ testFile = File.new( docElement.attributes["url"] )
+ testDoc = Document.new testFile
+ XPath.each( docElement, "context") { |e| handleContext(testDoc, e) }
end
# processes a variable definition in a namespace like <test var:foo="bar">
def handleVariable( ctx, variables, attrib )
- puts "--- Found attribute: #{attrib.name}"
- variables[attrib.name] = attrib.value
+ puts "--- Found attribute: #{attrib.name}"
+ variables[attrib.name] = attrib.value
end
# processes a namespace definition like <test xmlns:foo="fiz:bang:bam">
def handleNamespace( ctx, prefix, namespaces )
- puts "--- Found namespace: #{prefix}"
- namespaces[prefix] = ctx.namespaces[prefix]
+ puts "--- Found namespace: #{prefix}"
+ namespaces[prefix] = ctx.namespaces[prefix]
end
end
diff --git a/test/rexml/test_light.rb b/test/rexml/test_light.rb
index 8db8301..7ccf612 100644
--- a/test/rexml/test_light.rb
+++ b/test/rexml/test_light.rb
@@ -6,97 +6,97 @@ class LightTester < Test::Unit::TestCase
include REXMLTestUtils
include REXML::Light
- def test_parse_large
- parser = REXML::Parsers::LightParser.new(fixture_path("documentation.xml"))
- root = parser.parse
- end
-
- # FIXME INCOMPLETE
- # This is because the light API is not yet ready to be used to produce
- # trees.
+ def test_parse_large
+ parser = REXML::Parsers::LightParser.new(fixture_path("documentation.xml"))
+ root = parser.parse
+ end
+
+ # FIXME INCOMPLETE
+ # This is because the light API is not yet ready to be used to produce
+ # trees.
=begin
- def test_add_element
- doc = Node.new
- foo = doc.add_element( 'foo' )
- assert_equal( "foo", foo.name )
- end
-
- def test_add_attribute
- foo = Node.new( "a" )
- foo["attr"] = "bar"
- assert_equal( "bar", foo["attr"] )
- end
+ def test_add_element
+ doc = Node.new
+ foo = doc.add_element( 'foo' )
+ assert_equal( "foo", foo.name )
+ end
+
+ def test_add_attribute
+ foo = Node.new( "a" )
+ foo["attr"] = "bar"
+ assert_equal( "bar", foo["attr"] )
+ end
- def test_write_document
- r = make_small_document
- assert_equal( "<a><b/><c/></a>", r.to_s )
- end
+ def test_write_document
+ r = make_small_document
+ assert_equal( "<a><b/><c/></a>", r.to_s )
+ end
- def test_add_attribute_under_namespace
- foo = Node.new("a")
- foo["attr", "a"] = "1"
- foo["attr", "b"] = "2"
- foo["attr"] = "3"
- assert_equal( '1', foo['attr', 'a'] )
- assert_equal( '2', foo['attr', 'b'] )
- assert_equal( '3', foo['attr'] )
- end
+ def test_add_attribute_under_namespace
+ foo = Node.new("a")
+ foo["attr", "a"] = "1"
+ foo["attr", "b"] = "2"
+ foo["attr"] = "3"
+ assert_equal( '1', foo['attr', 'a'] )
+ assert_equal( '2', foo['attr', 'b'] )
+ assert_equal( '3', foo['attr'] )
+ end
- def test_change_namespace_of_element
- foo = Node.new
- assert_equal( '', foo.namespace )
- foo.namespace = 'a'
- assert_equal( 'a', foo.namespace )
- end
+ def test_change_namespace_of_element
+ foo = Node.new
+ assert_equal( '', foo.namespace )
+ foo.namespace = 'a'
+ assert_equal( 'a', foo.namespace )
+ end
- def test_access_child_elements
- foo = make_small_document
- assert_equal( 1, foo.size )
- a = foo[0]
- assert_equal( 2, a.size )
- assert_equal( 'b', a[0].name )
- assert_equal( 'c', a[1].name )
- end
+ def test_access_child_elements
+ foo = make_small_document
+ assert_equal( 1, foo.size )
+ a = foo[0]
+ assert_equal( 2, a.size )
+ assert_equal( 'b', a[0].name )
+ assert_equal( 'c', a[1].name )
+ end
- def test_itterate_over_children
- foo = make_small_document
- ctr = 0
- foo[0].each { ctr += 1 }
- assert_equal( 2, ctr )
- end
+ def test_itterate_over_children
+ foo = make_small_document
+ ctr = 0
+ foo[0].each { ctr += 1 }
+ assert_equal( 2, ctr )
+ end
- def test_add_text
- foo = Node.new( "a" )
- foo.add_text( "Sean" )
- sean = foo[0]
- assert( sean.node_type == :text )
- end
+ def test_add_text
+ foo = Node.new( "a" )
+ foo.add_text( "Sean" )
+ sean = foo[0]
+ assert( sean.node_type == :text )
+ end
- def test_add_instruction
- foo = Node.new( "a" )
- foo.add_instruction( "target", "value" )
- assert( foo[0].node_type == :processing_instruction )
- end
+ def test_add_instruction
+ foo = Node.new( "a" )
+ foo.add_instruction( "target", "value" )
+ assert( foo[0].node_type == :processing_instruction )
+ end
- def test_add_comment
- foo = Node.new( "a" )
- foo.add_comment( "target", "value" )
- assert( foo[0].node_type == :comment )
- end
+ def test_add_comment
+ foo = Node.new( "a" )
+ foo.add_comment( "target", "value" )
+ assert( foo[0].node_type == :comment )
+ end
- def test_get_root
- foo = Node.new( 'a' )
- 10.times { foo = foo.add_element('b') }
- assert_equals( 'b', foo.name )
- assert_equals( 'a', foo.root.name )
- end
+ def test_get_root
+ foo = Node.new( 'a' )
+ 10.times { foo = foo.add_element('b') }
+ assert_equals( 'b', foo.name )
+ assert_equals( 'a', foo.root.name )
+ end
- def make_small_document
- r = Node.new
- a = r.add_element( "a" )
- a.add_element( 'b' )
- a.add_element( 'c' )
- r
- end
+ def make_small_document
+ r = Node.new
+ a = r.add_element( "a" )
+ a.add_element( 'b' )
+ a.add_element( 'c' )
+ r
+ end
=end
end
diff --git a/test/rexml/test_lightparser.rb b/test/rexml/test_lightparser.rb
index e0d4423..ee33dc0 100644
--- a/test/rexml/test_lightparser.rb
+++ b/test/rexml/test_lightparser.rb
@@ -3,10 +3,10 @@ require 'rexml/parsers/lightparser'
class LightParserTester < Test::Unit::TestCase
include REXMLTestUtils
- include REXML
- def test_parsing
- f = File.new(fixture_path("documentation.xml"))
- parser = REXML::Parsers::LightParser.new( f )
- root = parser.parse
- end
+ include REXML
+ def test_parsing
+ f = File.new(fixture_path("documentation.xml"))
+ parser = REXML::Parsers::LightParser.new( f )
+ root = parser.parse
+ end
end
diff --git a/test/rexml/test_listener.rb b/test/rexml/test_listener.rb
index c9b49d9..f2cc4b7 100644
--- a/test/rexml/test_listener.rb
+++ b/test/rexml/test_listener.rb
@@ -7,96 +7,96 @@ require 'rexml/streamlistener'
class BaseTester < Test::Unit::TestCase
include REXMLTestUtils
- def test_empty
- return unless defined? @listener
- # Empty.
- t1 = %Q{<string></string>}
- assert_equal( "", @listener.parse( t1 ),
- "Empty" )
- end
-
- def test_space
- return unless defined? @listener
- # Space.
- t2 = %Q{<string> </string>}
- assert_equal( " ", @listener.parse( t2 ),
- "Space" )
- end
-
- def test_whitespace
- return unless defined? @listener
- # Whitespaces.
- t3 = %Q{<string>RE\n \t \n \t XML</string>}
- assert_equal( "RE\n \t \n \t XML", @listener.parse( t3 ),
- "Whitespaces" )
- end
-
- def test_leading_trailing_whitespace
- return unless defined? @listener
- # Leading and trailing whitespaces.
- t4 = %Q{<string> REXML </string>}
- assert_equal( " REXML ", @listener.parse( t4 ),
- "Leading and trailing whitespaces" )
- end
-
- def test_entity_reference
- return unless defined? @listener
- # Entity reference.
- t5 = %Q{<string>&lt;&gt;&amp;lt;&amp;gt;</string>}
- assert_equal( "<>&lt;&gt;", @listener.parse( t5 ),
- "Entity reference" )
- end
-
- def test_character_reference
- return unless defined? @listener
- # Character reference.
- t6 = %Q{<string>&#xd;</string>}
- assert_equal( "\r", @listener.parse( t6 ),
- "Character reference." )
- end
-
- def test_cr
- return unless defined? @listener
- # CR.
- t7 = %Q{<string> \r\n \r \n </string>}
- assert_equal( " \n \n \n ".unpack("C*").inspect,
- @listener.parse( t7 ).unpack("C*").inspect, "CR" )
- end
-
- # The accent bug, and the code that exibits the bug, was contributed by
- # Guilhem Vellut
- class AccentListener
- def tag_start(name,attributes)
- #p name
- #p attributes
- end
- def tag_end(name)
- #p "/"+name
- end
- def xmldecl(a,b,c)
- #puts "#{a} #{b} #{c}"
- end
- def text(tx)
- #p tx
- end
- end
-
- def test_accents
- source = '<?xml version="1.0" encoding="ISO-8859-1"?>
+ def test_empty
+ return unless defined? @listener
+ # Empty.
+ t1 = %Q{<string></string>}
+ assert_equal( "", @listener.parse( t1 ),
+ "Empty" )
+ end
+
+ def test_space
+ return unless defined? @listener
+ # Space.
+ t2 = %Q{<string> </string>}
+ assert_equal( " ", @listener.parse( t2 ),
+ "Space" )
+ end
+
+ def test_whitespace
+ return unless defined? @listener
+ # Whitespaces.
+ t3 = %Q{<string>RE\n \t \n \t XML</string>}
+ assert_equal( "RE\n \t \n \t XML", @listener.parse( t3 ),
+ "Whitespaces" )
+ end
+
+ def test_leading_trailing_whitespace
+ return unless defined? @listener
+ # Leading and trailing whitespaces.
+ t4 = %Q{<string> REXML </string>}
+ assert_equal( " REXML ", @listener.parse( t4 ),
+ "Leading and trailing whitespaces" )
+ end
+
+ def test_entity_reference
+ return unless defined? @listener
+ # Entity reference.
+ t5 = %Q{<string>&lt;&gt;&amp;lt;&amp;gt;</string>}
+ assert_equal( "<>&lt;&gt;", @listener.parse( t5 ),
+ "Entity reference" )
+ end
+
+ def test_character_reference
+ return unless defined? @listener
+ # Character reference.
+ t6 = %Q{<string>&#xd;</string>}
+ assert_equal( "\r", @listener.parse( t6 ),
+ "Character reference." )
+ end
+
+ def test_cr
+ return unless defined? @listener
+ # CR.
+ t7 = %Q{<string> \r\n \r \n </string>}
+ assert_equal( " \n \n \n ".unpack("C*").inspect,
+ @listener.parse( t7 ).unpack("C*").inspect, "CR" )
+ end
+
+ # The accent bug, and the code that exibits the bug, was contributed by
+ # Guilhem Vellut
+ class AccentListener
+ def tag_start(name,attributes)
+ #p name
+ #p attributes
+ end
+ def tag_end(name)
+ #p "/"+name
+ end
+ def xmldecl(a,b,c)
+ #puts "#{a} #{b} #{c}"
+ end
+ def text(tx)
+ #p tx
+ end
+ end
+
+ def test_accents
+ source = '<?xml version="1.0" encoding="ISO-8859-1"?>
<g>
<f a="é" />
</g>'
- doc = REXML::Document.new( source )
- a = doc.elements['/g/f'].attribute('a')
+ doc = REXML::Document.new( source )
+ a = doc.elements['/g/f'].attribute('a')
if a.value.respond_to? :force_encoding
a.value.force_encoding('binary')
end
- assert_equal( 'é', a.value)
- doc = REXML::Document.parse_stream(
- File::new(fixture_path("stream_accents.xml")),
- AccentListener::new
- )
- end
+ assert_equal( 'é', a.value)
+ doc = REXML::Document.parse_stream(
+ File::new(fixture_path("stream_accents.xml")),
+ AccentListener::new
+ )
+ end
end
class MyREXMLListener
@@ -118,12 +118,12 @@ class MyREXMLListener
end
class REXMLTester < BaseTester
- def setup
- @listener = MyREXMLListener.new
- end
-
- def test_character_reference_2
- t6 = %Q{<string>&#xd;</string>}
- assert_equal( t6.strip, REXML::Document.new(t6).to_s )
- end
+ def setup
+ @listener = MyREXMLListener.new
+ end
+
+ def test_character_reference_2
+ t6 = %Q{<string>&#xd;</string>}
+ assert_equal( t6.strip, REXML::Document.new(t6).to_s )
+ end
end
diff --git a/test/rexml/test_martin_fowler.rb b/test/rexml/test_martin_fowler.rb
index bdbf487..1b29c3d 100644
--- a/test/rexml/test_martin_fowler.rb
+++ b/test/rexml/test_martin_fowler.rb
@@ -2,6 +2,20 @@ require 'test/unit'
require 'rexml/document'
class OrderTester < Test::Unit::TestCase
+ DOC = <<END
+<paper>
+<title>Remove this element and figs order differently</title>
+<figure src="fig1"/>
+<figure src="fig2"/>
+<p>Para of text</p>
+<p>Remove this and figs order differently</p>
+<section>
+<figure src="fig3"/>
+</section>
+<figure src="fig4"/>
+</paper>
+END
+
def initialize n
@doc = REXML::Document.new(DOC)
@figs = REXML::XPath.match(@doc,'//figure')
@@ -21,18 +35,3 @@ class OrderTester < Test::Unit::TestCase
assert_equal 'fig4', @figs[3].attributes['src']
end
end
-
-
-DOC = <<END
-<paper>
-<title>Remove this element and figs order differently</title>
-<figure src="fig1"/>
-<figure src="fig2"/>
-<p>Para of text</p>
-<p>Remove this and figs order differently</p>
-<section>
-<figure src="fig3"/>
-</section>
-<figure src="fig4"/>
-</paper>
-END
diff --git a/test/rexml/test_preceding_sibling.rb b/test/rexml/test_preceding_sibling.rb
index c892b94..632e4da 100644
--- a/test/rexml/test_preceding_sibling.rb
+++ b/test/rexml/test_preceding_sibling.rb
@@ -2,8 +2,6 @@
require 'test/unit'
require 'rexml/document'
-p [REXML::VERSION, RUBY_VERSION, RUBY_RELEASE_DATE]
-
# daz - for report by Dan Kohn in:
# http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/156328
class XPathTesterDd < Test::Unit::TestCase
diff --git a/test/rexml/test_stream.rb b/test/rexml/test_stream.rb
index 4e3f0f7..2d9c177 100644
--- a/test/rexml/test_stream.rb
+++ b/test/rexml/test_stream.rb
@@ -32,7 +32,7 @@ class StreamTester < Test::Unit::TestCase
<!DOCTYPE foo [
<!ENTITY ent "replace">
<!ATTLIST a
- xmlns:human CDATA #FIXED "http://www.foo.com/human">
+ xmlns:human CDATA #FIXED "http://www.foo.com/human">
<!ELEMENT bar (#PCDATA)>
<!NOTATION n1 PUBLIC "-//HM//NOTATION TEST1//EN" 'urn:x-henrikmartensson.org:test5'>
]>
diff --git a/test/rexml/test_xpath.rb b/test/rexml/test_xpath.rb
index 119d4c2..f3a27cf 100644
--- a/test/rexml/test_xpath.rb
+++ b/test/rexml/test_xpath.rb
@@ -4,8 +4,8 @@ require "rexml/document"
class XPathTester < Test::Unit::TestCase
include REXMLTestUtils
- include REXML
- SOURCE = <<-EOF
+ include REXML
+ SOURCE = <<-EOF
<a id='1'>
<b id='2' x='y'>
<c id='3'/>
@@ -34,370 +34,370 @@ class XPathTester < Test::Unit::TestCase
</m>
</a>
EOF
- JENI_TENNISON = <<-EOJT
- <a>
- <b>
- <c>
- <d>
- <e id='x'>
- <f/>
- </e>
- </d>
- </c>
- <c>
- <d>
- <e id='y'/>
- </d>
- </c>
- </b>
- <b>
- <c>
- <d>
- <e id='z'/>
- </d>
- </c>
- </b>
- </a>
- EOJT
-
- def setup
- @@doc = Document.new(SOURCE) unless defined? @@doc
- @@jeni = Document.new( JENI_TENNISON ) unless defined? @@jeni
- end
-
- def each_test( element, xpath )
- count = 0
- XPath::each( element, xpath ) { |child|
- count += 1
- yield child if block_given?
- }
- count
- end
-
- def test_descendant
- doc = Document.new("<a><b><c id='1'/></b><d><b><c id='2'/></b></d></a>")
- p = XPath.match( doc, "//c" )
- assert_equal( 2, p.size )
- p = XPath.first( @@doc, "//p" )
- assert_equal "p", p.name
- c = each_test( @@doc, "//c" ) { |child| assert_equal "c", child.name }
- assert_equal 5, c
- c = each_test( @@doc.root, "b//c" ) { |child|
- assert_equal "c", child.name
- }
- assert_equal 2, c
-
- doc = Document.new( "<a><z id='1'/><b><z id='11'/><z id='12'/></b><c><z id='21'/><z id='22'/><d><z id='31'/><z id='32'/></d></c></a>" )
- # //para[1] : all descendants which are the first para child of their parent
- assert_equal( 4, XPath.match( doc, "//z[1]" ).size )
- # /descendant::para[1] : the first descendant para element
- assert_equal( 1, XPath.match( doc, "/descendant::z[1]" ).size )
- end
-
- def test_root
- source = "<a><b/></a>"
- doc = Document.new( source )
- assert_equal doc, doc.root_node
- assert_equal "a", XPath::first( doc, "/" ).elements[1].name
- end
-
- def test_abbreviated_simple_child
- assert_equal "a", XPath::first(@@doc, "a").name
- end
-
- def test_child
- c = XPath::first( @@doc, "a/b/c" )
- assert_equal "c", c.name
- assert_equal "3", XPath::first(@@doc, "a/b/c").attributes["id"]
- end
-
- def test_root_child
- assert_equal "a", XPath::first(@@doc, "/a").name
- c = XPath::first( @@doc, "a/b/c" )
- assert_equal "a", XPath::first(c, "/a").name
- end
-
- def test_root_children
- c = XPath::first( @@doc, "a/b/c" )
- assert_equal "2", XPath::first(c, "/a/b").attributes["id"]
- end
-
- def test_abbreviated_step
- c = XPath::first( @@doc, "a/b/c" )
+ JENI_TENNISON = <<-EOJT
+ <a>
+ <b>
+ <c>
+ <d>
+ <e id='x'>
+ <f/>
+ </e>
+ </d>
+ </c>
+ <c>
+ <d>
+ <e id='y'/>
+ </d>
+ </c>
+ </b>
+ <b>
+ <c>
+ <d>
+ <e id='z'/>
+ </d>
+ </c>
+ </b>
+ </a>
+ EOJT
+
+ def setup
+ @@doc = Document.new(SOURCE) unless defined? @@doc
+ @@jeni = Document.new( JENI_TENNISON ) unless defined? @@jeni
+ end
+
+ def each_test( element, xpath )
+ count = 0
+ XPath::each( element, xpath ) { |child|
+ count += 1
+ yield child if block_given?
+ }
+ count
+ end
+
+ def test_descendant
+ doc = Document.new("<a><b><c id='1'/></b><d><b><c id='2'/></b></d></a>")
+ p = XPath.match( doc, "//c" )
+ assert_equal( 2, p.size )
+ p = XPath.first( @@doc, "//p" )
+ assert_equal "p", p.name
+ c = each_test( @@doc, "//c" ) { |child| assert_equal "c", child.name }
+ assert_equal 5, c
+ c = each_test( @@doc.root, "b//c" ) { |child|
+ assert_equal "c", child.name
+ }
+ assert_equal 2, c
+
+ doc = Document.new( "<a><z id='1'/><b><z id='11'/><z id='12'/></b><c><z id='21'/><z id='22'/><d><z id='31'/><z id='32'/></d></c></a>" )
+ # //para[1] : all descendants which are the first para child of their parent
+ assert_equal( 4, XPath.match( doc, "//z[1]" ).size )
+ # /descendant::para[1] : the first descendant para element
+ assert_equal( 1, XPath.match( doc, "/descendant::z[1]" ).size )
+ end
+
+ def test_root
+ source = "<a><b/></a>"
+ doc = Document.new( source )
+ assert_equal doc, doc.root_node
+ assert_equal "a", XPath::first( doc, "/" ).elements[1].name
+ end
+
+ def test_abbreviated_simple_child
+ assert_equal "a", XPath::first(@@doc, "a").name
+ end
+
+ def test_child
+ c = XPath::first( @@doc, "a/b/c" )
+ assert_equal "c", c.name
+ assert_equal "3", XPath::first(@@doc, "a/b/c").attributes["id"]
+ end
+
+ def test_root_child
+ assert_equal "a", XPath::first(@@doc, "/a").name
+ c = XPath::first( @@doc, "a/b/c" )
+ assert_equal "a", XPath::first(c, "/a").name
+ end
+
+ def test_root_children
+ c = XPath::first( @@doc, "a/b/c" )
+ assert_equal "2", XPath::first(c, "/a/b").attributes["id"]
+ end
+
+ def test_abbreviated_step
+ c = XPath::first( @@doc, "a/b/c" )
assert_equal("c", c.name)
- assert_equal("a", XPath::first(@@doc.root, ".").name)
- assert_equal("b", XPath::first(c, "..").name)
- assert_equal("a", XPath::first(@@doc, "a/b/..").name)
-
- doc = REXML::Document.new(File.new(fixture_path("project.xml")))
- c = each_test(doc.root, "./Description" ) { |child|
- assert_equal("Description",child.name)
- }
- assert_equal 1, c
- end
-
- # Things that aren't tested elsewhere
- def test_predicates
- assert_equal "12", XPath::first(@@doc, "a/e/f[3]").attributes["id"]
- assert_equal "13", XPath::first(@@doc, "a/e/f[3]/g").attributes["id"]
- assert_equal "14", XPath::first(@@doc, "a/e/f[@a='d'][2]").attributes["id"]
- assert_equal "14", XPath::first(@@doc, "a/e/f[@a='d'][@id='14']").attributes["id"]
- assert_equal "a", XPath::first( @@doc, "*[name()='a' and @id='1']" ).name
- c=each_test( @@doc, "//*[name()='f' and @a='d']") { |i|
- assert_equal "f", i.name
- }
- assert_equal 2, c
- c=each_test( @@doc, "//*[name()='m' or @a='d']") { |i|
- assert ["m","f"].include?(i.name)
- }
- assert_equal 3, c
-
- assert_equal "b", XPath::first( @@doc, "//b[@x]" ).name
- end
-
- def test_node_type
- doc = Document.new "<a><?foo bar?><!--comment-->text</a>"
+ assert_equal("a", XPath::first(@@doc.root, ".").name)
+ assert_equal("b", XPath::first(c, "..").name)
+ assert_equal("a", XPath::first(@@doc, "a/b/..").name)
+
+ doc = REXML::Document.new(File.new(fixture_path("project.xml")))
+ c = each_test(doc.root, "./Description" ) { |child|
+ assert_equal("Description",child.name)
+ }
+ assert_equal 1, c
+ end
+
+ # Things that aren't tested elsewhere
+ def test_predicates
+ assert_equal "12", XPath::first(@@doc, "a/e/f[3]").attributes["id"]
+ assert_equal "13", XPath::first(@@doc, "a/e/f[3]/g").attributes["id"]
+ assert_equal "14", XPath::first(@@doc, "a/e/f[@a='d'][2]").attributes["id"]
+ assert_equal "14", XPath::first(@@doc, "a/e/f[@a='d'][@id='14']").attributes["id"]
+ assert_equal "a", XPath::first( @@doc, "*[name()='a' and @id='1']" ).name
+ c=each_test( @@doc, "//*[name()='f' and @a='d']") { |i|
+ assert_equal "f", i.name
+ }
+ assert_equal 2, c
+ c=each_test( @@doc, "//*[name()='m' or @a='d']") { |i|
+ assert ["m","f"].include?(i.name)
+ }
+ assert_equal 3, c
+
+ assert_equal "b", XPath::first( @@doc, "//b[@x]" ).name
+ end
+
+ def test_node_type
+ doc = Document.new "<a><?foo bar?><!--comment-->text</a>"
#res = XPath::first(doc.root, "text()")
#assert_equal "text", res.to_s
#res = XPath::first(doc, "*")
#assert_equal "a", res.name
- assert_equal( :processing_instruction,
+ assert_equal( :processing_instruction,
XPath::first(doc.root, "processing-instruction()").node_type)
- assert_equal( :comment, XPath::first(doc.root, "comment()").node_type)
- end
-
- def test_functions
- # trivial text() test
- # confuse-a-function
- source = "<a>more <b id='1'/><b id='2'>dumb</b><b id='3'/><c/> text</a>"
- doc = Document.new source
- res = ""
- #XPath::each(doc.root, "text()") {|val| res << val.to_s}
- #assert_equal "more text", res
-
- #res = XPath::first(doc.root, "b[last()]")
- #assert_equal '3', res.attributes['id']
- res = XPath::first(doc.root, "b[position()=2]")
- assert_equal '2', res.attributes['id']
- res = XPath::first(doc.root, "*[name()='c']")
- assert_equal "c", res.name
- end
-
- def no_test_ancestor
- doc = REXML::Document.new(File.new(fixture_path("testsrc.xml")))
- doc.elements.each("//item") { |el| print el.name
- if el.attributes['x']
- puts " -- "+el.attributes['x']
- else
- puts
- end
- }
- doc.elements.each("//item/ancestor::") { |el| print el.name
- if el.attributes['x']
- puts " -- "+el.attributes['x']
- else
- puts
- end
- }
- end
-
- # Here are some XPath tests that were originally submitted by ...
- # The code has changed some, but the logic and the source documents are the
- # same.
- # This method reads a document from a file, and then a series of xpaths,
- # also from a file. It then checks each xpath against the source file.
- def test_more
+ assert_equal( :comment, XPath::first(doc.root, "comment()").node_type)
+ end
+
+ def test_functions
+ # trivial text() test
+ # confuse-a-function
+ source = "<a>more <b id='1'/><b id='2'>dumb</b><b id='3'/><c/> text</a>"
+ doc = Document.new source
+ res = ""
+ #XPath::each(doc.root, "text()") {|val| res << val.to_s}
+ #assert_equal "more text", res
+
+ #res = XPath::first(doc.root, "b[last()]")
+ #assert_equal '3', res.attributes['id']
+ res = XPath::first(doc.root, "b[position()=2]")
+ assert_equal '2', res.attributes['id']
+ res = XPath::first(doc.root, "*[name()='c']")
+ assert_equal "c", res.name
+ end
+
+ def no_test_ancestor
+ doc = REXML::Document.new(File.new(fixture_path("testsrc.xml")))
+ doc.elements.each("//item") { |el| print el.name
+ if el.attributes['x']
+ puts " -- "+el.attributes['x']
+ else
+ puts
+ end
+ }
+ doc.elements.each("//item/ancestor::") { |el| print el.name
+ if el.attributes['x']
+ puts " -- "+el.attributes['x']
+ else
+ puts
+ end
+ }
+ end
+
+ # Here are some XPath tests that were originally submitted by ...
+ # The code has changed some, but the logic and the source documents are the
+ # same.
+ # This method reads a document from a file, and then a series of xpaths,
+ # also from a file. It then checks each xpath against the source file.
+ def test_more
xmlsource = fixture_path("testsrc.xml")
xpathtests = fixture_path("xp.tst")
- doc = REXML::Document.new(File.new(xmlsource))
- #results = ""
- results = REXML::Document.new
- results.add_element "test-results"
- for line in File.new(xpathtests)
- line.strip!
- begin
- rt = doc.root
- #puts "#"*80
- #print "\nDoing #{line} " ; $stdout.flush
- doc.elements.each(line) do |el|
- #print "." ; $stdout.flush
- results.root << el.clone
- #results << el.to_s
- end
- #ObjectSpace.garbage_collect
- GC::start
- rescue Exception => z
- #puts "\n'#{line}' failed"
- fail("Error on line #{line}:\n#{z.message}\n"+z.backtrace[0,10].join("\n"))
- #results.root.add_element( "error", {"path"=>line}).text = z.message+"\n"+z.backtrace[0,10].join("\n")
- #results << "<error path='"+line+"'>"+z.message+"</error>"
- end
- end
- end
-
- def test_axe_descendant
- assert_equal "f", XPath::first( @@doc, "descendant::f").name
- end
-
- def test_axe_parent
- q = XPath.first( @@doc, "a/d/c/parent::*/q" )
- assert_equal 19, q.attributes["id"].to_i
- end
-
- def test_abbreviated_attribute
- assert_equal 'a', XPath::first( @@doc, "a[@id='1']" ).name
- c = XPath::first( @@doc, "a/b/c[@id='4']" )
- assert_equal 'c', c.name
- assert_equal '4', c.attributes['id']
-
- result = XPath::first( @@doc, "descendant::f[@a='c']")
- assert_equal "11", result.attributes['id']
-
- assert_equal "11", XPath::first(@@doc, "a/e/f[@a='c']").attributes["id"]
- assert_equal "11", XPath::first(@@doc, "a/e/*[@a='c']").attributes["id"]
- end
-
- def test_axe_self
- c = XPath::first( @@doc, "a/b/c" )
- assert c
- assert_equal "c", c.name
- assert_equal "c", XPath::first( c, "self::node()" ).name
- end
-
- def test_axe_ancestor
- doc = REXML::Document.new "
- <a>
- <b id='1'>
- <c>
- <b id='2'>
- <d/>
- </b>
- </c>
- </b>
- </a>"
-
- d = XPath.first( doc, "//d" )
- assert_equal "d", d.name
- b = each_test( d, "ancestor::b" ) { |el|
- assert((1..2) === el.attributes['id'].to_i,
- "Expected #{el.attributes['id']} to be either 1 or 2"
- )
- }
- assert_equal 2, b
- end
-
- def test_axe_child
- m = XPath.first( @@doc, "a/child::m" )
- assert_equal 15, m.attributes['id'].to_i
- end
-
- def test_axe_attribute
- a = XPath.first( @@doc, "a/attribute::id" )
- assert_equal "1", a.value
- a = XPath.first( @@doc, "a/e/f[@id='14']/attribute::a" )
- assert_equal "d", a.value
- end
-
- def test_axe_sibling
- doc = Document.new "<a><b><c/></b><e><f id='10'/><f id='11'/><f id='12'/></e></a>"
- first_f = XPath.first( doc, "a/e/f" )
- assert first_f
- assert_equal '10', first_f.attributes['id']
- next_f = XPath.first( doc, "a/e/f/following-sibling::node()" )
- assert_equal '11', next_f.attributes['id']
-
- b = XPath.first( doc, "a/e/preceding-sibling::node()" )
- assert_equal 'b', b.name
- end
-
- def test_lang
- doc = Document.new(File.new(fixture_path("lang0.xml")))
- #puts IO.read( "test/lang.xml" )
-
- #puts XPath.match( doc, "//language/*" ).size
- c = each_test( doc, "//language/*" ) { |element|
- #puts "#{element.name}: #{element.text}"
- }
- assert_equal 4, c
- end
-
- def test_namespaces_1
- source = <<-EOF
- <foo xmlns:ts="this" xmlns:tt="that">
- <ts:bar>this bar</ts:bar>
- <tt:bar>that bar</tt:bar>
- </foo>
- EOF
- doc = Document.new source
- result = XPath.each( doc, "//bar" ) {
- fail "'bar' should match nothing in this case"
- }
-
- namespace = {"t"=>"this"}
- results = XPath.first( doc, "//t:bar", namespace )
- assert_equal "this bar", results.text
- end
-
- def test_namespaces_2
- source = <<-EOF
- <foo xmlns:ts="this" xmlns:tt="that">
- <ts:bar>this bar</ts:bar>
- <tt:bar>that bar</tt:bar>
- </foo>
- EOF
- doc = Document.new source
- res = XPath::first(doc, "//*[local_name()='bar']")
- assert res, "looking for //*[name()='bar']"
- assert_equal 'this', res.namespace
- res = XPath::first(doc.root, "*[namespace_uri()='that']")
- assert_equal 'that bar', res.text
- end
-
- def test_complex
- next_f = XPath.first( @@doc, "a/e/f[@id='11']/following-sibling::*" )
- assert_equal 12, next_f.attributes['id'].to_i
- prev_f = XPath.first( @@doc, "a/e/f[@id='11']/preceding-sibling::*" )
- assert_equal 10, prev_f.attributes['id'].to_i
- c = each_test( @@doc, "descendant-or-self::*[@x='y']" )
- assert_equal 2, c
- end
-
- def test_grouping
+ doc = REXML::Document.new(File.new(xmlsource))
+ #results = ""
+ results = REXML::Document.new
+ results.add_element "test-results"
+ for line in File.new(xpathtests)
+ line.strip!
+ begin
+ rt = doc.root
+ #puts "#"*80
+ #print "\nDoing #{line} " ; $stdout.flush
+ doc.elements.each(line) do |el|
+ #print "." ; $stdout.flush
+ results.root << el.clone
+ #results << el.to_s
+ end
+ #ObjectSpace.garbage_collect
+ GC::start
+ rescue Exception => z
+ #puts "\n'#{line}' failed"
+ fail("Error on line #{line}:\n#{z.message}\n"+z.backtrace[0,10].join("\n"))
+ #results.root.add_element( "error", {"path"=>line}).text = z.message+"\n"+z.backtrace[0,10].join("\n")
+ #results << "<error path='"+line+"'>"+z.message+"</error>"
+ end
+ end
+ end
+
+ def test_axe_descendant
+ assert_equal "f", XPath::first( @@doc, "descendant::f").name
+ end
+
+ def test_axe_parent
+ q = XPath.first( @@doc, "a/d/c/parent::*/q" )
+ assert_equal 19, q.attributes["id"].to_i
+ end
+
+ def test_abbreviated_attribute
+ assert_equal 'a', XPath::first( @@doc, "a[@id='1']" ).name
+ c = XPath::first( @@doc, "a/b/c[@id='4']" )
+ assert_equal 'c', c.name
+ assert_equal '4', c.attributes['id']
+
+ result = XPath::first( @@doc, "descendant::f[@a='c']")
+ assert_equal "11", result.attributes['id']
+
+ assert_equal "11", XPath::first(@@doc, "a/e/f[@a='c']").attributes["id"]
+ assert_equal "11", XPath::first(@@doc, "a/e/*[@a='c']").attributes["id"]
+ end
+
+ def test_axe_self
+ c = XPath::first( @@doc, "a/b/c" )
+ assert c
+ assert_equal "c", c.name
+ assert_equal "c", XPath::first( c, "self::node()" ).name
+ end
+
+ def test_axe_ancestor
+ doc = REXML::Document.new "
+ <a>
+ <b id='1'>
+ <c>
+ <b id='2'>
+ <d/>
+ </b>
+ </c>
+ </b>
+ </a>"
+
+ d = XPath.first( doc, "//d" )
+ assert_equal "d", d.name
+ b = each_test( d, "ancestor::b" ) { |el|
+ assert((1..2) === el.attributes['id'].to_i,
+ "Expected #{el.attributes['id']} to be either 1 or 2"
+ )
+ }
+ assert_equal 2, b
+ end
+
+ def test_axe_child
+ m = XPath.first( @@doc, "a/child::m" )
+ assert_equal 15, m.attributes['id'].to_i
+ end
+
+ def test_axe_attribute
+ a = XPath.first( @@doc, "a/attribute::id" )
+ assert_equal "1", a.value
+ a = XPath.first( @@doc, "a/e/f[@id='14']/attribute::a" )
+ assert_equal "d", a.value
+ end
+
+ def test_axe_sibling
+ doc = Document.new "<a><b><c/></b><e><f id='10'/><f id='11'/><f id='12'/></e></a>"
+ first_f = XPath.first( doc, "a/e/f" )
+ assert first_f
+ assert_equal '10', first_f.attributes['id']
+ next_f = XPath.first( doc, "a/e/f/following-sibling::node()" )
+ assert_equal '11', next_f.attributes['id']
+
+ b = XPath.first( doc, "a/e/preceding-sibling::node()" )
+ assert_equal 'b', b.name
+ end
+
+ def test_lang
+ doc = Document.new(File.new(fixture_path("lang0.xml")))
+ #puts IO.read( "test/lang.xml" )
+
+ #puts XPath.match( doc, "//language/*" ).size
+ c = each_test( doc, "//language/*" ) { |element|
+ #puts "#{element.name}: #{element.text}"
+ }
+ assert_equal 4, c
+ end
+
+ def test_namespaces_1
+ source = <<-EOF
+ <foo xmlns:ts="this" xmlns:tt="that">
+ <ts:bar>this bar</ts:bar>
+ <tt:bar>that bar</tt:bar>
+ </foo>
+ EOF
+ doc = Document.new source
+ result = XPath.each( doc, "//bar" ) {
+ fail "'bar' should match nothing in this case"
+ }
+
+ namespace = {"t"=>"this"}
+ results = XPath.first( doc, "//t:bar", namespace )
+ assert_equal "this bar", results.text
+ end
+
+ def test_namespaces_2
+ source = <<-EOF
+ <foo xmlns:ts="this" xmlns:tt="that">
+ <ts:bar>this bar</ts:bar>
+ <tt:bar>that bar</tt:bar>
+ </foo>
+ EOF
+ doc = Document.new source
+ res = XPath::first(doc, "//*[local_name()='bar']")
+ assert res, "looking for //*[name()='bar']"
+ assert_equal 'this', res.namespace
+ res = XPath::first(doc.root, "*[namespace_uri()='that']")
+ assert_equal 'that bar', res.text
+ end
+
+ def test_complex
+ next_f = XPath.first( @@doc, "a/e/f[@id='11']/following-sibling::*" )
+ assert_equal 12, next_f.attributes['id'].to_i
+ prev_f = XPath.first( @@doc, "a/e/f[@id='11']/preceding-sibling::*" )
+ assert_equal 10, prev_f.attributes['id'].to_i
+ c = each_test( @@doc, "descendant-or-self::*[@x='y']" )
+ assert_equal 2, c
+ end
+
+ def test_grouping
t = XPath.first( @@doc, "a/d/*[name()='d' and (name()='f' or name()='q')]" )
assert_nil t
- t = XPath.first( @@doc, "a/d/*[(name()='d' and name()='f') or name()='q']" )
- assert_equal 'q', t.name
- end
+ t = XPath.first( @@doc, "a/d/*[(name()='d' and name()='f') or name()='q']" )
+ assert_equal 'q', t.name
+ end
- def test_preceding
+ def test_preceding
d = Document.new "<a><b id='0'/><b id='2'/><b><c id='0'/><c id='1'/><c id='2'/></b><b id='1'/></a>"
- start = XPath.first( d, "/a/b[@id='1']" )
+ start = XPath.first( d, "/a/b[@id='1']" )
assert_equal 'b', start.name
- c = XPath.first( start, "preceding::c" )
- assert_equal '2', c.attributes['id']
+ c = XPath.first( start, "preceding::c" )
+ assert_equal '2', c.attributes['id']
- c1, c0 = XPath.match( d, "/a/b/c[@id='2']/preceding::node()" )
- assert_equal '1', c1.attributes['id']
- assert_equal '0', c0.attributes['id']
+ c1, c0 = XPath.match( d, "/a/b/c[@id='2']/preceding::node()" )
+ assert_equal '1', c1.attributes['id']
+ assert_equal '0', c0.attributes['id']
c2, c1, c0, b, b2, b0 = XPath.match( start, "preceding::node()" )
- assert_equal 'c', c2.name
- assert_equal 'c', c1.name
- assert_equal 'c', c0.name
- assert_equal 'b', b.name
- assert_equal 'b', b2.name
- assert_equal 'b', b0.name
+ assert_equal 'c', c2.name
+ assert_equal 'c', c1.name
+ assert_equal 'c', c0.name
+ assert_equal 'b', b.name
+ assert_equal 'b', b2.name
+ assert_equal 'b', b0.name
- assert_equal '2', c2.attributes['id']
- assert_equal '1', c1.attributes['id']
- assert_equal '0', c0.attributes['id']
- assert b.attributes.empty?
- assert_equal '2', b2.attributes['id']
- assert_equal '0', b0.attributes['id']
+ assert_equal '2', c2.attributes['id']
+ assert_equal '1', c1.attributes['id']
+ assert_equal '0', c0.attributes['id']
+ assert b.attributes.empty?
+ assert_equal '2', b2.attributes['id']
+ assert_equal '0', b0.attributes['id']
d = REXML::Document.new("<a><b/><c/><d/></a>")
matches = REXML::XPath.match(d, "/a/d/preceding::node()")
@@ -409,9 +409,9 @@ class XPathTester < Test::Unit::TestCase
c = REXML::XPath.match( d, "//c[@id = '5']")
cs = REXML::XPath.match( c, "preceding::c" )
assert_equal( 4, cs.length )
- end
+ end
- def test_following
+ def test_following
d = Document.new "<a><b id='0'/><b/><b><c id='1'/><c id='2'/></b><b id='1'/></a>"
start = XPath.first( d, "/a/b[@id='0']" )
assert_equal 'b', start.name
@@ -426,118 +426,118 @@ class XPathTester < Test::Unit::TestCase
assert_equal 6, res.size
res = XPath.match( c, 'following::i' )
assert_equal 2, res.size
- end
-
- # The following three paths were provided by
- # Jeni Tennison <jeni@jenitennison.com>
- # a consultant who is also an XSL and XPath expert
- #def test_child_cubed
- # els = @@jeni.elements.to_a("*****")
- # assert_equal 3, els.size
- #end
-
- #def test_div_2
- # results = doc.elements.to_a("/ div 2")
- #end
-
- #def test_nested_predicates
- # puts @@jeni.root.elements[1].elements[1].name
- # results = @@jeni.root.elements[1].elements[1].elements.to_a("../following-sibling::*[*[name() = name(current())]]")
- # puts results
- #end
+ end
+
+ # The following three paths were provided by
+ # Jeni Tennison <jeni@jenitennison.com>
+ # a consultant who is also an XSL and XPath expert
+ #def test_child_cubed
+ # els = @@jeni.elements.to_a("*****")
+ # assert_equal 3, els.size
+ #end
+
+ #def test_div_2
+ # results = doc.elements.to_a("/ div 2")
+ #end
+
+ #def test_nested_predicates
+ # puts @@jeni.root.elements[1].elements[1].name
+ # results = @@jeni.root.elements[1].elements[1].elements.to_a("../following-sibling::*[*[name() = name(current())]]")
+ # puts results
+ #end
- # Contributed by Mike Stok
- def test_starts_with
- source = <<-EOF
- <foo>
- <a href="mailto:a@b.c">a@b.c</a>
- <a href="http://www.foo.com">http://www.foo.com</a>
- </foo>
- EOF
- doc = Document.new source
- mailtos = doc.elements.to_a("//a[starts-with(@href, 'mailto:')]")
- assert_equal 1, mailtos.size
- assert_equal "mailto:a@b.c", mailtos[0].attributes['href']
-
- ailtos = doc.elements.to_a("//a[starts-with(@href, 'ailto:')]")
- assert_equal 0, ailtos.size
- end
-
- def test_toms_text_node
- file = "<a>A<b>B</b><c>C<d>D</d>E</c>F</a>"
- doc = Document.new(file)
+ # Contributed by Mike Stok
+ def test_starts_with
+ source = <<-EOF
+ <foo>
+ <a href="mailto:a@b.c">a@b.c</a>
+ <a href="http://www.foo.com">http://www.foo.com</a>
+ </foo>
+ EOF
+ doc = Document.new source
+ mailtos = doc.elements.to_a("//a[starts-with(@href, 'mailto:')]")
+ assert_equal 1, mailtos.size
+ assert_equal "mailto:a@b.c", mailtos[0].attributes['href']
+
+ ailtos = doc.elements.to_a("//a[starts-with(@href, 'ailto:')]")
+ assert_equal 0, ailtos.size
+ end
+
+ def test_toms_text_node
+ file = "<a>A<b>B</b><c>C<d>D</d>E</c>F</a>"
+ doc = Document.new(file)
assert_equal 'A', XPath.first(doc[0], 'text()').to_s
- assert_equal 'AF', XPath.match(doc[0], 'text()').collect { |n|
- n.to_s
- }.join('')
- assert_equal 'B', XPath.first(doc[0], 'b/text()').to_s
- assert_equal 'D', XPath.first(doc[0], '//d/text()').to_s
- assert_equal 'ABCDEF', XPath.match(doc[0], '//text()').collect {|n|
- n.to_s
- }.join('')
- end
+ assert_equal 'AF', XPath.match(doc[0], 'text()').collect { |n|
+ n.to_s
+ }.join('')
+ assert_equal 'B', XPath.first(doc[0], 'b/text()').to_s
+ assert_equal 'D', XPath.first(doc[0], '//d/text()').to_s
+ assert_equal 'ABCDEF', XPath.match(doc[0], '//text()').collect {|n|
+ n.to_s
+ }.join('')
+ end
def test_string_length
- doc = Document.new <<-EOF
- <AAA>
- <Q/>
- <SSSS/>
- <BB/>
- <CCC/>
- <DDDDDDDD/>
- <EEEE/>
- </AAA>
- EOF
- assert doc, "create doc"
-
- set = doc.elements.to_a("//*[string-length(name()) = 3]")
- assert_equal 2, set.size, "nodes with names length = 3"
-
- set = doc.elements.to_a("//*[string-length(name()) < 3]")
- assert_equal 2, set.size, "nodes with names length < 3"
-
- set = doc.elements.to_a("//*[string-length(name()) > 3]")
- assert_equal 3, set.size, "nodes with names length > 3"
- end
-
- # Test provided by Mike Stok
- def test_contains
- source = <<-EOF
- <foo>
- <a href="mailto:a@b.c">a@b.c</a>
- <a href="http://www.foo.com">http://www.foo.com</a>
- </foo>
- EOF
- doc = Document.new source
-
- [
+ doc = Document.new <<-EOF
+ <AAA>
+ <Q/>
+ <SSSS/>
+ <BB/>
+ <CCC/>
+ <DDDDDDDD/>
+ <EEEE/>
+ </AAA>
+ EOF
+ assert doc, "create doc"
+
+ set = doc.elements.to_a("//*[string-length(name()) = 3]")
+ assert_equal 2, set.size, "nodes with names length = 3"
+
+ set = doc.elements.to_a("//*[string-length(name()) < 3]")
+ assert_equal 2, set.size, "nodes with names length < 3"
+
+ set = doc.elements.to_a("//*[string-length(name()) > 3]")
+ assert_equal 3, set.size, "nodes with names length > 3"
+ end
+
+ # Test provided by Mike Stok
+ def test_contains
+ source = <<-EOF
+ <foo>
+ <a href="mailto:a@b.c">a@b.c</a>
+ <a href="http://www.foo.com">http://www.foo.com</a>
+ </foo>
+ EOF
+ doc = Document.new source
+
+ [
#['o', 2],
['foo', 1], ['bar', 0]].each { |search, expected|
- set = doc.elements.to_a("//a[contains(@href, '#{search}')]")
- assert_equal expected, set.size
- }
- end
-
- # Mike Stok and Sean Russell
- def test_substring
- # examples from http://www.w3.org/TR/xpath#function-substring
- doc = Document.new('<test string="12345" />')
-
- d = Document.new("<a b='1'/>")
- #puts XPath.first(d, 'node()[0 + 1]')
- #d = Document.new("<a b='1'/>")
- #puts XPath.first(d, 'a[0 mod 0]')
- [ [1.5, 2.6, '234'],
- [0, 3, '12'],
- [0, '0 div 0', ''],
- [1, '0 div 0', ''],
- ['-42', '1 div 0', '12345'],
- ['-1 div 0', '1 div 0', '']
- ].each { |start, length, expected|
- set = doc.elements.to_a("//test[substring(@string, #{start}, #{length}) = '#{expected}']")
- assert_equal 1, set.size, "#{start}, #{length}, '#{expected}'"
- }
- end
+ set = doc.elements.to_a("//a[contains(@href, '#{search}')]")
+ assert_equal expected, set.size
+ }
+ end
+
+ # Mike Stok and Sean Russell
+ def test_substring
+ # examples from http://www.w3.org/TR/xpath#function-substring
+ doc = Document.new('<test string="12345" />')
+
+ d = Document.new("<a b='1'/>")
+ #puts XPath.first(d, 'node()[0 + 1]')
+ #d = Document.new("<a b='1'/>")
+ #puts XPath.first(d, 'a[0 mod 0]')
+ [ [1.5, 2.6, '234'],
+ [0, 3, '12'],
+ [0, '0 div 0', ''],
+ [1, '0 div 0', ''],
+ ['-42', '1 div 0', '12345'],
+ ['-1 div 0', '1 div 0', '']
+ ].each { |start, length, expected|
+ set = doc.elements.to_a("//test[substring(@string, #{start}, #{length}) = '#{expected}']")
+ assert_equal 1, set.size, "#{start}, #{length}, '#{expected}'"
+ }
+ end
def test_translate
source = <<-EOF
@@ -565,138 +565,138 @@ class XPathTester < Test::Unit::TestCase
}
end
- def test_math
- d = Document.new( '<a><b/><c/></a>' )
+ def test_math
+ d = Document.new( '<a><b/><c/></a>' )
assert XPath.first( d.root, 'node()[1]' )
- assert_equal 'b', XPath.first( d.root, 'node()[1]' ).name
- assert XPath.first( d.root, 'node()[0 + 1]' )
- assert_equal 'b', XPath.first( d.root, './node()[0 + 1]' ).name
- assert XPath.first( d.root, 'node()[1 + 1]' )
- assert_equal 'c', XPath.first( d.root, './node()[1 + 1]' ).name
- assert XPath.first( d.root, 'node()[4 div 2]' )
- assert_equal 'c', XPath.first( d.root, './node()[4 div 2]' ).name
- assert XPath.first( d.root, 'node()[2 - 1]' )
- assert_equal 'b', XPath.first( d.root, './node()[2 - 1]' ).name
- assert XPath.first( d.root, 'node()[5 mod 2]' )
- assert_equal 'b', XPath.first( d.root, './node()[5 mod 2]' ).name
- assert XPath.first( d.root, 'node()[8 mod 3]' )
- assert_equal 'c', XPath.first( d.root, './node()[8 mod 3]' ).name
- assert XPath.first( d.root, 'node()[1 * 2]' )
- assert_equal 'c', XPath.first( d.root, './node()[1 * 2]' ).name
- assert XPath.first( d.root, 'node()[2 + -1]' )
- assert_equal 'b', XPath.first( d.root, './node()[2 + -1]' ).name
- end
-
- def test_name
+ assert_equal 'b', XPath.first( d.root, 'node()[1]' ).name
+ assert XPath.first( d.root, 'node()[0 + 1]' )
+ assert_equal 'b', XPath.first( d.root, './node()[0 + 1]' ).name
+ assert XPath.first( d.root, 'node()[1 + 1]' )
+ assert_equal 'c', XPath.first( d.root, './node()[1 + 1]' ).name
+ assert XPath.first( d.root, 'node()[4 div 2]' )
+ assert_equal 'c', XPath.first( d.root, './node()[4 div 2]' ).name
+ assert XPath.first( d.root, 'node()[2 - 1]' )
+ assert_equal 'b', XPath.first( d.root, './node()[2 - 1]' ).name
+ assert XPath.first( d.root, 'node()[5 mod 2]' )
+ assert_equal 'b', XPath.first( d.root, './node()[5 mod 2]' ).name
+ assert XPath.first( d.root, 'node()[8 mod 3]' )
+ assert_equal 'c', XPath.first( d.root, './node()[8 mod 3]' ).name
+ assert XPath.first( d.root, 'node()[1 * 2]' )
+ assert_equal 'c', XPath.first( d.root, './node()[1 * 2]' ).name
+ assert XPath.first( d.root, 'node()[2 + -1]' )
+ assert_equal 'b', XPath.first( d.root, './node()[2 + -1]' ).name
+ end
+
+ def test_name
assert_raise( UndefinedNamespaceException, "x should be undefined" ) {
d = REXML::Document.new("<a x='foo'><b/><x:b/></a>")
}
- d = REXML::Document.new("<a xmlns:x='foo'><b/><x:b/></a>")
- assert_equal 1, d.root.elements.to_a('*[name() = "b"]').size
- assert_equal 1, d.elements.to_a('//*[name() = "x:b"]').size
- end
-
- def test_local_name
- d = REXML::Document.new("<a xmlns:x='foo'><b/><x:b/></a>")
- assert_equal 2, d.root.elements.to_a('*[local_name() = "b"]').size
- assert_equal 2, d.elements.to_a('//*[local_name() = "b"]').size
- end
-
- def test_comparisons
- source = "<a><b id='1'/><b id='2'/><b id='3'/></a>"
- doc = REXML::Document.new(source)
-
- # NOTE TO SER: check that number() is required
- assert_equal 2, REXML::XPath.match(doc, "//b[number(@id) > 1]").size
- assert_equal 3, REXML::XPath.match(doc, "//b[number(@id) >= 1]").size
- assert_equal 1, REXML::XPath.match(doc, "//b[number(@id) <= 1]").size
- assert_equal 1, REXML::XPath.match(doc, "//b[number(@id) = (1 * 1)]").size
- assert_equal 1, REXML::XPath.match(doc, "//b[number(@id) = (1 mod 2)]").size
- assert_equal 1, REXML::XPath.match(doc, "//b[number(@id) = (4 div 2)]").size
- end
-
- # Contributed by Kouhei
- def test_substring_before
- doc = Document.new("<r><a/><b/><c/></r>")
- assert_equal("a", doc.root.elements.to_a("*[name()=substring-before('abc', 'b')]")[0].name)
- assert_equal("c", doc.root.elements.to_a("*[name()=substring-after('abc', 'b')]")[0].name)
- end
-
- def test_spaces
- doc = Document.new("<a>
- <b>
- <c id='a'/>
- </b>
- <c id='b'/>
- </a>")
+ d = REXML::Document.new("<a xmlns:x='foo'><b/><x:b/></a>")
+ assert_equal 1, d.root.elements.to_a('*[name() = "b"]').size
+ assert_equal 1, d.elements.to_a('//*[name() = "x:b"]').size
+ end
+
+ def test_local_name
+ d = REXML::Document.new("<a xmlns:x='foo'><b/><x:b/></a>")
+ assert_equal 2, d.root.elements.to_a('*[local_name() = "b"]').size
+ assert_equal 2, d.elements.to_a('//*[local_name() = "b"]').size
+ end
+
+ def test_comparisons
+ source = "<a><b id='1'/><b id='2'/><b id='3'/></a>"
+ doc = REXML::Document.new(source)
+
+ # NOTE TO SER: check that number() is required
+ assert_equal 2, REXML::XPath.match(doc, "//b[number(@id) > 1]").size
+ assert_equal 3, REXML::XPath.match(doc, "//b[number(@id) >= 1]").size
+ assert_equal 1, REXML::XPath.match(doc, "//b[number(@id) <= 1]").size
+ assert_equal 1, REXML::XPath.match(doc, "//b[number(@id) = (1 * 1)]").size
+ assert_equal 1, REXML::XPath.match(doc, "//b[number(@id) = (1 mod 2)]").size
+ assert_equal 1, REXML::XPath.match(doc, "//b[number(@id) = (4 div 2)]").size
+ end
+
+ # Contributed by Kouhei
+ def test_substring_before
+ doc = Document.new("<r><a/><b/><c/></r>")
+ assert_equal("a", doc.root.elements.to_a("*[name()=substring-before('abc', 'b')]")[0].name)
+ assert_equal("c", doc.root.elements.to_a("*[name()=substring-after('abc', 'b')]")[0].name)
+ end
+
+ def test_spaces
+ doc = Document.new("<a>
+ <b>
+ <c id='a'/>
+ </b>
+ <c id='b'/>
+ </a>")
+ assert_equal( 1, REXML::XPath.match(doc,
+ "//*[local-name()='c' and @id='b']").size )
+ assert_equal( 1, REXML::XPath.match(doc,
+ "//*[ local-name()='c' and @id='b' ]").size )
assert_equal( 1, REXML::XPath.match(doc,
- "//*[local-name()='c' and @id='b']").size )
- assert_equal( 1, REXML::XPath.match(doc,
- "//*[ local-name()='c' and @id='b' ]").size )
- assert_equal( 1, REXML::XPath.match(doc,
- "//*[ local-name() = 'c' and @id = 'b' ]").size )
- assert_equal( 1,
- REXML::XPath.match(doc, '/a/c[@id]').size )
- assert_equal( 1,
- REXML::XPath.match(doc, '/a/c[(@id)]').size )
- assert_equal( 1,
- REXML::XPath.match(doc, '/a/c[ @id ]').size )
- assert_equal( 1,
- REXML::XPath.match(doc, '/a/c[ (@id) ]').size )
- assert_equal( 1,
- REXML::XPath.match(doc, '/a/c[( @id )]').size )
- assert_equal( 1, REXML::XPath.match(doc.root,
- '/a/c[ ( @id ) ]').size )
- assert_equal( 1, REXML::XPath.match(doc,
- '/a/c [ ( @id ) ] ').size )
- assert_equal( 1, REXML::XPath.match(doc,
- ' / a / c [ ( @id ) ] ').size )
- end
-
- def test_text_nodes
- # source = "<root>
- #<child/>
- #<child>test</child>
- #</root>"
- source = "<root><child>test</child></root>"
- d = REXML::Document.new( source )
- r = REXML::XPath.match( d, %q{/root/child[text()="test"]} )
- assert_equal( 1, r.size )
- assert_equal( "child", r[0].name )
- assert_equal( "test", r[0].text )
- end
-
- def test_auto_string_value
- source = "<root><foo/><title>Introduction</title></root>"
- d = REXML::Document.new( source )
- #r = REXML::XPath.match( d, %q{/root[title="Introduction"]} )
- #assert_equal( 1, r.size )
- source = "<a><b/><c/><c>test</c></a>"
- d = REXML::Document.new( source )
- r = REXML::XPath.match( d, %q{/a[c='test']} )
- assert_equal( 1, r.size )
- r = REXML::XPath.match( d, %q{a[c='test']} )
- assert_equal( 1, r.size )
- r = d.elements["/a[c='test']"]
- assert_not_nil( r )
- r = d.elements["a[c='test']"]
- assert_not_nil( r )
+ "//*[ local-name() = 'c' and @id = 'b' ]").size )
+ assert_equal( 1,
+ REXML::XPath.match(doc, '/a/c[@id]').size )
+ assert_equal( 1,
+ REXML::XPath.match(doc, '/a/c[(@id)]').size )
+ assert_equal( 1,
+ REXML::XPath.match(doc, '/a/c[ @id ]').size )
+ assert_equal( 1,
+ REXML::XPath.match(doc, '/a/c[ (@id) ]').size )
+ assert_equal( 1,
+ REXML::XPath.match(doc, '/a/c[( @id )]').size )
+ assert_equal( 1, REXML::XPath.match(doc.root,
+ '/a/c[ ( @id ) ]').size )
+ assert_equal( 1, REXML::XPath.match(doc,
+ '/a/c [ ( @id ) ] ').size )
+ assert_equal( 1, REXML::XPath.match(doc,
+ ' / a / c [ ( @id ) ] ').size )
+ end
+
+ def test_text_nodes
+ # source = "<root>
+ #<child/>
+ #<child>test</child>
+ #</root>"
+ source = "<root><child>test</child></root>"
+ d = REXML::Document.new( source )
+ r = REXML::XPath.match( d, %q{/root/child[text()="test"]} )
+ assert_equal( 1, r.size )
+ assert_equal( "child", r[0].name )
+ assert_equal( "test", r[0].text )
+ end
+
+ def test_auto_string_value
+ source = "<root><foo/><title>Introduction</title></root>"
+ d = REXML::Document.new( source )
+ #r = REXML::XPath.match( d, %q{/root[title="Introduction"]} )
+ #assert_equal( 1, r.size )
+ source = "<a><b/><c/><c>test</c></a>"
+ d = REXML::Document.new( source )
+ r = REXML::XPath.match( d, %q{/a[c='test']} )
+ assert_equal( 1, r.size )
+ r = REXML::XPath.match( d, %q{a[c='test']} )
+ assert_equal( 1, r.size )
+ r = d.elements["/a[c='test']"]
+ assert_not_nil( r )
+ r = d.elements["a[c='test']"]
+ assert_not_nil( r )
r = d.elements["a[c='xtest']"]
assert_nil( r )
r = REXML::XPath.match( d, %q{a[c='xtest']} )
assert_equal( 0, r.size )
- end
+ end
- def test_ordering
- source = "<a><b><c id='1'/><c id='2'/></b><b><d id='1'/><d id='2'/></b></a>"
- d = REXML::Document.new( source )
- r = REXML::XPath.match( d, %q{/a/*/*[1]} )
- assert_equal( 1, r.size )
- r.each { |el| assert_equal( '1', el.attribute('id').value ) }
- end
+ def test_ordering
+ source = "<a><b><c id='1'/><c id='2'/></b><b><d id='1'/><d id='2'/></b></a>"
+ d = REXML::Document.new( source )
+ r = REXML::XPath.match( d, %q{/a/*/*[1]} )
+ assert_equal( 1, r.size )
+ r.each { |el| assert_equal( '1', el.attribute('id').value ) }
+ end
def test_descendant_or_self_ordering
- source = "<a>
+ source = "<a>
<b>
<c id='1'/>
<c id='2'/>
diff --git a/test/rexml/test_xpath_attribute_query.rb b/test/rexml/test_xpath_attribute_query.rb
index 8d5102b..99439f2 100644
--- a/test/rexml/test_xpath_attribute_query.rb
+++ b/test/rexml/test_xpath_attribute_query.rb
@@ -10,39 +10,39 @@ class TestRexmlXpathAttributeQuery < Test::Unit::TestCase
# xmlstr1 and xmlstr2 only differ in the second line - namespaces in the root element
@@xmlstr1 = '<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/" xmlns:gd="http://schemas.google.com/g/2005" xmlns:gCal="http://schemas.google.com/gCal/2005">
- <id>http://www.google.com/calendar/feeds/me%40gmail.com</id>
- <entry>
- <id>http://www.google.com/calendar/feeds/me%40gmail.com/me%40gmail.com</id>
- <published>2007-05-16T13:42:27.942Z</published>
- <updated>2007-05-15T03:29:28.000Z</updated>
- <title type="text">My Calendar</title>
- <link rel="alternate" type="application/atom+xml" href="http://www.google.com/calendar/feeds/me%40gmail.com/private/full"/>
- <link rel="http://schemas.google.com/acl/2007#accessControlList" type="application/atom+xml" href="http://www.google.com/calendar/feeds/me%40gmail.com/acl/full"/>
- <link rel="self" type="application/atom+xml" href="http://www.google.com/calendar/feeds/me%40gmail.com/me%40gmail.com"/>
- <author>
- <name>Me</name>
- <email>me@gmail.com</email>
- </author>
- </entry>
+ <id>http://www.google.com/calendar/feeds/me%40gmail.com</id>
+ <entry>
+ <id>http://www.google.com/calendar/feeds/me%40gmail.com/me%40gmail.com</id>
+ <published>2007-05-16T13:42:27.942Z</published>
+ <updated>2007-05-15T03:29:28.000Z</updated>
+ <title type="text">My Calendar</title>
+ <link rel="alternate" type="application/atom+xml" href="http://www.google.com/calendar/feeds/me%40gmail.com/private/full"/>
+ <link rel="http://schemas.google.com/acl/2007#accessControlList" type="application/atom+xml" href="http://www.google.com/calendar/feeds/me%40gmail.com/acl/full"/>
+ <link rel="self" type="application/atom+xml" href="http://www.google.com/calendar/feeds/me%40gmail.com/me%40gmail.com"/>
+ <author>
+ <name>Me</name>
+ <email>me@gmail.com</email>
+ </author>
+ </entry>
</feed>'
@@xmlstr2 = '<?xml version="1.0" encoding="UTF-8"?>
<feed>
- <id>http://www.google.com/calendar/feeds/me%40gmail.com</id>
- <entry>
- <id>http://www.google.com/calendar/feeds/me%40gmail.com/me%40gmail.com</id>
- <published>2007-05-16T13:42:27.942Z</published>
- <updated>2007-05-15T03:29:28.000Z</updated>
- <title type="text">My Calendar</title>
- <link rel="alternate" type="application/atom+xml" href="http://www.google.com/calendar/feeds/me%40gmail.com/private/full"/>
- <link rel="http://schemas.google.com/acl/2007#accessControlList" type="application/atom+xml" href="http://www.google.com/calendar/feeds/me%40gmail.com/acl/full"/>
- <link rel="self" type="application/atom+xml" href="http://www.google.com/calendar/feeds/me%40gmail.com/me%40gmail.com"/>
- <author>
- <name>Me</name>
- <email>me@gmail.com</email>
- </author>
- </entry>
+ <id>http://www.google.com/calendar/feeds/me%40gmail.com</id>
+ <entry>
+ <id>http://www.google.com/calendar/feeds/me%40gmail.com/me%40gmail.com</id>
+ <published>2007-05-16T13:42:27.942Z</published>
+ <updated>2007-05-15T03:29:28.000Z</updated>
+ <title type="text">My Calendar</title>
+ <link rel="alternate" type="application/atom+xml" href="http://www.google.com/calendar/feeds/me%40gmail.com/private/full"/>
+ <link rel="http://schemas.google.com/acl/2007#accessControlList" type="application/atom+xml" href="http://www.google.com/calendar/feeds/me%40gmail.com/acl/full"/>
+ <link rel="self" type="application/atom+xml" href="http://www.google.com/calendar/feeds/me%40gmail.com/me%40gmail.com"/>
+ <author>
+ <name>Me</name>
+ <email>me@gmail.com</email>
+ </author>
+ </entry>
</feed>'
# Fails
diff --git a/test/rexml/test_xpath_msw.rb b/test/rexml/test_xpath_msw.rb
index b40e366..c03835e 100644
--- a/test/rexml/test_xpath_msw.rb
+++ b/test/rexml/test_xpath_msw.rb
@@ -1,10 +1,9 @@
require "test/unit/testcase"
-require "test/unit/ui/console/testrunner"
require "rexml/document"
class XPathAxesTester < Test::Unit::TestCase
- include REXML
- SOURCE = <<-EOF
+ include REXML
+ SOURCE = <<-EOF
<a id='1'>
<e id='2'>
<f id='3'/>
@@ -15,9 +14,9 @@ class XPathAxesTester < Test::Unit::TestCase
</a>
EOF
- def setup
- @@doc = Document.new(SOURCE) unless defined? @@doc
- end
+ def setup
+ @@doc = Document.new(SOURCE) unless defined? @@doc
+ end
def test_preceding_sibling_axis
context = XPath.first(@@doc,"/a/e/f[last()]")
@@ -37,6 +36,3 @@ class XPathAxesTester < Test::Unit::TestCase
end
end
-
-#Test::Unit::UI::Console::TestRunner.run(XPathAxesTester.suite)
-
diff --git a/test/rexml/test_xpath_pred.rb b/test/rexml/test_xpath_pred.rb
index 64eab3e..373a7f5 100644
--- a/test/rexml/test_xpath_pred.rb
+++ b/test/rexml/test_xpath_pred.rb
@@ -4,7 +4,7 @@ require "rexml/xpath"
require "rexml/parsers/xpathparser"
class XPathPredicateTester < Test::Unit::TestCase
- include REXML
+ include REXML
SRC=<<-EOL
<article>
<section role="subdivision" id="1">
diff --git a/test/rexml/test_xpathtext.rb b/test/rexml/test_xpathtext.rb
index 0ae48ac..c339398 100644
--- a/test/rexml/test_xpathtext.rb
+++ b/test/rexml/test_xpathtext.rb
@@ -53,8 +53,8 @@ class XpathTestCase < Test::Unit::TestCase
# 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)
+ comment = REXML::Comment.new('Test comment', node2)
+ assert_same(node2, comment.parent)
end
def test_ancestors
@@ -62,7 +62,7 @@ class XpathTestCase < Test::Unit::TestCase
node2 = REXML::Element.new('b', node1)
textnode = REXML::Text.new('test', false, node2)
#textnode.parent = node2 # should be unnecessary
- assert_same node2, textnode.parent
+ 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()')