mirror of
				https://github.com/ruby/ruby.git
				synced 2022-11-09 12:17:21 -05:00 
			
		
		
		
	* test/rexml/: untabify.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29285 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
		
							parent
							
								
									146bf4fdaf
								
							
						
					
					
						commit
						2a15d25a59
					
				
					 23 changed files with 1668 additions and 1673 deletions
				
			
		|  | @ -1,3 +1,7 @@ | ||||||
|  | Fri Sep 17 22:46:02 2010  Kouhei Sutou  <kou@cozmixng.org> | ||||||
|  | 
 | ||||||
|  | 	* test/rexml/: untabify. | ||||||
|  | 
 | ||||||
| Fri Sep 17 22:29:56 2010  Kouhei Sutou  <kou@cozmixng.org> | Fri Sep 17 22:29:56 2010  Kouhei Sutou  <kou@cozmixng.org> | ||||||
| 
 | 
 | ||||||
| 	* test/rexml/: fix fixture data path. All REXML tests are worked. | 	* test/rexml/: fix fixture data path. All REXML tests are worked. | ||||||
|  |  | ||||||
|  | @ -2,152 +2,152 @@ require 'test/unit/testcase' | ||||||
| require 'rexml/document' | require 'rexml/document' | ||||||
| 
 | 
 | ||||||
| class AttributesTester < Test::Unit::TestCase | class AttributesTester < Test::Unit::TestCase | ||||||
| 	include REXML |   include REXML | ||||||
| 	def test_accessor |   def test_accessor | ||||||
| 		doc = Document.new("<a xmlns:foo='a' xmlns:bar='b' foo:att='1' bar:att='2' att='3'/>") |     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 '3', doc.root.attributes['att'] | ||||||
| 		assert_equal '2', doc.root.attributes['bar:att'] |     assert_equal '2', doc.root.attributes['bar:att'] | ||||||
| 		doc.root.attributes['att'] = 5 |     doc.root.attributes['att'] = 5 | ||||||
| 		assert_equal '5', doc.root.attributes['att'] |     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'2''/) |  | ||||||
| 		assert(s =~ /h2='1"2'/) |  | ||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
| 	# Submitted by Kou |   def test_each_attribute | ||||||
| 	def test_namespace_conflict |     doc = Document.new('<a x="1" y="2"/>') | ||||||
| 		assert_raise( ParseException,  |     doc.root.attributes.each_attribute {|attr| | ||||||
| 			"Declaring two attributes with the same namespace should be an error" ) do |       if attr.expanded_name == 'x' | ||||||
| 			REXML::Document.new <<-XML |         assert_equal '1', attr.value | ||||||
| 			<x xmlns:n1="http://www.w3.org"  |       elsif attr.expanded_name == 'y' | ||||||
| 				 xmlns:n2="http://www.w3.org" > |         assert_equal '2', attr.value | ||||||
| 				<bad n1:a="1"  n2:a="2" /> |       else | ||||||
| 			</x> |         assert_fail "No such attribute!!" | ||||||
| 			XML |       end | ||||||
| 		end |     } | ||||||
|  |   end | ||||||
| 
 | 
 | ||||||
| 		REXML::Document.new("<a xmlns:a='a' xmlns:b='a'></a>") |   def test_each | ||||||
| 	end |     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 | ||||||
| 
 | 
 | ||||||
| 	# Submitted by Kou |   def test_get_attribute | ||||||
| 	def test_attribute_deletion |     doc = Document.new('<a xmlns:x="a" x:foo="1" foo="2" bar="3"/>') | ||||||
| 		e = REXML::Element.new |     assert_equal '2', doc.root.attributes.get_attribute("foo").value | ||||||
| 		e.add_namespace("a", "http://a/") |     assert_equal '1', doc.root.attributes.get_attribute("x:foo").value | ||||||
| 		e.add_namespace("b", "http://b/") |   end | ||||||
| 		e.add_attributes({"c" => "cc", "a:c" => "cC", "b:c" => "CC"}) |  | ||||||
| 
 | 
 | ||||||
| 		e.attributes.delete("c") |   def test_size | ||||||
| 		assert_nil(e.attributes.get_attribute("c")) |     doc = Document.new("<a xmlns:foo='a' x='1' y='2' foo:x='3'/>") | ||||||
|  |     assert_equal 4, doc.root.attributes.length | ||||||
|  |   end | ||||||
| 
 | 
 | ||||||
| 		before_size = e.attributes.size |   def test_setter | ||||||
| 		e.attributes.delete("c") |     doc = Document.new("<a xmlns:x='a' x:foo='1' foo='3'/>") | ||||||
| 		assert_nil(e.attributes.get_attribute("c")) |     doc.root.attributes['y:foo'] = '2' | ||||||
| 		assert_equal(before_size, e.attributes.size) |     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 | ||||||
| 
 | 
 | ||||||
| 		e.attributes.delete(e.attributes.get_attribute("a:c")) |   def test_delete | ||||||
| 		assert_nil(e.attributes.get_attribute("a:c")) |     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'] | ||||||
| 
 | 
 | ||||||
| 		e.attributes.delete("b:c") |     doc.root.attributes.delete 'x:foo' | ||||||
| 		assert_nil(e.attributes.get_attribute("b:c")) |     assert_equal 5, doc.root.attributes.size | ||||||
| 
 | 
 | ||||||
| 		before_size = e.attributes.size |     attr = doc.root.attributes.get_attribute('y:foo') | ||||||
| 		e.attributes.delete(e.attributes.get_attribute("b:c")) |     doc.root.attributes.delete attr | ||||||
| 		assert_nil(e.attributes.get_attribute("b:c")) |     assert_equal 4, doc.root.attributes.size | ||||||
| 		assert_equal(before_size, e.attributes.size) |  | ||||||
| 
 | 
 | ||||||
| 		before_size = e.attributes.size |     assert_equal '4', doc.root.attributes['z:foo'] | ||||||
| 		e.attributes.delete("c") |   end | ||||||
| 		assert_nil(e.attributes.get_attribute("c")) |  | ||||||
| 		assert_equal(before_size, e.attributes.size) |  | ||||||
| 
 | 
 | ||||||
| 		e.add_attribute("c", "cc") |   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 | ||||||
| 
 | 
 | ||||||
| 		e.attributes.delete(e.attributes.get_attribute("c")) |   # Contributed by Mike Stok | ||||||
| 		assert_nil(e.attributes.get_attribute("c")) |   def test_values_with_apostrophes | ||||||
| 	end |     doc = Document.new(%q#<tag h1="1'2'" h2='1"2'/>#) | ||||||
|  |     s = doc.to_s | ||||||
|  |     assert(s =~ /h1='1'2''/) | ||||||
|  |     assert(s =~ /h2='1"2'/) | ||||||
|  |   end | ||||||
| 
 | 
 | ||||||
| 	# Submitted by Kou |   # Submitted by Kou | ||||||
| 	def test_element_usage |   def test_namespace_conflict | ||||||
| 		attr = Attribute.new("name", "value") |     assert_raise( ParseException,  | ||||||
| 		elem = Element.new("elem") |                   "Declaring two attributes with the same namespace should be an error" ) do | ||||||
| 		a = Attribute.new(attr, elem) |       REXML::Document.new <<-XML | ||||||
| 		assert_equal(elem, a.element) |       <x xmlns:n1="http://www.w3.org"  | ||||||
| 	end |          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) |   def attr_test(attr_name,attr_value) | ||||||
|     a1 = REXML::Attribute.new(attr_name,attr_value) |     a1 = REXML::Attribute.new(attr_name,attr_value) | ||||||
|  |  | ||||||
|  | @ -5,7 +5,6 @@ require 'test/unit' | ||||||
| require 'rexml/document' | require 'rexml/document' | ||||||
| 
 | 
 | ||||||
| class TestAttributes < Test::Unit::TestCase | class TestAttributes < Test::Unit::TestCase | ||||||
| 
 |  | ||||||
|   def setup |   def setup | ||||||
|     @ns_a = "urn:x-test:a" |     @ns_a = "urn:x-test:a" | ||||||
|     @ns_b = "urn:x-test:b" |     @ns_b = "urn:x-test:b" | ||||||
|  | @ -21,7 +20,7 @@ class TestAttributes < Test::Unit::TestCase | ||||||
|     XMLEND |     XMLEND | ||||||
|     @attributes = REXML::Document.new(element_string).root.attributes |     @attributes = REXML::Document.new(element_string).root.attributes | ||||||
|   end |   end | ||||||
|    | 
 | ||||||
|   def test_get_attribute_ns |   def test_get_attribute_ns | ||||||
|     assert_equal("1", @attributes.get_attribute_ns("", "a").value) |     assert_equal("1", @attributes.get_attribute_ns("", "a").value) | ||||||
|     assert_equal("2", @attributes.get_attribute_ns("", "b").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("5", @attributes.get_attribute_ns(@ns_a, "e").value) | ||||||
|     assert_equal("6", @attributes.get_attribute_ns(@ns_b, "f").value) |     assert_equal("6", @attributes.get_attribute_ns(@ns_b, "f").value) | ||||||
|   end |   end | ||||||
|    |  | ||||||
| end | end | ||||||
|  |  | ||||||
|  | @ -8,9 +8,9 @@ require "rexml/formatters/default" | ||||||
| 
 | 
 | ||||||
| class ContribTester < Test::Unit::TestCase | class ContribTester < Test::Unit::TestCase | ||||||
|   include REXMLTestUtils |   include REXMLTestUtils | ||||||
| 	include REXML |   include REXML | ||||||
| 
 | 
 | ||||||
| XML_STRING_01 = <<DELIMITER |   XML_STRING_01 = <<DELIMITER | ||||||
| <?xml version="1.0" encoding="UTF-8"?> | <?xml version="1.0" encoding="UTF-8"?> | ||||||
| <biblio> | <biblio> | ||||||
|   <entry type="Book"> |   <entry type="Book"> | ||||||
|  | @ -31,7 +31,7 @@ XML_STRING_01 = <<DELIMITER | ||||||
| </biblio> | </biblio> | ||||||
| DELIMITER | DELIMITER | ||||||
| 
 | 
 | ||||||
| XML_STRING_02 = <<DELIMITER |   XML_STRING_02 = <<DELIMITER | ||||||
| <biblio> | <biblio> | ||||||
|   <entry type="Book"> |   <entry type="Book"> | ||||||
|     <language>english</language> |     <language>english</language> | ||||||
|  | @ -51,129 +51,129 @@ XML_STRING_02 = <<DELIMITER | ||||||
| </biblio> | </biblio> | ||||||
| DELIMITER | DELIMITER | ||||||
| 
 | 
 | ||||||
| 	# Tobias Reif <tobiasreif@pinkjuice.com> |   # Tobias Reif <tobiasreif@pinkjuice.com> | ||||||
| 	def test_bad_doctype_Tobias |   def test_bad_doctype_Tobias | ||||||
| 		source = <<-EOF |     source = <<-EOF | ||||||
| 		 <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" |      <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" | ||||||
| 				"http://www.w3.org/TR/SVG/DTD/svg10.dtd" |         "http://www.w3.org/TR/SVG/DTD/svg10.dtd" | ||||||
| 			 [ |        [ | ||||||
| 			 <!-- <!ENTITY % fast-slow "0 0  .5 1">--> |        <!-- <!ENTITY % fast-slow "0 0  .5 1">--> | ||||||
| 			 <!--<!ENTITY % slow-fast ".5 0  1 1">--> |        <!--<!ENTITY % slow-fast ".5 0  1 1">--> | ||||||
| 			 <!ENTITY hover_ani |        <!ENTITY hover_ani | ||||||
| 				'<animateTransform attributeName="transform" |         '<animateTransform attributeName="transform" | ||||||
| 				 type="scale" restart="whenNotActive" values="1;0.96" |          type="scale" restart="whenNotActive" values="1;0.96" | ||||||
| 				 dur="0.5s" calcMode="spline" keySplines="0 0  .5 1" |          dur="0.5s" calcMode="spline" keySplines="0 0  .5 1" | ||||||
| 				 fill="freeze" begin="mouseover"/> |          fill="freeze" begin="mouseover"/> | ||||||
| 				 <animateTransform  attributeName="transform" |          <animateTransform  attributeName="transform" | ||||||
| 				 type="scale" restart="whenNotActive" values="0.96;1" |          type="scale" restart="whenNotActive" values="0.96;1" | ||||||
| 				 dur="0.5s" calcMode="spline" keySplines=".5 0  1 1" |          dur="0.5s" calcMode="spline" keySplines=".5 0  1 1" | ||||||
| 				 fill="freeze" begin="mouseover+0.5s"/>' |          fill="freeze" begin="mouseover+0.5s"/>' | ||||||
| 			 > |        > | ||||||
| 			 ] |        ] | ||||||
| 		 > |      > | ||||||
| 		EOF |     EOF | ||||||
| 		doc = REXML::Document.new source |     doc = REXML::Document.new source | ||||||
| 		doc.write(out="") |     doc.write(out="") | ||||||
| 		assert(out[/>'>/] != nil, "Couldn't find >'>") |     assert(out[/>'>/] != nil, "Couldn't find >'>") | ||||||
| 		assert(out[/\]>/] != nil, "Couldn't find ]>") |     assert(out[/\]>/] != nil, "Couldn't find ]>") | ||||||
| 	end |   end | ||||||
| 
 | 
 | ||||||
| 	# Peter Verhage |   # Peter Verhage | ||||||
| 	def test_namespace_Peter |   def test_namespace_Peter | ||||||
| 		source = <<-EOF |     source = <<-EOF | ||||||
| 		<?xml version="1.0"?> |     <?xml version="1.0"?> | ||||||
| 		<config:myprog-config xmlns:config="http://someurl/program/version"> |     <config:myprog-config xmlns:config="http://someurl/program/version"> | ||||||
| 		<!-- main options --> |     <!-- main options --> | ||||||
| 			<config:main> |       <config:main> | ||||||
| 				<config:parameter name="name"  value="value"/> |         <config:parameter name="name"  value="value"/> | ||||||
| 			</config:main> |       </config:main> | ||||||
| 		</config:myprog-config> |     </config:myprog-config> | ||||||
| 		EOF |     EOF | ||||||
| 		doc = REXML::Document.new source |     doc = REXML::Document.new source | ||||||
| 		assert_equal "myprog-config", doc.root.name |     assert_equal "myprog-config", doc.root.name | ||||||
| 		count = 0 |     count = 0 | ||||||
| 		REXML::XPath.each(doc, "x:myprog-config/x:main/x:parameter",  |     REXML::XPath.each(doc, "x:myprog-config/x:main/x:parameter",  | ||||||
| 			{"x"=>"http://someurl/program/version"}) { |element| |       {"x"=>"http://someurl/program/version"}) { |element| | ||||||
| 				assert_equal "name", element.attributes["name"] |         assert_equal "name", element.attributes["name"] | ||||||
| 			count += 1; |       count += 1; | ||||||
| 		} |     } | ||||||
| 		assert_equal 1, count |     assert_equal 1, count | ||||||
| 		assert_equal "myprog-config", doc.elements["config:myprog-config"].name |     assert_equal "myprog-config", doc.elements["config:myprog-config"].name | ||||||
| 	end |   end | ||||||
| 
 | 
 | ||||||
| 	# Tobias Reif <tobiasreif@pinkjuice.com> |   # Tobias Reif <tobiasreif@pinkjuice.com> | ||||||
| 	def test_complex_xpath_Tobias |   def test_complex_xpath_Tobias | ||||||
| 		source = <<-EOF |     source = <<-EOF | ||||||
| 		<root> |     <root> | ||||||
| 			<foo> |       <foo> | ||||||
| 				<bar style="baz"/> |         <bar style="baz"/> | ||||||
| 				<blah style="baz"/> |         <blah style="baz"/> | ||||||
| 				<blam style="baz"/> |         <blam style="baz"/> | ||||||
| 			</foo> |       </foo> | ||||||
| 			<wax> |       <wax> | ||||||
| 				<fudge> |         <fudge> | ||||||
| 					<noodle/> |           <noodle/> | ||||||
| 				</fudge> |         </fudge> | ||||||
| 			</wax> |       </wax> | ||||||
| 		</root> |     </root> | ||||||
| 		EOF |     EOF | ||||||
| 		# elements that have child elements |     # elements that have child elements | ||||||
| 		#  but not grandchildren |     #  but not grandchildren | ||||||
| 		#  and not children that don't have a style attribute |     #  and not children that don't have a style attribute | ||||||
| 		#  and not children that have a unique style attribute |     #  and not children that have a unique style attribute | ||||||
| 		complex_path = "*[* "+ |     complex_path = "*[* "+ | ||||||
| 			"and not(*/node()) "+ |       "and not(*/node()) "+ | ||||||
| 			"and not(*[not(@style)]) "+ |       "and not(*[not(@style)]) "+ | ||||||
| 			"and not(*/@style != */@style)]" |       "and not(*/@style != */@style)]" | ||||||
| 		doc = REXML::Document.new source |     doc = REXML::Document.new source | ||||||
| 		results = REXML::XPath.match( doc.root, complex_path ) |     results = REXML::XPath.match( doc.root, complex_path ) | ||||||
| 		assert(results) |     assert(results) | ||||||
| 		assert_equal 1, results.size |     assert_equal 1, results.size | ||||||
| 		assert_equal "foo", results[0].name |     assert_equal "foo", results[0].name | ||||||
| 	end |   end | ||||||
| 
 | 
 | ||||||
| 	# "Chris Morris" <chrismo@charter.net> |   # "Chris Morris" <chrismo@charter.net> | ||||||
| 	def test_extra_newline_on_read_Chris |   def test_extra_newline_on_read_Chris | ||||||
| 		text = 'test text' |     text = 'test text' | ||||||
| 		e = REXML::Element.new('Test') |     e = REXML::Element.new('Test') | ||||||
| 		e.add_text(text) |     e.add_text(text) | ||||||
|     REXML::Formatters::Default.new.write(e,out="") |     REXML::Formatters::Default.new.write(e,out="") | ||||||
| 
 | 
 | ||||||
| 		doc = REXML::Document.new(out) |     doc = REXML::Document.new(out) | ||||||
| 		outtext = doc.root.text |     outtext = doc.root.text | ||||||
| 
 | 
 | ||||||
| 		assert_equal(text, outtext) |     assert_equal(text, outtext) | ||||||
| 	end |   end | ||||||
| 
 | 
 | ||||||
| 	# Tobias Reif <tobiasreif@pinkjuice.com> |   # Tobias Reif <tobiasreif@pinkjuice.com> | ||||||
| 	def test_other_xpath_Tobias |   def test_other_xpath_Tobias | ||||||
| 		schema = <<-DELIM |     schema = <<-DELIM | ||||||
| 		<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" |     <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" | ||||||
| 			elementFormDefault="qualified"> |       elementFormDefault="qualified"> | ||||||
| 			<xs:element name="rect"> |       <xs:element name="rect"> | ||||||
| 				<xs:complexType> |         <xs:complexType> | ||||||
| 					<xs:attribute name="width" type="xs:byte" use="required"/> |           <xs:attribute name="width" type="xs:byte" use="required"/> | ||||||
| 					<xs:attribute name="height" type="xs:byte" use="required"/> |           <xs:attribute name="height" type="xs:byte" use="required"/> | ||||||
| 				</xs:complexType> |         </xs:complexType> | ||||||
| 			</xs:element> |       </xs:element> | ||||||
| 			<xs:element name="svg"> |       <xs:element name="svg"> | ||||||
| 				<xs:complexType> |         <xs:complexType> | ||||||
| 					<xs:sequence> |           <xs:sequence> | ||||||
| 						<xs:element ref="rect"/> |             <xs:element ref="rect"/> | ||||||
| 					</xs:sequence> |           </xs:sequence> | ||||||
| 				</xs:complexType> |         </xs:complexType> | ||||||
| 			</xs:element> |       </xs:element> | ||||||
| 		</xs:schema> |     </xs:schema> | ||||||
| 		DELIM |     DELIM | ||||||
| 
 | 
 | ||||||
| 		doc = REXML::Document.new schema |     doc = REXML::Document.new schema | ||||||
| 
 | 
 | ||||||
| 		result = REXML::XPath.first(doc.root, 'xs:element[descendant::xs:element[@ref]]') |     result = REXML::XPath.first(doc.root, 'xs:element[descendant::xs:element[@ref]]') | ||||||
| 		assert result |     assert result | ||||||
| 		assert_equal "svg", result.attributes['name'] |     assert_equal "svg", result.attributes['name'] | ||||||
| 		result = REXML::XPath.first(doc, 'element[descendant::element[@ref]]') |     result = REXML::XPath.first(doc, 'element[descendant::element[@ref]]') | ||||||
| 		assert_nil result |     assert_nil result | ||||||
| 	end |   end | ||||||
| 
 | 
 | ||||||
|   #this first test succeeds, to check if stuff is set up correctly |   #this first test succeeds, to check if stuff is set up correctly | ||||||
|   def test_xpath_01_TobiasReif |   def test_xpath_01_TobiasReif | ||||||
|  | @ -228,8 +228,8 @@ DELIMITER | ||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
|   def test_umlaut |   def test_umlaut | ||||||
| 		koln_iso = "K\xf6ln" |     koln_iso = "K\xf6ln" | ||||||
| 		koln_utf = "K\xc3\xb6ln" |     koln_utf = "K\xc3\xb6ln" | ||||||
|     source_iso = "<?xml version='1.0' encoding='ISO-8859-1'?><test>#{koln_iso}</test>" |     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>" |     source_utf = "<?xml version='1.0' encoding='UTF-8'?><test>#{koln_utf}</test>" | ||||||
| 
 | 
 | ||||||
|  | @ -240,16 +240,16 @@ DELIMITER | ||||||
|       source_utf.force_encoding('utf-8') |       source_utf.force_encoding('utf-8') | ||||||
|     end |     end | ||||||
| 
 | 
 | ||||||
| 		doc = REXML::Document.new(source_iso) |     doc = REXML::Document.new(source_iso) | ||||||
| 		assert_equal('ISO-8859-1', doc.xml_decl.encoding) |     assert_equal('ISO-8859-1', doc.xml_decl.encoding) | ||||||
| 		assert_equal(koln_utf, doc.root.text) |     assert_equal(koln_utf, doc.root.text) | ||||||
| 		doc.write(out="") |     doc.write(out="") | ||||||
| 		assert_equal(source_iso, out ) |     assert_equal(source_iso, out ) | ||||||
| 		doc.xml_decl.encoding = 'UTF-8' |     doc.xml_decl.encoding = 'UTF-8' | ||||||
| 		doc.write(out="") |     doc.write(out="") | ||||||
| 		assert_equal(source_utf, out) |     assert_equal(source_utf, out) | ||||||
| 
 | 
 | ||||||
| 		doc = Document.new <<-EOF |     doc = Document.new <<-EOF | ||||||
| <?xml version="1.0" encoding="ISO-8859-1"?> | <?xml version="1.0" encoding="ISO-8859-1"?> | ||||||
| <intranet> | <intranet> | ||||||
| <position><aktuell datum="01-10-11">Technik</aktuell></position> | <position><aktuell datum="01-10-11">Technik</aktuell></position> | ||||||
|  | @ -265,228 +265,228 @@ Die Technik ist das R | ||||||
| </nebenspalte> | </nebenspalte> | ||||||
| </intranet> | </intranet> | ||||||
| EOF | EOF | ||||||
| 		tn = XPath.first(doc, "//nebenspalte/text()[2]") |     tn = XPath.first(doc, "//nebenspalte/text()[2]") | ||||||
| 		expected_iso = "Nützliches von Flashern für Flasher." |     expected_iso = "Nützliches von Flashern für Flasher." | ||||||
|                 expected_utf = expected_iso.unpack('C*').pack('U*') |                 expected_utf = expected_iso.unpack('C*').pack('U*') | ||||||
|                 if expected_utf.respond_to? :encode |                 if expected_utf.respond_to? :encode | ||||||
| 		  expected_iso.force_encoding("iso-8859-1") |       expected_iso.force_encoding("iso-8859-1") | ||||||
| 		  expected_utf.force_encoding(Encoding::UTF_8) |       expected_utf.force_encoding(Encoding::UTF_8) | ||||||
|                 end |                 end | ||||||
| 		assert_equal(expected_utf, tn.to_s.strip) |     assert_equal(expected_utf, tn.to_s.strip) | ||||||
|     f = REXML::Formatters::Default.new |     f = REXML::Formatters::Default.new | ||||||
|     f.write( tn, Output.new(o = "", "ISO-8859-1") ) |     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')) |     doc = Document.new File.new(fixture_path('xmlfile-bug.xml')) | ||||||
| 		tn = XPath.first(doc, "//nebenspalte/text()[2]") |     tn = XPath.first(doc, "//nebenspalte/text()[2]") | ||||||
| 		assert_equal(expected_utf, tn.to_s.strip) |     assert_equal(expected_utf, tn.to_s.strip) | ||||||
|     f.write( tn, Output.new(o = "", "ISO-8859-1") ) |     f.write( tn, Output.new(o = "", "ISO-8859-1") ) | ||||||
| 		assert_equal(expected_iso, o.strip) |     assert_equal(expected_iso, o.strip) | ||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
| 	def test_element_cloning_namespace_Chris |   def test_element_cloning_namespace_Chris | ||||||
| 		aDoc = REXML::Document.new '<h1 tpl:content="title" xmlns:tpl="1">Dummy title</h1>' |     aDoc = REXML::Document.new '<h1 tpl:content="title" xmlns:tpl="1">Dummy title</h1>' | ||||||
| 
 | 
 | ||||||
| 		anElement = anElement = aDoc.elements[1] |     anElement = anElement = aDoc.elements[1] | ||||||
| 		elementAttrPrefix = anElement.attributes.get_attribute('content').prefix |     elementAttrPrefix = anElement.attributes.get_attribute('content').prefix | ||||||
| 
 | 
 | ||||||
| 		aClone = anElement.clone |     aClone = anElement.clone | ||||||
| 		cloneAttrPrefix = aClone.attributes.get_attribute('content').prefix |     cloneAttrPrefix = aClone.attributes.get_attribute('content').prefix | ||||||
| 
 | 
 | ||||||
| 		assert_equal( elementAttrPrefix , cloneAttrPrefix ) |     assert_equal( elementAttrPrefix , cloneAttrPrefix ) | ||||||
| 	end |   end | ||||||
| 
 | 
 | ||||||
| 	def test_namespaces_in_attlist_tobias |   def test_namespaces_in_attlist_tobias | ||||||
| 		in_string = File.open(fixture_path('foo.xml'), 'r') do |file| |     in_string = File.open(fixture_path('foo.xml'), 'r') do |file| | ||||||
| 			 file.read |        file.read | ||||||
| 		end |     end | ||||||
| 
 | 
 | ||||||
| 		doc = Document.new in_string |     doc = Document.new in_string | ||||||
| 
 | 
 | ||||||
| 		assert_nil XPath.first(doc,'//leg') |     assert_nil XPath.first(doc,'//leg') | ||||||
| 		assert_equal 'http://www.foo.com/human', doc.root.elements[1].namespace |     assert_equal 'http://www.foo.com/human', doc.root.elements[1].namespace | ||||||
| 		assert_equal 'human leg',  |     assert_equal 'human leg',  | ||||||
| 			XPath.first(doc, '//x:leg/text()', {'x'=>'http://www.foo.com/human'}).to_s |       XPath.first(doc, '//x:leg/text()', {'x'=>'http://www.foo.com/human'}).to_s | ||||||
| 	end |   end | ||||||
| 
 | 
 | ||||||
| 	#  Alun ap Rhisiart |   #  Alun ap Rhisiart | ||||||
| 	def test_less_than_in_element_content |   def test_less_than_in_element_content | ||||||
| 		source = File.new(fixture_path('ProductionSupport.xml')) |     source = File.new(fixture_path('ProductionSupport.xml')) | ||||||
| 		h = Hash.new |     h = Hash.new | ||||||
| 		doc = REXML::Document.new source |     doc = REXML::Document.new source | ||||||
| 		doc.elements.each("//CommonError") { |el|  |     doc.elements.each("//CommonError") { |el|  | ||||||
| 			h[el.elements['Key'].text] = 'okay'  |       h[el.elements['Key'].text] = 'okay'  | ||||||
| 		} |     } | ||||||
| 		assert(h.include?('MotorInsuranceContract(Object)>>#error:')) |     assert(h.include?('MotorInsuranceContract(Object)>>#error:')) | ||||||
| 	end |   end | ||||||
| 
 | 
 | ||||||
| 	# XPaths provided by Thomas Sawyer |   # XPaths provided by Thomas Sawyer | ||||||
| 	def test_various_xpath |   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"/></p></r>') | ||||||
| 		doc = REXML::Document.new('<r a="1"><p><c b="2">3</c></p></r>') |     doc = REXML::Document.new('<r a="1"><p><c b="2">3</c></p></r>') | ||||||
| 
 | 
 | ||||||
| 		[['/r', REXML::Element], |     [['/r', REXML::Element], | ||||||
| 		 ['/r/p/c', REXML::Element], |      ['/r/p/c', REXML::Element], | ||||||
| 		 ['/r/attribute::a', Attribute], |      ['/r/attribute::a', Attribute], | ||||||
| 		 ['/r/@a', Attribute], |      ['/r/@a', Attribute], | ||||||
| 		 ['/r/attribute::*', Attribute], |      ['/r/attribute::*', Attribute], | ||||||
| 		 ['/r/@*', Attribute], |      ['/r/@*', Attribute], | ||||||
| 		 ['/r/p/c/attribute::b', Attribute], |      ['/r/p/c/attribute::b', Attribute], | ||||||
| 		 ['/r/p/c/@b', Attribute], |      ['/r/p/c/@b', Attribute], | ||||||
| 		 ['/r/p/c/attribute::*', Attribute], |      ['/r/p/c/attribute::*', Attribute], | ||||||
| 		 ['/r/p/c/@*', Attribute], |      ['/r/p/c/@*', Attribute], | ||||||
| 		 ['//c/attribute::b', Attribute], |      ['//c/attribute::b', Attribute], | ||||||
| 		 ['//c/@b', Attribute], |      ['//c/@b', Attribute], | ||||||
| 		 ['//c/attribute::*', Attribute], |      ['//c/attribute::*', Attribute], | ||||||
| 		 ['//c/@*', Attribute], |      ['//c/@*', Attribute], | ||||||
| 		 ['.//node()', REXML::Node ], |      ['.//node()', REXML::Node ], | ||||||
| 		 ['.//node()[@a]', REXML::Element ], |      ['.//node()[@a]', REXML::Element ], | ||||||
| 		 ['.//node()[@a="1"]', REXML::Element ], |      ['.//node()[@a="1"]', REXML::Element ], | ||||||
| 		 ['.//node()[@b]', REXML::Element ], # no show, why? |      ['.//node()[@b]', REXML::Element ], # no show, why? | ||||||
| 		 ['.//node()[@b="2"]', REXML::Element ] |      ['.//node()[@b="2"]', REXML::Element ] | ||||||
| 		].each do |xpath,kind| |     ].each do |xpath,kind| | ||||||
| 			begin |       begin | ||||||
| 				REXML::XPath.each( doc, xpath ) do |what| |         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" ) |           assert_kind_of( kind, what, "\n\nWrong type (#{what.class}) returned for #{xpath} (expected #{kind.name})\n\n" ) | ||||||
| 				end |         end | ||||||
| 			rescue Exception |       rescue Exception | ||||||
| 				puts "PATH WAS: #{xpath}" |         puts "PATH WAS: #{xpath}" | ||||||
| 				raise |         raise | ||||||
| 			end |       end | ||||||
| 		end |     end | ||||||
| 
 | 
 | ||||||
| 		[ |     [ | ||||||
| 		 ['/r', 'attribute::a', Attribute ], |      ['/r', 'attribute::a', Attribute ], | ||||||
| 		 ['/r', '@a', Attribute ], |      ['/r', '@a', Attribute ], | ||||||
| 		 ['/r', 'attribute::*', Attribute ], |      ['/r', 'attribute::*', Attribute ], | ||||||
| 		 ['/r', '@*', Attribute ], |      ['/r', '@*', Attribute ], | ||||||
| 		 ['/r/p/c', 'attribute::b', Attribute ], |      ['/r/p/c', 'attribute::b', Attribute ], | ||||||
| 		 ['/r/p/c', '@b', Attribute ], |      ['/r/p/c', '@b', Attribute ], | ||||||
| 		 ['/r/p/c', 'attribute::*', Attribute ], |      ['/r/p/c', 'attribute::*', Attribute ], | ||||||
| 		 ['/r/p/c', '@*', Attribute ] |      ['/r/p/c', '@*', Attribute ] | ||||||
| 		].each do |nodepath, xpath, kind| |     ].each do |nodepath, xpath, kind| | ||||||
| 			begin |       begin | ||||||
| 				context = REXML::XPath.first(doc, nodepath) |         context = REXML::XPath.first(doc, nodepath) | ||||||
| 				REXML::XPath.each( context, xpath ) do |what| |         REXML::XPath.each( context, xpath ) do |what| | ||||||
| 					assert_kind_of kind, what, "Wrong type (#{what.class}) returned for #{xpath} (expected #{kind.name})\n" |           assert_kind_of kind, what, "Wrong type (#{what.class}) returned for #{xpath} (expected #{kind.name})\n" | ||||||
| 				end |         end | ||||||
| 			rescue Exception |       rescue Exception | ||||||
| 				puts "PATH WAS: #{xpath}" |         puts "PATH WAS: #{xpath}" | ||||||
| 				raise |         raise | ||||||
| 			end |       end | ||||||
| 		end |     end | ||||||
| 	end |   end | ||||||
| 
 | 
 | ||||||
| 	def test_entities_Holden_Glova |   def test_entities_Holden_Glova | ||||||
| 		document = <<-EOL |     document = <<-EOL | ||||||
| 		<?xml version="1.0" encoding="UTF-8"?> |     <?xml version="1.0" encoding="UTF-8"?> | ||||||
| 		<!DOCTYPE rubynet [ |     <!DOCTYPE rubynet [ | ||||||
| 		<!ENTITY rbconfig.MAJOR "1"> |     <!ENTITY rbconfig.MAJOR "1"> | ||||||
| 		<!ENTITY rbconfig.MINOR "7"> |     <!ENTITY rbconfig.MINOR "7"> | ||||||
| 		<!ENTITY rbconfig.TEENY "2"> |     <!ENTITY rbconfig.TEENY "2"> | ||||||
| 		<!ENTITY rbconfig.ruby_version "&rbconfig.MAJOR;.&rbconfig.MINOR;"> |     <!ENTITY rbconfig.ruby_version "&rbconfig.MAJOR;.&rbconfig.MINOR;"> | ||||||
| 		<!ENTITY rbconfig.arch "i386-freebsd5"> |     <!ENTITY rbconfig.arch "i386-freebsd5"> | ||||||
| 		<!ENTITY rbconfig.prefix "/usr/local"> |     <!ENTITY rbconfig.prefix "/usr/local"> | ||||||
| 		<!ENTITY rbconfig.libdir "&rbconfig.prefix;/lib"> |     <!ENTITY rbconfig.libdir "&rbconfig.prefix;/lib"> | ||||||
| 		<!ENTITY rbconfig.includedir "&rbconfig.prefix;/include"> |     <!ENTITY rbconfig.includedir "&rbconfig.prefix;/include"> | ||||||
| 		<!ENTITY rbconfig.sitedir "&rbconfig.prefix;/lib/ruby/site_ruby"> |     <!ENTITY rbconfig.sitedir "&rbconfig.prefix;/lib/ruby/site_ruby"> | ||||||
| 		<!ENTITY rbconfig.sitelibdir "&rbconfig.sitedir;/&rbconfig.ruby_version;"> |     <!ENTITY rbconfig.sitelibdir "&rbconfig.sitedir;/&rbconfig.ruby_version;"> | ||||||
| 		<!ENTITY rbconfig.sitearchdir "&rbconfig.sitelibdir;/&rbconfig.arch;"> |     <!ENTITY rbconfig.sitearchdir "&rbconfig.sitelibdir;/&rbconfig.arch;"> | ||||||
| 		]> |     ]> | ||||||
| 		<rubynet> |     <rubynet> | ||||||
| 			<pkg version="version1.0"> |       <pkg version="version1.0"> | ||||||
| 				<files> |         <files> | ||||||
| 					<file> |           <file> | ||||||
| 						<filename>uga.rb</filename> |             <filename>uga.rb</filename> | ||||||
| 						<mode>0444</mode> |             <mode>0444</mode> | ||||||
| 						<path>&rbconfig.libdir;/rexml</path> |             <path>&rbconfig.libdir;/rexml</path> | ||||||
| 						<content encoding="xml">... the file here</content> |             <content encoding="xml">... the file here</content> | ||||||
| 					</file> |           </file> | ||||||
| 					<file> |           <file> | ||||||
| 						<filename>booga.h</filename> |             <filename>booga.h</filename> | ||||||
| 						<mode>0444</mode> |             <mode>0444</mode> | ||||||
| 						<path>&rbconfig.includedir;</path> |             <path>&rbconfig.includedir;</path> | ||||||
| 						<content encoding="xml">... the file here</content> |             <content encoding="xml">... the file here</content> | ||||||
| 					</file> |           </file> | ||||||
| 					<file> |           <file> | ||||||
| 						<filename>foo.so</filename> |             <filename>foo.so</filename> | ||||||
| 						<mode>0555</mode> |             <mode>0555</mode> | ||||||
| 						<path>&rbconfig.sitearchdir;/rexml</path> |             <path>&rbconfig.sitearchdir;/rexml</path> | ||||||
| 						<content encoding="mime64">Li4uIHRoZSBmaWxlIGhlcmU=\n</content> |             <content encoding="mime64">Li4uIHRoZSBmaWxlIGhlcmU=\n</content> | ||||||
| 					</file> |           </file> | ||||||
| 				</files> |         </files> | ||||||
| 			</pkg> |       </pkg> | ||||||
| 		</rubynet> |     </rubynet> | ||||||
| 		EOL |     EOL | ||||||
| 
 | 
 | ||||||
| 		file_xpath = '/rubynet/pkg/files/file' |     file_xpath = '/rubynet/pkg/files/file' | ||||||
| 
 | 
 | ||||||
| 		root = REXML::Document.new(document) |     root = REXML::Document.new(document) | ||||||
| 
 | 
 | ||||||
| 		root.elements.each(file_xpath) do |metadata| |     root.elements.each(file_xpath) do |metadata| | ||||||
| 			text = metadata.elements['path'].get_text.value |       text = metadata.elements['path'].get_text.value | ||||||
| 			assert text !~ /&rbconfig/, "'#{text}' failed" |       assert text !~ /&rbconfig/, "'#{text}' failed" | ||||||
| 		end |     end | ||||||
| 
 | 
 | ||||||
| 		#Error occurred in test_package_file_opens(TC_PackageInstall):  |     #Error occurred in test_package_file_opens(TC_PackageInstall):  | ||||||
| 		# ArgumentError: |     # ArgumentError: | ||||||
| 		#illegal access mode &rbconfig.prefix;/lib/rexml |     #illegal access mode &rbconfig.prefix;/lib/rexml | ||||||
| 		# |     # | ||||||
| 		#[synack@Evergreen] src $ ruby --version |     #[synack@Evergreen] src $ ruby --version | ||||||
| 		#ruby 1.6.7 (2002-03-01) [i686-linux-gnu] |     #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 |     #It looks like it expanded the first entity, but didn't reparse it for more | ||||||
| 		#entities. possible bug - or have I mucked this up? |     #entities. possible bug - or have I mucked this up? | ||||||
| 	end |   end | ||||||
| 
 | 
 | ||||||
| 	def test_whitespace_after_xml_decl |   def test_whitespace_after_xml_decl | ||||||
| 		d = Document.new <<EOL |     d = Document.new <<EOL | ||||||
| <?xml version='1.0'?> | <?xml version='1.0'?> | ||||||
|   <blo> |   <blo> | ||||||
| 		<wak> |     <wak> | ||||||
| 		</wak> |     </wak> | ||||||
| </blo> | </blo> | ||||||
| EOL | EOL | ||||||
| 	end |   end | ||||||
| 
 | 
 | ||||||
| 	def test_external_entity |   def test_external_entity | ||||||
| 		xp = '//channel/title' |     xp = '//channel/title' | ||||||
| 
 | 
 | ||||||
| 		%w{working.rss broken.rss}.each do |path| |     %w{working.rss broken.rss}.each do |path| | ||||||
| 			File.open(File.join(fixture_path(path))) do |file| |       File.open(File.join(fixture_path(path))) do |file| | ||||||
| 				doc = REXML::Document.new file.readlines.join('') |         doc = REXML::Document.new file.readlines.join('') | ||||||
| 
 | 
 | ||||||
| 				# check to make sure everything is kosher |         # check to make sure everything is kosher | ||||||
| 				assert_equal( doc.root.class, REXML::Element ) |         assert_equal( doc.root.class, REXML::Element ) | ||||||
| 				assert_equal( doc.root.elements.class, REXML::Elements ) |         assert_equal( doc.root.elements.class, REXML::Elements ) | ||||||
| 
 | 
 | ||||||
| 				# get the title of the feed |         # get the title of the feed | ||||||
| 				assert( doc.root.elements[xp].kind_of?( REXML::Element ) ) |         assert( doc.root.elements[xp].kind_of?( REXML::Element ) ) | ||||||
| 			end |       end | ||||||
| 		end |     end | ||||||
| 	end |   end | ||||||
| 
 | 
 | ||||||
| 	def test_maintain_dtd  |   def test_maintain_dtd  | ||||||
| 		src = %q{<?xml version="1.0" encoding="UTF-8"?> |     src = %q{<?xml version="1.0" encoding="UTF-8"?> | ||||||
| <!DOCTYPE ivattacks SYSTEM "../../ivacm.dtd" [ | <!DOCTYPE ivattacks SYSTEM "../../ivacm.dtd" [ | ||||||
| <!ENTITY % extern-packages SYSTEM "../../ivpackages.dtd"> | <!ENTITY % extern-packages SYSTEM "../../ivpackages.dtd"> | ||||||
| <!ENTITY % extern-packages SYSTEM "../../common-declarations.dtd"> | <!ENTITY % extern-packages SYSTEM "../../common-declarations.dtd"> | ||||||
| %extern-packages; | %extern-packages; | ||||||
| %extern-common; | %extern-common; | ||||||
| ]>} | ]>} | ||||||
| 		doc = Document.new( src ) |     doc = Document.new( src ) | ||||||
| 		doc.write( out="" ) |     doc.write( out="" ) | ||||||
| 		src = src.tr('"', "'") |     src = src.tr('"', "'") | ||||||
| 		out = out.tr('"', "'") |     out = out.tr('"', "'") | ||||||
| 		assert_equal( src, out ) |     assert_equal( src, out ) | ||||||
| 	end |   end | ||||||
| 
 | 
 | ||||||
| 	def test_text_nodes_nomatch |   def test_text_nodes_nomatch | ||||||
| 		source = "<root><child>test</child></root>" |     source = "<root><child>test</child></root>" | ||||||
| 		d = REXML::Document.new( source ) |     d = REXML::Document.new( source ) | ||||||
| 		r = REXML::XPath.match( d, %q{/root/child[text()="no-test"]} ) |     r = REXML::XPath.match( d, %q{/root/child[text()="no-test"]} ) | ||||||
| 		assert_equal( 0, r.size ) |     assert_equal( 0, r.size ) | ||||||
| 	end |   end | ||||||
| 
 | 
 | ||||||
|   def test_raw_Terje_Elde |   def test_raw_Terje_Elde | ||||||
|     f = REXML::Formatters::Default.new |     f = REXML::Formatters::Default.new | ||||||
|  | @ -560,24 +560,24 @@ EOL | ||||||
| =begin | =begin | ||||||
|  # This is a silly test, and is low priority |  # This is a silly test, and is low priority | ||||||
|  def test_namespace_serialization_tobi_reif |  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/> |  <b:p/> | ||||||
| </doc>' | </doc>' | ||||||
| 	 ns = 'http://www.foo.foo' |    ns = 'http://www.foo.foo' | ||||||
| 	 ns_declaration={'f'=>ns} |    ns_declaration={'f'=>ns} | ||||||
| 	 returned = XPath.match(doc,'//f:p',ns_declaration) |    returned = XPath.match(doc,'//f:p',ns_declaration) | ||||||
| 	 # passes: |    # passes: | ||||||
| 	 assert( (returned[0].namespace==ns), 'namespace should be '+ns) |    assert( (returned[0].namespace==ns), 'namespace should be '+ns) | ||||||
| 	 serialized = returned.to_s |    serialized = returned.to_s | ||||||
| 	 serialized_and_parsed = Document.new(serialized) |    serialized_and_parsed = Document.new(serialized) | ||||||
| 	 puts 'serialized: '+serialized |    puts 'serialized: '+serialized | ||||||
| 		 # ... currently brings <b:p/> |      # ... currently brings <b:p/> | ||||||
| 		 # prefix b is undeclared (!) |      # prefix b is undeclared (!) | ||||||
| 	 assert( (serialized_and_parsed.namespace==ns), |    assert( (serialized_and_parsed.namespace==ns), | ||||||
| 		 'namespace should still be '+ns.inspect+ |      'namespace should still be '+ns.inspect+ | ||||||
| 		 ' and not '+serialized_and_parsed.namespace.inspect) |      ' and not '+serialized_and_parsed.namespace.inspect) | ||||||
| 	 # ... currently results in a failure: |    # ... currently results in a failure: | ||||||
| 	 # 'namespace should still be "http://www.foo.foo" and not ""' |    # 'namespace should still be "http://www.foo.foo" and not ""' | ||||||
|  end |  end | ||||||
| =end | =end | ||||||
| end | end | ||||||
|  |  | ||||||
|  | @ -1104,9 +1104,9 @@ EOL | ||||||
|   end |   end | ||||||
|    |    | ||||||
|   def test_transitive |   def test_transitive | ||||||
| 	doc = REXML::Document.new( "<a/>") |   doc = REXML::Document.new( "<a/>") | ||||||
| 	s = "" |   s = "" | ||||||
| 	doc.write( s, 0, true ) |   doc.write( s, 0, true ) | ||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
|   # This is issue #40 |   # This is issue #40 | ||||||
|  | @ -1145,25 +1145,25 @@ EOL | ||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| 	def test_ticket_58 |   def test_ticket_58 | ||||||
| 		doc = REXML::Document.new |     doc = REXML::Document.new | ||||||
| 		doc << REXML::XMLDecl.default |     doc << REXML::XMLDecl.default | ||||||
| 		doc << REXML::Element.new("a") |     doc << REXML::Element.new("a") | ||||||
| 		 |      | ||||||
| 		str = "" |     str = "" | ||||||
| 		doc.write(str) |     doc.write(str) | ||||||
| 		 |      | ||||||
| 		assert_equal("<a/>", str) |     assert_equal("<a/>", str) | ||||||
| 
 | 
 | ||||||
| 		doc = REXML::Document.new |     doc = REXML::Document.new | ||||||
| 		doc << REXML::XMLDecl.new("1.0", "UTF-8") |     doc << REXML::XMLDecl.new("1.0", "UTF-8") | ||||||
| 		doc << REXML::Element.new("a") |     doc << REXML::Element.new("a") | ||||||
| 		 |      | ||||||
| 		str = "" |     str = "" | ||||||
| 		doc.write(str) |     doc.write(str) | ||||||
| 		 |      | ||||||
| 		assert_equal("<?xml version='1.0' encoding='UTF-8'?><a/>", str) |     assert_equal("<?xml version='1.0' encoding='UTF-8'?><a/>", str) | ||||||
| 	end |   end | ||||||
| 
 | 
 | ||||||
|   # Incomplete tags should generate an error |   # Incomplete tags should generate an error | ||||||
|   def test_ticket_53 |   def test_ticket_53 | ||||||
|  | @ -1251,9 +1251,9 @@ EOL | ||||||
|   def test_ticket_85 |   def test_ticket_85 | ||||||
|     xml = <<ENDXML |     xml = <<ENDXML | ||||||
| <foo> | <foo> | ||||||
| 	<bar> |   <bar> | ||||||
| 		<bob name='jimmy'/> |     <bob name='jimmy'/> | ||||||
| 	</bar> |   </bar> | ||||||
| </foo> | </foo> | ||||||
| ENDXML | ENDXML | ||||||
| 
 | 
 | ||||||
|  | @ -1276,7 +1276,7 @@ ENDXML | ||||||
|     # Output directives should override whitespace directives. |     # Output directives should override whitespace directives. | ||||||
|     assert_equal( output1, output2 ) |     assert_equal( output1, output2 ) | ||||||
| 
 | 
 | ||||||
|     # The base case.	 |     # The base case. | ||||||
|     d = Document.new(yml) |     d = Document.new(yml) | ||||||
|     f.write( d, output3="" ) |     f.write( d, output3="" ) | ||||||
|      |      | ||||||
|  | @ -1286,7 +1286,7 @@ ENDXML | ||||||
|     f.write( d, output4="" ) |     f.write( d, output4="" ) | ||||||
| 
 | 
 | ||||||
|     assert_equal( output3.strip, output4.strip ) |     assert_equal( output3.strip, output4.strip ) | ||||||
|   end  	 |   end | ||||||
| 
 | 
 | ||||||
|   def test_ticket_91 |   def test_ticket_91 | ||||||
|     source="<root> |     source="<root> | ||||||
|  |  | ||||||
|  | @ -2,45 +2,45 @@ require 'test/unit/testcase' | ||||||
| require 'rexml/document' | require 'rexml/document' | ||||||
| 
 | 
 | ||||||
| class ElementsTester < Test::Unit::TestCase | class ElementsTester < Test::Unit::TestCase | ||||||
| 	include REXML |   include REXML | ||||||
| 	def test_elements_accessor |   def test_elements_accessor | ||||||
| 		doc = Document.new '<a><b/><c id="1"/><c id="2"/><d/></a>' |     doc = Document.new '<a><b/><c id="1"/><c id="2"/><d/></a>' | ||||||
| 		assert_equal 'b', doc.root.elements[1].name |     assert_equal 'b', doc.root.elements[1].name | ||||||
| 		assert_equal '1', doc.root.elements['c'].attributes['id'] |     assert_equal '1', doc.root.elements['c'].attributes['id'] | ||||||
| 		assert_equal '2', doc.root.elements[2,'c'].attributes['id'] |     assert_equal '2', doc.root.elements[2,'c'].attributes['id'] | ||||||
| 	end |   end | ||||||
| 
 | 
 | ||||||
| 	def test_elements_indexing |   def test_elements_indexing | ||||||
| 		doc = Document.new '<a/>' |     doc = Document.new '<a/>' | ||||||
| 		doc.root.elements[10] = Element.new('b') |     doc.root.elements[10] = Element.new('b') | ||||||
| 		assert_equal 'b', doc.root.elements[1].name |     assert_equal 'b', doc.root.elements[1].name | ||||||
| 		doc.root.elements[1] = Element.new('c') |     doc.root.elements[1] = Element.new('c') | ||||||
| 		assert_equal 'c', doc.root.elements[1].name |     assert_equal 'c', doc.root.elements[1].name | ||||||
| 		doc.root.elements['c'] = Element.new('d') |     doc.root.elements['c'] = Element.new('d') | ||||||
| 		assert_equal 'd', doc.root.elements[1].name |     assert_equal 'd', doc.root.elements[1].name | ||||||
| 	end |   end | ||||||
| 	 |    | ||||||
| 	def test_elements_delete |   def test_elements_delete | ||||||
| 		doc = Document.new '<a><b/><c/><c id="1"/></a>' |     doc = Document.new '<a><b/><c/><c id="1"/></a>' | ||||||
| 		block = proc { |str|  |     block = proc { |str|  | ||||||
| 			out = '' |       out = '' | ||||||
| 			doc.write out |       doc.write out | ||||||
| 			assert_equal str, out  |       assert_equal str, out  | ||||||
| 		} |     } | ||||||
| 		b = doc.root.elements[1] |     b = doc.root.elements[1] | ||||||
| 		doc.root.elements.delete b  |     doc.root.elements.delete b  | ||||||
| 		block.call( "<a><c/><c id='1'/></a>" ) |     block.call( "<a><c/><c id='1'/></a>" ) | ||||||
| 		doc.elements.delete("a/c[@id='1']") |     doc.elements.delete("a/c[@id='1']") | ||||||
| 		block.call( '<a><c/></a>' ) |     block.call( '<a><c/></a>' ) | ||||||
| 		doc.root.elements.delete 1 |     doc.root.elements.delete 1 | ||||||
|     block.call( '<a/>' ) |     block.call( '<a/>' ) | ||||||
| 	end |   end | ||||||
| 
 | 
 | ||||||
| 	def test_elements_delete_all |   def test_elements_delete_all | ||||||
| 		doc = Document.new '<a><c/><c/><c/><c/></a>' |     doc = Document.new '<a><c/><c/><c/><c/></a>' | ||||||
| 		deleted = doc.elements.delete_all 'a/c' |     deleted = doc.elements.delete_all 'a/c' | ||||||
| 		assert_equal 4, deleted.size |     assert_equal 4, deleted.size | ||||||
| 	end |   end | ||||||
| 
 | 
 | ||||||
|   def test_ticket_36 |   def test_ticket_36 | ||||||
|     doc = Document.new( "<a xmlns:xi='foo'><b><xi:c id='1'/></b><xi:c id='2'/></a>" ) |     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 ) |     assert_equal( 2, deleted.size ) | ||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
| 	def test_elements_add |   def test_elements_add | ||||||
| 		a = Element.new 'a' |     a = Element.new 'a' | ||||||
| 		a.elements.add Element.new('b') |     a.elements.add Element.new('b') | ||||||
| 		assert_equal 'b', a.elements[1].name |     assert_equal 'b', a.elements[1].name | ||||||
| 		a.elements.add 'c' |     a.elements.add 'c' | ||||||
| 		assert_equal 'c', a.elements[2].name |     assert_equal 'c', a.elements[2].name | ||||||
| 	end |   end | ||||||
| 
 | 
 | ||||||
| 	def test_elements_size |   def test_elements_size | ||||||
| 		doc = Document.new '<a>sean<b/>elliott<b/>russell<b/></a>' |     doc = Document.new '<a>sean<b/>elliott<b/>russell<b/></a>' | ||||||
| 		assert_equal 6, doc.root.size |     assert_equal 6, doc.root.size | ||||||
| 		assert_equal 3, doc.root.elements.size |     assert_equal 3, doc.root.elements.size | ||||||
| 	end |   end | ||||||
| 
 | 
 | ||||||
| 	def test_elements_each |   def test_elements_each | ||||||
| 		doc = Document.new '<a><b/><c/><d/>sean<b/><c/><d/></a>' |     doc = Document.new '<a><b/><c/><d/>sean<b/><c/><d/></a>' | ||||||
| 		count = 0 |     count = 0 | ||||||
| 		block = proc {|e| count += 1} |     block = proc {|e| count += 1} | ||||||
| 		doc.root.elements.each(&block) |     doc.root.elements.each(&block) | ||||||
| 		assert_equal 6, count |     assert_equal 6, count | ||||||
| 		count = 0 |     count = 0 | ||||||
| 		doc.root.elements.each('b', &block) |     doc.root.elements.each('b', &block) | ||||||
| 		assert_equal 2, count |     assert_equal 2, count | ||||||
| 		count = 0 |     count = 0 | ||||||
| 		doc.root.elements.each('child::node()', &block) |     doc.root.elements.each('child::node()', &block) | ||||||
| 		assert_equal 6, count |     assert_equal 6, count | ||||||
| 		count = 0 |     count = 0 | ||||||
| 		XPath.each(doc.root, 'child::node()', &block) |     XPath.each(doc.root, 'child::node()', &block) | ||||||
| 		assert_equal 7, count |     assert_equal 7, count | ||||||
| 	end |   end | ||||||
| 
 | 
 | ||||||
| 	def test_elements_to_a |   def test_elements_to_a | ||||||
| 		doc = Document.new '<a>sean<b/>elliott<c/></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.size | ||||||
| 		assert_equal 2, doc.root.elements.to_a("child::node()").size |     assert_equal 2, doc.root.elements.to_a("child::node()").size | ||||||
| 		assert_equal 4, XPath.match(doc.root, "child::node()").size |     assert_equal 4, XPath.match(doc.root, "child::node()").size | ||||||
| 	end |   end | ||||||
| 	 |    | ||||||
| 	def test_elements_collect |   def test_elements_collect | ||||||
| 		doc = Document.new( "<a><b id='1'/><b id='2'/></a>" ) |     doc = Document.new( "<a><b id='1'/><b id='2'/></a>" ) | ||||||
| 		r = doc.elements.collect( "/a/b" ) { |e| e.attributes["id"].to_i } |     r = doc.elements.collect( "/a/b" ) { |e| e.attributes["id"].to_i } | ||||||
| 		assert_equal( [1,2], r ) |     assert_equal( [1,2], r ) | ||||||
| 	end |   end | ||||||
| 	 |    | ||||||
| 	def test_elements_inject |   def test_elements_inject | ||||||
| 		doc = Document.new( "<a><b id='1'/><b id='2'/></a>" ) |     doc = Document.new( "<a><b id='1'/><b id='2'/></a>" ) | ||||||
| 		r = doc.elements.inject( "/a/b", 3 ) { |s, e| |     r = doc.elements.inject( "/a/b", 3 ) { |s, e| | ||||||
| 			s + e.attributes["id"].to_i |       s + e.attributes["id"].to_i | ||||||
| 		} |     } | ||||||
| 		assert_equal 6, r |     assert_equal 6, r | ||||||
| 	end |   end | ||||||
| end | end | ||||||
|  |  | ||||||
|  | @ -15,7 +15,7 @@ class EncodingTester < Test::Unit::TestCase | ||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
|   # Given an encoded document, try to write out to that encoding |   # 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 = Document.new( @encoded ) | ||||||
|     doc.write( out="" ) |     doc.write( out="" ) | ||||||
|     out.force_encoding('binary') if out.respond_to? :force_encoding |     out.force_encoding('binary') if out.respond_to? :force_encoding | ||||||
|  |  | ||||||
|  | @ -6,54 +6,54 @@ require "rexml/parseexception" | ||||||
| =begin | =begin | ||||||
| # THIS DOESN'T WORK | # THIS DOESN'T WORK | ||||||
| begin | begin | ||||||
| 	require 'iconv' |   require 'iconv' | ||||||
| 
 | 
 | ||||||
| 	UnixCharsets = open("| iconv -l") do |f| |   UnixCharsets = open("| iconv -l") do |f| | ||||||
| 		 f.readlines[5..-1].collect { |x| x.sub(/\/\/\n/,"").delete(' ') } |      f.readlines[5..-1].collect { |x| x.sub(/\/\/\n/,"").delete(' ') } | ||||||
| 	end |   end | ||||||
| 
 | 
 | ||||||
| 	DATA = <<END |   DATA = <<END | ||||||
| <?xml version="1.0" encoding='ENC'?> | <?xml version="1.0" encoding='ENC'?> | ||||||
| <Ruby xmlns="http://www.ruby-lang.org/ruby/1.8"> | <Ruby xmlns="http://www.ruby-lang.org/ruby/1.8"> | ||||||
| </Ruby> | </Ruby> | ||||||
| END | END | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| 	class IConvTester < Test::Unit::TestCase |   class IConvTester < Test::Unit::TestCase | ||||||
| 
 | 
 | ||||||
| 		def test_iconv |     def test_iconv | ||||||
| 			broken_encodings = 0 |       broken_encodings = 0 | ||||||
| 			UnixCharsets.each do |enc| |       UnixCharsets.each do |enc| | ||||||
| 				begin |         begin | ||||||
| 					puts "Testing encoding #{enc}" |           puts "Testing encoding #{enc}" | ||||||
| 					data = DATA.dup |           data = DATA.dup | ||||||
| 					data[/ENC/] = enc |           data[/ENC/] = enc | ||||||
| 					REXML::Document.new(data).root |           REXML::Document.new(data).root | ||||||
| 				rescue REXML::ParseException => e |         rescue REXML::ParseException => e | ||||||
| 					broken_encodings += 1 |           broken_encodings += 1 | ||||||
| 					fail "Encoding #{enc} does not work with REXML: #{e.message}" |           fail "Encoding #{enc} does not work with REXML: #{e.message}" | ||||||
| 				rescue Errno::EINVAL => e |         rescue Errno::EINVAL => e | ||||||
| 					broken_encodings += 1 |           broken_encodings += 1 | ||||||
| 					fail "Encoding #{enc} does not work with REXML: #{e.message}" |           fail "Encoding #{enc} does not work with REXML: #{e.message}" | ||||||
| 				rescue ArgumentError => e |         rescue ArgumentError => e | ||||||
| 					broken_encodings += 1 |           broken_encodings += 1 | ||||||
| 					fail "Encoding #{enc} does not work with REXML: #{e.message}" |           fail "Encoding #{enc} does not work with REXML: #{e.message}" | ||||||
| 				rescue |         rescue | ||||||
| 					broken_encodings += 1 |           broken_encodings += 1 | ||||||
| 					fail "Encoding #{enc} does not work with REXML: #{$!.message}" |           fail "Encoding #{enc} does not work with REXML: #{$!.message}" | ||||||
| 				end |         end | ||||||
| 			end |       end | ||||||
| 
 | 
 | ||||||
| 			if broken_encodings > 0  |       if broken_encodings > 0  | ||||||
| 				fail "There were #{broken_encodings} encoding failures out of #{UnixCharsets.size} plus some REXML internal encodings" |         fail "There were #{broken_encodings} encoding failures out of #{UnixCharsets.size} plus some REXML internal encodings" | ||||||
| 			else |       else | ||||||
| 				fail "There were no encoding failures" |         fail "There were no encoding failures" | ||||||
| 			end |       end | ||||||
| 
 | 
 | ||||||
| 			puts "Full list of registered encodings in REXML:" |       puts "Full list of registered encodings in REXML:" | ||||||
| 			puts REXML::Encoding::ENCODING_CLAIMS.values.join(', ') |       puts REXML::Encoding::ENCODING_CLAIMS.values.join(', ') | ||||||
| 		end |     end | ||||||
| 	end |   end | ||||||
| rescue LoadError | rescue LoadError | ||||||
| end | end | ||||||
| =end | =end | ||||||
|  |  | ||||||
|  | @ -4,145 +4,145 @@ require 'rexml/entity' | ||||||
| require 'rexml/source' | require 'rexml/source' | ||||||
| 
 | 
 | ||||||
| class EntityTester < Test::Unit::TestCase | class EntityTester < Test::Unit::TestCase | ||||||
| 	def test_parse_general_decl |   def test_parse_general_decl | ||||||
| 		simple = "<!ENTITY foo 'bar'>" |     simple = "<!ENTITY foo 'bar'>" | ||||||
| 		simple =~ /#{REXML::Entity::GEDECL}/ |     simple =~ /#{REXML::Entity::GEDECL}/ | ||||||
| 		assert $& |     assert $& | ||||||
| 		assert_equal simple, $& |     assert_equal simple, $& | ||||||
| 		 |      | ||||||
| 		REXML::Entity::ENTITYDECL =~ simple |     REXML::Entity::ENTITYDECL =~ simple | ||||||
| 		assert REXML::Entity::matches?(simple) |     assert REXML::Entity::matches?(simple) | ||||||
| 		match = REXML::Entity::ENTITYDECL.match(simple) |     match = REXML::Entity::ENTITYDECL.match(simple) | ||||||
| 		assert_equal 'foo', match[1] |     assert_equal 'foo', match[1] | ||||||
| 		assert_equal "'bar'", match[2] |     assert_equal "'bar'", match[2] | ||||||
| 
 | 
 | ||||||
| 		simple = '<!ENTITY Pub-Status  |     simple = '<!ENTITY Pub-Status  | ||||||
| 		"This is a pre-release of the specification.">' |     "This is a pre-release of the specification.">' | ||||||
| 		assert REXML::Entity::matches?(simple) |     assert REXML::Entity::matches?(simple) | ||||||
| 		match = REXML::Entity::ENTITYDECL.match(simple) |     match = REXML::Entity::ENTITYDECL.match(simple) | ||||||
| 		assert_equal 'Pub-Status', match[1] |     assert_equal 'Pub-Status', match[1] | ||||||
| 		assert_equal '"This is a pre-release of the specification."', match[2] |     assert_equal '"This is a pre-release of the specification."', match[2] | ||||||
| 
 | 
 | ||||||
| 		txt = '"This is a  |     txt = '"This is a  | ||||||
| 		pre-release of <the> specification."' |     pre-release of <the> specification."' | ||||||
| 		simple = "<!ENTITY 		Pub-Status  |     simple = "<!ENTITY     Pub-Status  | ||||||
| 		#{txt}>" |     #{txt}>" | ||||||
| 		assert REXML::Entity::matches?(simple) |     assert REXML::Entity::matches?(simple) | ||||||
| 		match = REXML::Entity::ENTITYDECL.match(simple) |     match = REXML::Entity::ENTITYDECL.match(simple) | ||||||
| 		assert_equal 'Pub-Status', match[1] |     assert_equal 'Pub-Status', match[1] | ||||||
| 		assert_equal txt, match[2] |     assert_equal txt, match[2] | ||||||
| 	end |   end | ||||||
| 
 | 
 | ||||||
| 	def test_parse_external_decl |   def test_parse_external_decl | ||||||
| 		zero = '<!ENTITY open-hatch SYSTEM "http://www.textuality.com/boilerplate/OpenHatch.xml" >' |     zero = '<!ENTITY open-hatch SYSTEM "http://www.textuality.com/boilerplate/OpenHatch.xml" >' | ||||||
| 		one = '<!ENTITY open-hatch |     one = '<!ENTITY open-hatch | ||||||
| 							SYSTEM "http://www.textuality.com/boilerplate/OpenHatch.xml">' |               SYSTEM "http://www.textuality.com/boilerplate/OpenHatch.xml">' | ||||||
| 		two = '<!ENTITY open-hatch |     two = '<!ENTITY open-hatch | ||||||
| 							PUBLIC "-//Textuality//TEXT Standard open-hatch boilerplate//EN" |               PUBLIC "-//Textuality//TEXT Standard open-hatch boilerplate//EN" | ||||||
| 						  "http://www.textuality.com/boilerplate/OpenHatch.xml">' |               "http://www.textuality.com/boilerplate/OpenHatch.xml">' | ||||||
| 		three = '<!ENTITY hatch-pic |     three = '<!ENTITY hatch-pic | ||||||
| 							SYSTEM "../grafix/OpenHatch.gif" |               SYSTEM "../grafix/OpenHatch.gif" | ||||||
| 							NDATA gif >' |               NDATA gif >' | ||||||
| 		assert REXML::Entity::matches?(zero) |     assert REXML::Entity::matches?(zero) | ||||||
| 		assert REXML::Entity::matches?(one) |     assert REXML::Entity::matches?(one) | ||||||
| 		assert REXML::Entity::matches?(two) |     assert REXML::Entity::matches?(two) | ||||||
| 		assert REXML::Entity::matches?(three) |     assert REXML::Entity::matches?(three) | ||||||
| 	end |   end | ||||||
| 
 | 
 | ||||||
| 	def test_parse_entity |   def test_parse_entity | ||||||
| 		one = %q{<!ENTITY % YN '"Yes"'>} |     one = %q{<!ENTITY % YN '"Yes"'>} | ||||||
| 		two = %q{<!ENTITY WhatHeSaid "He said %YN;">} |     two = %q{<!ENTITY WhatHeSaid "He said %YN;">} | ||||||
| 		assert REXML::Entity::matches?(one) |     assert REXML::Entity::matches?(one) | ||||||
| 		assert REXML::Entity::matches?(two) |     assert REXML::Entity::matches?(two) | ||||||
| 	end |   end | ||||||
| 
 | 
 | ||||||
| 	def test_constructor |   def test_constructor | ||||||
| 		one = [ %q{<!ENTITY % YN '"Yes"'>}, |     one = [ %q{<!ENTITY % YN '"Yes"'>}, | ||||||
| 			%q{<!ENTITY % YN2 "Yes">}, |       %q{<!ENTITY % YN2 "Yes">}, | ||||||
| 			%q{<!ENTITY WhatHeSaid "He said %YN;">}, |       %q{<!ENTITY WhatHeSaid "He said %YN;">}, | ||||||
| 			'<!ENTITY open-hatch |       '<!ENTITY open-hatch | ||||||
| 							SYSTEM "http://www.textuality.com/boilerplate/OpenHatch.xml">', |               SYSTEM "http://www.textuality.com/boilerplate/OpenHatch.xml">', | ||||||
| 			'<!ENTITY open-hatch2 |       '<!ENTITY open-hatch2 | ||||||
| 							PUBLIC "-//Textuality//TEXT Standard open-hatch boilerplate//EN" |               PUBLIC "-//Textuality//TEXT Standard open-hatch boilerplate//EN" | ||||||
| 						  "http://www.textuality.com/boilerplate/OpenHatch.xml">', |               "http://www.textuality.com/boilerplate/OpenHatch.xml">', | ||||||
| 			'<!ENTITY hatch-pic |       '<!ENTITY hatch-pic | ||||||
| 							SYSTEM "../grafix/OpenHatch.gif" |               SYSTEM "../grafix/OpenHatch.gif" | ||||||
| 							NDATA gif>' ] |               NDATA gif>' ] | ||||||
| 		source = %q{<!DOCTYPE foo [ |     source = %q{<!DOCTYPE foo [ | ||||||
| 			<!ENTITY % YN '"Yes"'> |       <!ENTITY % YN '"Yes"'> | ||||||
| 			<!ENTITY % YN2 "Yes"> |       <!ENTITY % YN2 "Yes"> | ||||||
| 			<!ENTITY WhatHeSaid "He said %YN;"> |       <!ENTITY WhatHeSaid "He said %YN;"> | ||||||
| 			<!ENTITY open-hatch |       <!ENTITY open-hatch | ||||||
| 							SYSTEM "http://www.textuality.com/boilerplate/OpenHatch.xml"> |               SYSTEM "http://www.textuality.com/boilerplate/OpenHatch.xml"> | ||||||
| 			<!ENTITY open-hatch2 |       <!ENTITY open-hatch2 | ||||||
| 							PUBLIC "-//Textuality//TEXT Standard open-hatch boilerplate//EN" |               PUBLIC "-//Textuality//TEXT Standard open-hatch boilerplate//EN" | ||||||
| 						  "http://www.textuality.com/boilerplate/OpenHatch.xml"> |               "http://www.textuality.com/boilerplate/OpenHatch.xml"> | ||||||
| 			<!ENTITY hatch-pic |       <!ENTITY hatch-pic | ||||||
| 							SYSTEM "../grafix/OpenHatch.gif" |               SYSTEM "../grafix/OpenHatch.gif" | ||||||
| 							NDATA gif> |               NDATA gif> | ||||||
| 		]>} |     ]>} | ||||||
| 
 | 
 | ||||||
| 		d = REXML::Document.new( source ) |     d = REXML::Document.new( source ) | ||||||
| 		dt = d.doctype |     dt = d.doctype | ||||||
| 		c = 0 |     c = 0 | ||||||
| 		dt.each do |child| |     dt.each do |child| | ||||||
| 			if child.kind_of? REXML::Entity |       if child.kind_of? REXML::Entity | ||||||
| 				str = one[c].tr("\r\n\t", '   ').squeeze(" ") |         str = one[c].tr("\r\n\t", '   ').squeeze(" ") | ||||||
| 				assert_equal str, child.to_s |         assert_equal str, child.to_s | ||||||
| 				c+=1 |         c+=1 | ||||||
| 			end |       end | ||||||
| 		end |     end | ||||||
| 	end |   end | ||||||
| 
 | 
 | ||||||
| 	def test_replace_entities |   def test_replace_entities | ||||||
| 		source = "<!DOCTYPE blah [\n<!ENTITY foo \"bar\">\n]><a>&foo;</a>" |     source = "<!DOCTYPE blah [\n<!ENTITY foo \"bar\">\n]><a>&foo;</a>" | ||||||
| 		doc = REXML::Document.new(source) |     doc = REXML::Document.new(source) | ||||||
| 		assert_equal 'bar', doc.root.text |     assert_equal 'bar', doc.root.text | ||||||
| 		out = '' |     out = '' | ||||||
| 		doc.write out |     doc.write out | ||||||
| 		assert_equal source, out |     assert_equal source, out | ||||||
| 	end |   end | ||||||
| 
 | 
 | ||||||
| 	def test_raw |   def test_raw | ||||||
| 		source = '<!DOCTYPE foo [ |     source = '<!DOCTYPE foo [ | ||||||
| <!ENTITY ent "replace"> | <!ENTITY ent "replace"> | ||||||
| ]><a>replace &ent;</a>' | ]><a>replace &ent;</a>' | ||||||
| 		doc = REXML::Document.new( source, {:raw=>:all}) |     doc = REXML::Document.new( source, {:raw=>:all}) | ||||||
| 		assert_equal('replace &ent;', doc.root.get_text.to_s) |     assert_equal('replace &ent;', doc.root.get_text.to_s) | ||||||
| 		assert_equal(source, doc.to_s) |     assert_equal(source, doc.to_s) | ||||||
| 	end |   end | ||||||
| 
 | 
 | ||||||
| 	def test_lazy_evaluation |   def test_lazy_evaluation | ||||||
| 		source = '<!DOCTYPE foo [ |     source = '<!DOCTYPE foo [ | ||||||
| <!ENTITY ent "replace"> | <!ENTITY ent "replace"> | ||||||
| ]><a>replace &ent;</a>' | ]><a>replace &ent;</a>' | ||||||
| 		doc = REXML::Document.new( source )  |     doc = REXML::Document.new( source )  | ||||||
| 		assert_equal(source, doc.to_s) |     assert_equal(source, doc.to_s) | ||||||
| 		assert_equal("replace replace", doc.root.text) |     assert_equal("replace replace", doc.root.text) | ||||||
| 		assert_equal(source, doc.to_s) |     assert_equal(source, doc.to_s) | ||||||
| 	end |   end | ||||||
| 
 | 
 | ||||||
| 	# Contributed (not only test, but bug fix!!) by Kouhei Sutou |   # Contributed (not only test, but bug fix!!) by Kouhei Sutou | ||||||
| 	def test_entity_replacement |   def test_entity_replacement | ||||||
| 		source = %q{<!DOCTYPE foo [ |     source = %q{<!DOCTYPE foo [ | ||||||
| 		<!ENTITY % YN '"Yes"'> |     <!ENTITY % YN '"Yes"'> | ||||||
| 		<!ENTITY WhatHeSaid "He said %YN;">]> |     <!ENTITY WhatHeSaid "He said %YN;">]> | ||||||
| 		<a>&WhatHeSaid;</a>} |     <a>&WhatHeSaid;</a>} | ||||||
| 
 | 
 | ||||||
| 		d = REXML::Document.new( source ) |     d = REXML::Document.new( source ) | ||||||
| 		dt = d.doctype |     dt = d.doctype | ||||||
| 		assert_equal( '"Yes"', dt.entities[ "YN" ].value ) |     assert_equal( '"Yes"', dt.entities[ "YN" ].value ) | ||||||
| 		assert_equal( 'He said "Yes"', dt.entities[ "WhatHeSaid" ].value ) |     assert_equal( 'He said "Yes"', dt.entities[ "WhatHeSaid" ].value ) | ||||||
| 		assert_equal( 'He said "Yes"', d.elements[1].text ) |     assert_equal( 'He said "Yes"', d.elements[1].text ) | ||||||
| 	end |   end | ||||||
| 
 | 
 | ||||||
| 	# More unit tests from Kouhei.  I looove users who give me unit tests. |   # More unit tests from Kouhei.  I looove users who give me unit tests. | ||||||
| 	def test_entity_insertions |   def test_entity_insertions | ||||||
| 		assert_equal("&", REXML::Text.new("&", false, nil, true).to_s) |     assert_equal("&", REXML::Text.new("&", false, nil, true).to_s) | ||||||
| 		#assert_equal("&", REXML::Text.new("&", false, false).to_s) |     #assert_equal("&", REXML::Text.new("&", false, false).to_s) | ||||||
| 	end |   end | ||||||
| 
 | 
 | ||||||
| 	def test_single_pass_unnormalization # ticket 123 |   def test_single_pass_unnormalization # ticket 123 | ||||||
| 		assert_equal '&&', REXML::Text::unnormalize('&amp;&') |     assert_equal '&&', REXML::Text::unnormalize('&amp;&') | ||||||
| 	end |   end | ||||||
| end | end | ||||||
|  |  | ||||||
|  | @ -3,209 +3,209 @@ require "test/unit/testcase" | ||||||
| require "rexml/document" | require "rexml/document" | ||||||
| 
 | 
 | ||||||
| class FunctionsTester < Test::Unit::TestCase | class FunctionsTester < Test::Unit::TestCase | ||||||
| 	include REXML |   include REXML | ||||||
| 	def test_functions |   def test_functions | ||||||
| 		# trivial text() test |     # trivial text() test | ||||||
| 		# confuse-a-function |     # confuse-a-function | ||||||
| 		source = "<a>more <b id='1'/><b id='2'>dumb</b><b id='3'/><c/> text</a>" |     source = "<a>more <b id='1'/><b id='2'>dumb</b><b id='3'/><c/> text</a>" | ||||||
| 		doc = Document.new source |     doc = Document.new source | ||||||
| 		res = "" |     res = "" | ||||||
| 		XPath::each(doc.root, "text()") {|val| res << val.to_s} |     XPath::each(doc.root, "text()") {|val| res << val.to_s} | ||||||
| 		assert_equal "more  text", res |     assert_equal "more  text", res | ||||||
| 
 | 
 | ||||||
| 		res = XPath::first(doc.root, "b[last()]") |     res = XPath::first(doc.root, "b[last()]") | ||||||
| 		assert_equal '3', res.attributes['id'] |     assert_equal '3', res.attributes['id'] | ||||||
| 		res = XPath::first(doc.root, "b[position()=2]") |     res = XPath::first(doc.root, "b[position()=2]") | ||||||
| 		assert_equal '2', res.attributes['id'] |     assert_equal '2', res.attributes['id'] | ||||||
| 		res = XPath::first(doc.root, "*[name()='c']") |     res = XPath::first(doc.root, "*[name()='c']") | ||||||
| 		assert_equal "c", res.name |     assert_equal "c", res.name | ||||||
| 	end |   end | ||||||
| 
 | 
 | ||||||
| 	# Contributed by Mike Stok |   # Contributed by Mike Stok | ||||||
| 	def test_starts_with |   def test_starts_with | ||||||
| 		source = <<-EOF |     source = <<-EOF | ||||||
| 			<foo> |       <foo> | ||||||
| 			<a href="mailto:a@b.c">a@b.c</a> |       <a href="mailto:a@b.c">a@b.c</a> | ||||||
| 			<a href="http://www.foo.com">http://www.foo.com</a> |       <a href="http://www.foo.com">http://www.foo.com</a> | ||||||
| 			</foo> |       </foo> | ||||||
| 		EOF |     EOF | ||||||
| 		doc = Document.new source |     doc = Document.new source | ||||||
| 		mailtos = doc.elements.to_a("//a[starts-with(@href, 'mailto:')]") |     mailtos = doc.elements.to_a("//a[starts-with(@href, 'mailto:')]") | ||||||
| 		assert_equal 1, mailtos.size |     assert_equal 1, mailtos.size | ||||||
| 		assert_equal "mailto:a@b.c", mailtos[0].attributes['href'] |     assert_equal "mailto:a@b.c", mailtos[0].attributes['href'] | ||||||
| 
 | 
 | ||||||
| 		ailtos = doc.elements.to_a("//a[starts-with(@href, 'ailto:')]") |     ailtos = doc.elements.to_a("//a[starts-with(@href, 'ailto:')]") | ||||||
| 		assert_equal 0, ailtos.size |     assert_equal 0, ailtos.size | ||||||
| 	end |   end | ||||||
| 
 | 
 | ||||||
|   def test_string_length |   def test_string_length | ||||||
| 		doc = Document.new <<-EOF |     doc = Document.new <<-EOF | ||||||
| 			<AAA> |       <AAA> | ||||||
| 			<Q/> |       <Q/> | ||||||
| 			<SSSS/> |       <SSSS/> | ||||||
| 			<BB/> |       <BB/> | ||||||
| 			<CCC/> |       <CCC/> | ||||||
| 			<DDDDDDDD/> |       <DDDDDDDD/> | ||||||
| 			<EEEE/> |       <EEEE/> | ||||||
| 			</AAA> |       </AAA> | ||||||
| 		EOF |     EOF | ||||||
| 		assert doc, "create doc" |     assert doc, "create doc" | ||||||
| 
 | 
 | ||||||
| 		set = doc.elements.to_a("//*[string-length(name()) = 3]") |     set = doc.elements.to_a("//*[string-length(name()) = 3]") | ||||||
| 		assert_equal 2, set.size, "nodes with names length = 3" |     assert_equal 2, set.size, "nodes with names length = 3" | ||||||
| 
 | 
 | ||||||
| 		set = doc.elements.to_a("//*[string-length(name()) < 3]") |     set = doc.elements.to_a("//*[string-length(name()) < 3]") | ||||||
| 		assert_equal 2, set.size, "nodes with names length < 3" |     assert_equal 2, set.size, "nodes with names length < 3" | ||||||
| 
 | 
 | ||||||
| 		set = doc.elements.to_a("//*[string-length(name()) > 3]") |     set = doc.elements.to_a("//*[string-length(name()) > 3]") | ||||||
| 		assert_equal 3, set.size, "nodes with names length > 3" |     assert_equal 3, set.size, "nodes with names length > 3" | ||||||
| 	end |   end | ||||||
| 
 | 
 | ||||||
| 	# Test provided by Mike Stok |   # Test provided by Mike Stok | ||||||
| 	def test_contains |   def test_contains | ||||||
| 		source = <<-EOF |     source = <<-EOF | ||||||
| 			<foo> |       <foo> | ||||||
| 			<a href="mailto:a@b.c">a@b.c</a> |       <a href="mailto:a@b.c">a@b.c</a> | ||||||
| 			<a href="http://www.foo.com">http://www.foo.com</a> |       <a href="http://www.foo.com">http://www.foo.com</a> | ||||||
| 			</foo> |       </foo> | ||||||
| 		EOF |     EOF | ||||||
| 		doc = Document.new source |     doc = Document.new source | ||||||
| 
 | 
 | ||||||
| 		[['o', 2], ['foo', 1], ['bar', 0]].each { |test| |     [['o', 2], ['foo', 1], ['bar', 0]].each { |test| | ||||||
| 			search, expected = test |       search, expected = test | ||||||
| 			set = doc.elements.to_a("//a[contains(@href, '#{search}')]") |       set = doc.elements.to_a("//a[contains(@href, '#{search}')]") | ||||||
| 			assert_equal expected, set.size |       assert_equal expected, set.size | ||||||
| 		} |     } | ||||||
| 	end |   end | ||||||
| 
 | 
 | ||||||
| 	# Mike Stok and Sean Russell |   # Mike Stok and Sean Russell | ||||||
| 	def test_substring |   def test_substring | ||||||
| 		# examples from http://www.w3.org/TR/xpath#function-substring |     # examples from http://www.w3.org/TR/xpath#function-substring | ||||||
| 		doc = Document.new('<test string="12345" />') |     doc = Document.new('<test string="12345" />') | ||||||
| 
 | 
 | ||||||
| 		d = Document.new("<a b='1'/>") |     d = Document.new("<a b='1'/>") | ||||||
| 		#puts XPath.first(d, 'node()[0 + 1]') |     #puts XPath.first(d, 'node()[0 + 1]') | ||||||
| 		#d = Document.new("<a b='1'/>") |     #d = Document.new("<a b='1'/>") | ||||||
| 		#puts XPath.first(d, 'a[0 mod 0]') |     #puts XPath.first(d, 'a[0 mod 0]') | ||||||
| 		[ [1.5, 2.6, '234'], |     [ [1.5, 2.6, '234'], | ||||||
| 			[0, 3, '12'], |       [0, 3, '12'], | ||||||
| 			[0, '0 div 0', ''], |       [0, '0 div 0', ''], | ||||||
| 			[1, '0 div 0', ''], |       [1, '0 div 0', ''], | ||||||
| 			['-42', '1 div 0', '12345'], |       ['-42', '1 div 0', '12345'], | ||||||
|                         ['-1 div 0', '1 div 0', ''] |                         ['-1 div 0', '1 div 0', ''] | ||||||
| 		].each { |start, length, expected| |     ].each { |start, length, expected| | ||||||
| 			set = doc.elements.to_a("//test[substring(@string, #{start}, #{length}) = '#{expected}']") |       set = doc.elements.to_a("//test[substring(@string, #{start}, #{length}) = '#{expected}']") | ||||||
| 			assert_equal 1, set.size, "#{start}, #{length}, '#{expected}'" |       assert_equal 1, set.size, "#{start}, #{length}, '#{expected}'" | ||||||
| 		} |     } | ||||||
| 	end |   end | ||||||
| 
 | 
 | ||||||
|   def test_substring_angrez |   def test_substring_angrez | ||||||
|     testString = REXML::Functions::substring_after("helloworld","hello") |     testString = REXML::Functions::substring_after("helloworld","hello") | ||||||
|     assert_equal( 'world', testString ) |     assert_equal( 'world', testString ) | ||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
| 	def test_translate |   def test_translate | ||||||
| 		source = <<-EOF |     source = <<-EOF | ||||||
| 		<doc> |     <doc> | ||||||
| 		<case name='w3c one' result='BAr' />        <!-- w3c --> |     <case name='w3c one' result='BAr' />        <!-- w3c --> | ||||||
| 		<case name='w3c two' result='AAA' />        <!-- w3c --> |     <case name='w3c two' result='AAA' />        <!-- w3c --> | ||||||
| 		<case name='alchemy' result="gold" />   <!-- mike --> |     <case name='alchemy' result="gold" />   <!-- mike --> | ||||||
| 		<case name='vbxml one' result='A Space Odyssey' /> |     <case name='vbxml one' result='A Space Odyssey' /> | ||||||
| 		<case name='vbxml two' result='AbCdEf' /> |     <case name='vbxml two' result='AbCdEf' /> | ||||||
| 		</doc> |     </doc> | ||||||
| 		EOF |     EOF | ||||||
| 
 | 
 | ||||||
| 		doc = Document.new(source) |     doc = Document.new(source) | ||||||
| 
 | 
 | ||||||
| 		[ ['bar', 'abc', 'ABC', 'w3c one'], |     [ ['bar', 'abc', 'ABC', 'w3c one'], | ||||||
| 			['--aaa--','abc-','ABC', 'w3c two'], |       ['--aaa--','abc-','ABC', 'w3c two'], | ||||||
| 			['lead', 'dear language', 'doll groover', 'alchemy'], |       ['lead', 'dear language', 'doll groover', 'alchemy'], | ||||||
| 			['A Space Odissei', 'i', 'y', 'vbxml one'], |       ['A Space Odissei', 'i', 'y', 'vbxml one'], | ||||||
| 			['abcdefg', 'aceg', 'ACE', 'vbxml two'], |       ['abcdefg', 'aceg', 'ACE', 'vbxml two'], | ||||||
| 		].each { |arg1, arg2, arg3, name| |     ].each { |arg1, arg2, arg3, name| | ||||||
| 			translate = "translate('#{arg1}', '#{arg2}', '#{arg3}')" |       translate = "translate('#{arg1}', '#{arg2}', '#{arg3}')" | ||||||
| 			set = doc.elements.to_a("//case[@result = #{translate}]") |       set = doc.elements.to_a("//case[@result = #{translate}]") | ||||||
| 			assert_equal 1, set.size, translate |       assert_equal 1, set.size, translate | ||||||
| 			assert_equal name, set[0].attributes['name'] |       assert_equal name, set[0].attributes['name'] | ||||||
| 		} |     } | ||||||
| 	end |   end | ||||||
| 
 | 
 | ||||||
| 	def test_name |   def test_name | ||||||
| 		d = REXML::Document.new("<a xmlns: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.root.elements.to_a('*[name() = "b"]').size | ||||||
| 		assert_equal 1, d.elements.to_a('//*[name() = "x:b"]').size |     assert_equal 1, d.elements.to_a('//*[name() = "x:b"]').size | ||||||
| 	end |   end | ||||||
| 
 | 
 | ||||||
| 	def test_local_name |   def test_local_name | ||||||
| 		d = REXML::Document.new("<a xmlns:x='foo'><b/><x:b/></a>") |     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.root.elements.to_a('*[local_name() = "b"]').size | ||||||
| 		assert_equal 2, d.elements.to_a('//*[local_name() = "b"]').size |     assert_equal 2, d.elements.to_a('//*[local_name() = "b"]').size | ||||||
| 	end |   end | ||||||
| 
 | 
 | ||||||
| 	def test_substring2 |   def test_substring2 | ||||||
| 		doc = Document.new('<test string="12345" />') |     doc = Document.new('<test string="12345" />') | ||||||
| 		assert_equal(1,doc.elements.to_a("//test[substring(@string,2)='2345']").size) |     assert_equal(1,doc.elements.to_a("//test[substring(@string,2)='2345']").size) | ||||||
| 	end |   end | ||||||
| 
 | 
 | ||||||
| 	# Submitted by Kouhei |   # Submitted by Kouhei | ||||||
| 	def test_floor_ceiling_round |   def test_floor_ceiling_round | ||||||
| 		source = "<a><b id='1'/><b id='2'/><b id='3'/></a>" |     source = "<a><b id='1'/><b id='2'/><b id='3'/></a>" | ||||||
| 		doc = REXML::Document.new(source) |     doc = REXML::Document.new(source) | ||||||
| 
 | 
 | ||||||
| 		id_1 = doc.elements["/a/b[@id='1']"] |     id_1 = doc.elements["/a/b[@id='1']"] | ||||||
| 		id_2 = doc.elements["/a/b[@id='2']"] |     id_2 = doc.elements["/a/b[@id='2']"] | ||||||
| 		id_3 = doc.elements["/a/b[@id='3']"] |     id_3 = doc.elements["/a/b[@id='3']"] | ||||||
| 	     |        | ||||||
| 		good = { |     good = { | ||||||
| 		  "floor" => [[], [id_1], [id_2], [id_3]], |       "floor" => [[], [id_1], [id_2], [id_3]], | ||||||
| 			"ceiling" => [[id_1], [id_2], [id_3], []], |       "ceiling" => [[id_1], [id_2], [id_3], []], | ||||||
| 			"round" => [[id_1], [id_2], [id_3], []] |       "round" => [[id_1], [id_2], [id_3], []] | ||||||
| 		} |     } | ||||||
| 		good.each do |key, value| |     good.each do |key, value| | ||||||
| 			(0..3).each do |i| |       (0..3).each do |i| | ||||||
| 				xpath = "//b[number(@id) = #{key}(#{i+0.5})]" |         xpath = "//b[number(@id) = #{key}(#{i+0.5})]" | ||||||
| 				assert_equal(value[i], REXML::XPath.match(doc, xpath)) |         assert_equal(value[i], REXML::XPath.match(doc, xpath)) | ||||||
| 			end |       end | ||||||
| 		end |     end | ||||||
| 
 | 
 | ||||||
| 		good["round"] = [[], [id_1], [id_2], [id_3]] |     good["round"] = [[], [id_1], [id_2], [id_3]] | ||||||
| 		good.each do |key, value| |     good.each do |key, value| | ||||||
| 			(0..3).each do |i| |       (0..3).each do |i| | ||||||
| 				xpath = "//b[number(@id) = #{key}(#{i+0.4})]" |         xpath = "//b[number(@id) = #{key}(#{i+0.4})]" | ||||||
| 				assert_equal(value[i], REXML::XPath.match(doc, xpath)) |         assert_equal(value[i], REXML::XPath.match(doc, xpath)) | ||||||
| 			end |       end | ||||||
| 		end |     end | ||||||
| 	end |   end | ||||||
| 
 | 
 | ||||||
| 	# Submitted by Kou |   # Submitted by Kou | ||||||
| 	def test_lang |   def test_lang | ||||||
| 		d = Document.new(<<-XML) |     d = Document.new(<<-XML) | ||||||
| 		<a xml:lang="en"> |     <a xml:lang="en"> | ||||||
| 		<b xml:lang="ja"> |     <b xml:lang="ja"> | ||||||
| 		<c xml:lang="fr"/> |     <c xml:lang="fr"/> | ||||||
| 		<d/> |     <d/> | ||||||
| 		<e xml:lang="ja-JP"/> |     <e xml:lang="ja-JP"/> | ||||||
| 		<f xml:lang="en-US"/> |     <f xml:lang="en-US"/> | ||||||
| 		</b> |     </b> | ||||||
| 		</a> |     </a> | ||||||
| 		XML |     XML | ||||||
| 
 | 
 | ||||||
| 		assert_equal(1, d.elements.to_a("//*[lang('fr')]").size) |     assert_equal(1, d.elements.to_a("//*[lang('fr')]").size) | ||||||
| 		assert_equal(3, d.elements.to_a("//*[lang('ja')]").size) |     assert_equal(3, d.elements.to_a("//*[lang('ja')]").size) | ||||||
| 		assert_equal(2, d.elements.to_a("//*[lang('en')]").size) |     assert_equal(2, d.elements.to_a("//*[lang('en')]").size) | ||||||
| 		assert_equal(1, d.elements.to_a("//*[lang('en-us')]").size) |     assert_equal(1, d.elements.to_a("//*[lang('en-us')]").size) | ||||||
| 
 | 
 | ||||||
| 		d = Document.new(<<-XML) |     d = Document.new(<<-XML) | ||||||
| 		<root> |     <root> | ||||||
| 		<para xml:lang="en"/> |     <para xml:lang="en"/> | ||||||
| 		<div xml:lang="en"><para/></div> |     <div xml:lang="en"><para/></div> | ||||||
| 		<para xml:lang="EN"/> |     <para xml:lang="EN"/> | ||||||
| 		<para xml:lang="en-us"/> |     <para xml:lang="en-us"/> | ||||||
| 		</root> |     </root> | ||||||
| 		XML |     XML | ||||||
| 
 | 
 | ||||||
| 		assert_equal(5, d.elements.to_a("//*[lang('en')]").size) |     assert_equal(5, d.elements.to_a("//*[lang('en')]").size) | ||||||
| 	end |   end | ||||||
| 
 | 
 | ||||||
|   def test_ticket_60 |   def test_ticket_60 | ||||||
|     document = REXML::Document.new("<a><b>A</b><b>1</b></a>") |     document = REXML::Document.new("<a><b>A</b><b>1</b></a>") | ||||||
|  |  | ||||||
|  | @ -28,5 +28,5 @@ class TC_Rexml_Functions_Number < Test::Unit::TestCase | ||||||
|   #  telem = REXML::Element.new("elem") |   #  telem = REXML::Element.new("elem") | ||||||
|   #  telem.text="9.13E12" |   #  telem.text="9.13E12" | ||||||
|   #  assert_equal(9.13E12, REXML::Functions::number(telem)) |   #  assert_equal(9.13E12, REXML::Functions::number(telem)) | ||||||
| 	#end  |   #end | ||||||
| end | end | ||||||
|  |  | ||||||
|  | @ -47,16 +47,16 @@ class JaxenTester < Test::Unit::TestCase | ||||||
| 
 | 
 | ||||||
|   # processes a tests/document/context node  |   # processes a tests/document/context node  | ||||||
|   def handleContext( testDoc, ctxElement) |   def handleContext( testDoc, ctxElement) | ||||||
| 	testCtx = XPath.match( testDoc, ctxElement.attributes["select"] )[0] |     testCtx = XPath.match( testDoc, ctxElement.attributes["select"] )[0] | ||||||
| 	namespaces = {}  |     namespaces = {}  | ||||||
| 	if testCtx.class == Element |     if testCtx.class == Element | ||||||
| 		testCtx.prefixes.each { |pre| handleNamespace( testCtx, pre, namespaces ) }  |       testCtx.prefixes.each { |pre| handleNamespace( testCtx, pre, namespaces ) }  | ||||||
| 	end |     end | ||||||
| 	variables = {}  |     variables = {}  | ||||||
| 	XPath.each( ctxElement, "@*[namespace-uri() = 'http://jaxen.org/test-harness/var']") { |attrib| handleVariable(testCtx, variables, attrib) } |     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, "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[not(@exception) or (@exception != 'true') ]") { |e| handleNominalTest(testCtx,variables, namespaces, e) } | ||||||
| 	XPath.each( ctxElement, "test[@exception = 'true']") { |e| handleExceptionalTest(testCtx,variables, namespaces, e) } |     XPath.each( ctxElement, "test[@exception = 'true']") { |e| handleExceptionalTest(testCtx,variables, namespaces, e) } | ||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
|   # processes a tests/document/context/valueOf or tests/document/context/test/valueOf node |   # 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 )  |   # processes a tests/document/context/test node ( where @exception is true )  | ||||||
|   def handleExceptionalTest(ctx, variables, namespaces, testElement) |   def handleExceptionalTest(ctx, variables, namespaces, testElement) | ||||||
|     assert_raise( Exception ) { |     assert_raise( Exception ) { | ||||||
|   		XPath.match( ctx, testElement.attributes["select"], namespaces, variables ) |       XPath.match( ctx, testElement.attributes["select"], namespaces, variables ) | ||||||
|     } |     } | ||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
|   # processes a tests/document node  |   # processes a tests/document node  | ||||||
|   def handleDocument(docElement) |   def handleDocument(docElement) | ||||||
|   	puts "- Processing document: #{docElement.attributes['url']}" |     puts "- Processing document: #{docElement.attributes['url']}" | ||||||
|   	testFile = File.new( docElement.attributes["url"] ) |     testFile = File.new( docElement.attributes["url"] ) | ||||||
|   	testDoc = Document.new testFile |     testDoc = Document.new testFile | ||||||
|   	XPath.each( docElement, "context") { |e| handleContext(testDoc, e) } |     XPath.each( docElement, "context") { |e| handleContext(testDoc, e) } | ||||||
|   end |   end | ||||||
|    |    | ||||||
|   # processes a variable definition in a namespace like <test var:foo="bar">  |   # processes a variable definition in a namespace like <test var:foo="bar">  | ||||||
|   def handleVariable( ctx, variables, attrib ) |   def handleVariable( ctx, variables, attrib ) | ||||||
|   	puts "--- Found attribute: #{attrib.name}" |     puts "--- Found attribute: #{attrib.name}" | ||||||
|   	variables[attrib.name] = attrib.value |     variables[attrib.name] = attrib.value | ||||||
|   end |   end | ||||||
|    |    | ||||||
|   # processes a namespace definition like <test xmlns:foo="fiz:bang:bam">  |   # processes a namespace definition like <test xmlns:foo="fiz:bang:bam">  | ||||||
|   def handleNamespace( ctx, prefix, namespaces ) |   def handleNamespace( ctx, prefix, namespaces ) | ||||||
|   	puts "--- Found namespace: #{prefix}" |     puts "--- Found namespace: #{prefix}" | ||||||
|   	namespaces[prefix] = ctx.namespaces[prefix]  |     namespaces[prefix] = ctx.namespaces[prefix]  | ||||||
|   end |   end | ||||||
|    |    | ||||||
| end | end | ||||||
|  |  | ||||||
|  | @ -6,97 +6,97 @@ class LightTester < Test::Unit::TestCase | ||||||
|   include REXMLTestUtils |   include REXMLTestUtils | ||||||
|   include REXML::Light |   include REXML::Light | ||||||
| 
 | 
 | ||||||
| 	def test_parse_large  |   def test_parse_large  | ||||||
| 		parser = REXML::Parsers::LightParser.new(fixture_path("documentation.xml")) |     parser = REXML::Parsers::LightParser.new(fixture_path("documentation.xml")) | ||||||
| 		root = parser.parse |     root = parser.parse | ||||||
| 	end |   end | ||||||
| 	 |    | ||||||
| 	# FIXME INCOMPLETE |   # FIXME INCOMPLETE | ||||||
| 	# This is because the light API is not yet ready to be used to produce |   # This is because the light API is not yet ready to be used to produce | ||||||
| 	# trees. |   # trees. | ||||||
| =begin | =begin | ||||||
| 	def test_add_element |   def test_add_element | ||||||
| 		doc = Node.new |     doc = Node.new | ||||||
| 		foo = doc.add_element( 'foo' ) |     foo = doc.add_element( 'foo' ) | ||||||
| 		assert_equal( "foo", foo.name ) |     assert_equal( "foo", foo.name ) | ||||||
| 	end |   end | ||||||
| 	 |    | ||||||
| 	def test_add_attribute |   def test_add_attribute | ||||||
| 		foo = Node.new( "a" ) |     foo = Node.new( "a" ) | ||||||
| 		foo["attr"] = "bar" |     foo["attr"] = "bar" | ||||||
| 		assert_equal( "bar", foo["attr"] ) |     assert_equal( "bar", foo["attr"] ) | ||||||
| 	end |   end | ||||||
| 
 | 
 | ||||||
| 	def test_write_document |   def test_write_document | ||||||
| 		r = make_small_document |     r = make_small_document | ||||||
| 		assert_equal( "<a><b/><c/></a>", r.to_s ) |     assert_equal( "<a><b/><c/></a>", r.to_s ) | ||||||
| 	end |   end | ||||||
| 
 | 
 | ||||||
| 	def test_add_attribute_under_namespace |   def test_add_attribute_under_namespace | ||||||
| 		foo = Node.new("a") |     foo = Node.new("a") | ||||||
| 		foo["attr", "a"] = "1" |     foo["attr", "a"] = "1" | ||||||
| 		foo["attr", "b"] = "2" |     foo["attr", "b"] = "2" | ||||||
| 		foo["attr"] = "3" |     foo["attr"] = "3" | ||||||
| 		assert_equal( '1', foo['attr', 'a'] ) |     assert_equal( '1', foo['attr', 'a'] ) | ||||||
| 		assert_equal( '2', foo['attr', 'b'] ) |     assert_equal( '2', foo['attr', 'b'] ) | ||||||
| 		assert_equal( '3', foo['attr'] ) |     assert_equal( '3', foo['attr'] ) | ||||||
| 	end |   end | ||||||
| 
 | 
 | ||||||
| 	def test_change_namespace_of_element |   def test_change_namespace_of_element | ||||||
| 		foo = Node.new |     foo = Node.new | ||||||
| 		assert_equal( '', foo.namespace ) |     assert_equal( '', foo.namespace ) | ||||||
| 		foo.namespace = 'a' |     foo.namespace = 'a' | ||||||
| 		assert_equal( 'a', foo.namespace ) |     assert_equal( 'a', foo.namespace ) | ||||||
| 	end |   end | ||||||
| 
 | 
 | ||||||
| 	def test_access_child_elements |   def test_access_child_elements | ||||||
| 		foo = make_small_document |     foo = make_small_document | ||||||
| 		assert_equal( 1, foo.size ) |     assert_equal( 1, foo.size ) | ||||||
| 		a = foo[0] |     a = foo[0] | ||||||
| 		assert_equal( 2, a.size ) |     assert_equal( 2, a.size ) | ||||||
| 		assert_equal( 'b', a[0].name ) |     assert_equal( 'b', a[0].name ) | ||||||
| 		assert_equal( 'c', a[1].name ) |     assert_equal( 'c', a[1].name ) | ||||||
| 	end |   end | ||||||
| 
 | 
 | ||||||
| 	def test_itterate_over_children |   def test_itterate_over_children | ||||||
| 		foo = make_small_document |     foo = make_small_document | ||||||
| 		ctr = 0 |     ctr = 0 | ||||||
| 		foo[0].each { ctr += 1 } |     foo[0].each { ctr += 1 } | ||||||
| 		assert_equal( 2, ctr ) |     assert_equal( 2, ctr ) | ||||||
| 	end |   end | ||||||
| 
 | 
 | ||||||
| 	def test_add_text |   def test_add_text | ||||||
| 		foo = Node.new( "a" ) |     foo = Node.new( "a" ) | ||||||
| 		foo.add_text( "Sean" ) |     foo.add_text( "Sean" ) | ||||||
| 		sean = foo[0] |     sean = foo[0] | ||||||
| 		assert( sean.node_type == :text ) |     assert( sean.node_type == :text ) | ||||||
| 	end |   end | ||||||
| 
 | 
 | ||||||
| 	def test_add_instruction |   def test_add_instruction | ||||||
| 		foo = Node.new( "a" ) |     foo = Node.new( "a" ) | ||||||
| 		foo.add_instruction( "target", "value" ) |     foo.add_instruction( "target", "value" ) | ||||||
| 		assert( foo[0].node_type == :processing_instruction ) |     assert( foo[0].node_type == :processing_instruction ) | ||||||
| 	end |   end | ||||||
| 
 | 
 | ||||||
| 	def test_add_comment |   def test_add_comment | ||||||
| 		foo = Node.new( "a" ) |     foo = Node.new( "a" ) | ||||||
| 		foo.add_comment( "target", "value" ) |     foo.add_comment( "target", "value" ) | ||||||
| 		assert( foo[0].node_type == :comment ) |     assert( foo[0].node_type == :comment ) | ||||||
| 	end |   end | ||||||
| 
 | 
 | ||||||
| 	def test_get_root |   def test_get_root | ||||||
| 		foo = Node.new( 'a' ) |     foo = Node.new( 'a' ) | ||||||
| 		10.times { foo = foo.add_element('b') } |     10.times { foo = foo.add_element('b') } | ||||||
| 		assert_equals( 'b', foo.name ) |     assert_equals( 'b', foo.name ) | ||||||
| 		assert_equals( 'a', foo.root.name ) |     assert_equals( 'a', foo.root.name ) | ||||||
| 	end |   end | ||||||
| 
 | 
 | ||||||
| 	def make_small_document |   def make_small_document | ||||||
| 		r = Node.new |     r = Node.new | ||||||
| 		a = r.add_element( "a" ) |     a = r.add_element( "a" ) | ||||||
| 		a.add_element( 'b' ) |     a.add_element( 'b' ) | ||||||
| 		a.add_element( 'c' ) |     a.add_element( 'c' ) | ||||||
| 		r |     r | ||||||
| 	end |   end | ||||||
| =end | =end | ||||||
| end | end | ||||||
|  |  | ||||||
|  | @ -3,10 +3,10 @@ require 'rexml/parsers/lightparser' | ||||||
| 
 | 
 | ||||||
| class LightParserTester < Test::Unit::TestCase | class LightParserTester < Test::Unit::TestCase | ||||||
|   include REXMLTestUtils |   include REXMLTestUtils | ||||||
| 	include REXML |   include REXML | ||||||
| 	def test_parsing |   def test_parsing | ||||||
| 		f = File.new(fixture_path("documentation.xml")) |     f = File.new(fixture_path("documentation.xml")) | ||||||
| 		parser = REXML::Parsers::LightParser.new( f ) |     parser = REXML::Parsers::LightParser.new( f ) | ||||||
| 		root = parser.parse |     root = parser.parse | ||||||
| 	end |   end | ||||||
| end | end | ||||||
|  |  | ||||||
|  | @ -7,96 +7,96 @@ require 'rexml/streamlistener' | ||||||
| 
 | 
 | ||||||
| class BaseTester < Test::Unit::TestCase | class BaseTester < Test::Unit::TestCase | ||||||
|   include REXMLTestUtils |   include REXMLTestUtils | ||||||
| 	def test_empty |   def test_empty | ||||||
| 		return unless defined? @listener |     return unless defined? @listener | ||||||
| 		# Empty. |     # Empty. | ||||||
| 		t1 = %Q{<string></string>} |     t1 = %Q{<string></string>} | ||||||
| 		assert_equal( "", @listener.parse( t1 ),  |     assert_equal( "", @listener.parse( t1 ),  | ||||||
| 			"Empty" ) |       "Empty" ) | ||||||
| 	end |   end | ||||||
| 
 | 
 | ||||||
| 	def test_space |   def test_space | ||||||
| 		return unless defined? @listener |     return unless defined? @listener | ||||||
| 		# Space. |     # Space. | ||||||
| 		t2 = %Q{<string>    </string>} |     t2 = %Q{<string>    </string>} | ||||||
| 		assert_equal( "    ", @listener.parse( t2 ), |     assert_equal( "    ", @listener.parse( t2 ), | ||||||
| 			"Space" ) |       "Space" ) | ||||||
| 	end |   end | ||||||
| 
 | 
 | ||||||
| 	def test_whitespace |   def test_whitespace | ||||||
| 		return unless defined? @listener |     return unless defined? @listener | ||||||
| 		# Whitespaces. |     # Whitespaces. | ||||||
| 		t3 = %Q{<string>RE\n \t \n \t XML</string>} |     t3 = %Q{<string>RE\n \t \n \t XML</string>} | ||||||
| 		assert_equal( "RE\n \t \n \t XML", @listener.parse( t3 ), |     assert_equal( "RE\n \t \n \t XML", @listener.parse( t3 ), | ||||||
| 			"Whitespaces" ) |       "Whitespaces" ) | ||||||
| 	end |   end | ||||||
| 
 | 
 | ||||||
| 	def test_leading_trailing_whitespace |   def test_leading_trailing_whitespace | ||||||
| 		return unless defined? @listener |     return unless defined? @listener | ||||||
| 		# Leading and trailing whitespaces. |     # Leading and trailing whitespaces. | ||||||
| 		t4 = %Q{<string>    REXML    </string>} |     t4 = %Q{<string>    REXML    </string>} | ||||||
| 		assert_equal( "    REXML    ", @listener.parse( t4 ), |     assert_equal( "    REXML    ", @listener.parse( t4 ), | ||||||
| 			"Leading and trailing whitespaces" ) |       "Leading and trailing whitespaces" ) | ||||||
| 	end |   end | ||||||
| 
 | 
 | ||||||
| 	def test_entity_reference |   def test_entity_reference | ||||||
| 		return unless defined? @listener |     return unless defined? @listener | ||||||
| 		# Entity reference. |     # Entity reference. | ||||||
| 		t5 = %Q{<string><>&lt;&gt;</string>} |     t5 = %Q{<string><>&lt;&gt;</string>} | ||||||
| 		assert_equal( "<><>", @listener.parse( t5 ), |     assert_equal( "<><>", @listener.parse( t5 ), | ||||||
| 			"Entity reference" ) |       "Entity reference" ) | ||||||
| 	end |   end | ||||||
| 
 | 
 | ||||||
| 	def test_character_reference |   def test_character_reference | ||||||
| 		return unless defined? @listener |     return unless defined? @listener | ||||||
| 		# Character reference. |     # Character reference. | ||||||
| 		t6 = %Q{<string>
</string>} |     t6 = %Q{<string>
</string>} | ||||||
| 		assert_equal( "\r", @listener.parse( t6 ), |     assert_equal( "\r", @listener.parse( t6 ), | ||||||
| 			"Character reference." ) |       "Character reference." ) | ||||||
| 	end |   end | ||||||
| 
 | 
 | ||||||
| 	def test_cr |   def test_cr | ||||||
| 		return unless defined? @listener |     return unless defined? @listener | ||||||
| 		# CR. |     # CR. | ||||||
| 		t7 = %Q{<string> \r\n \r \n </string>} |     t7 = %Q{<string> \r\n \r \n </string>} | ||||||
| 		assert_equal( " \n \n \n ".unpack("C*").inspect,  |     assert_equal( " \n \n \n ".unpack("C*").inspect,  | ||||||
| 			@listener.parse( t7 ).unpack("C*").inspect, "CR" ) |       @listener.parse( t7 ).unpack("C*").inspect, "CR" ) | ||||||
| 	end |   end | ||||||
| 
 | 
 | ||||||
| 	# The accent bug, and the code that exibits the bug, was contributed by   |   # The accent bug, and the code that exibits the bug, was contributed by   | ||||||
| 	# Guilhem Vellut |   # Guilhem Vellut | ||||||
| 	class AccentListener |   class AccentListener | ||||||
| 		def tag_start(name,attributes) |     def tag_start(name,attributes) | ||||||
| 			#p name |       #p name | ||||||
| 			#p attributes |       #p attributes | ||||||
| 		end |     end | ||||||
| 		def tag_end(name) |     def tag_end(name) | ||||||
| 			#p "/"+name |       #p "/"+name | ||||||
| 		end |     end | ||||||
| 		def xmldecl(a,b,c) |     def xmldecl(a,b,c) | ||||||
| 			#puts "#{a} #{b} #{c}" |       #puts "#{a} #{b} #{c}" | ||||||
| 		end |     end | ||||||
| 		def text(tx) |     def text(tx) | ||||||
| 			#p tx |       #p tx | ||||||
| 		end |     end | ||||||
| 	end |   end | ||||||
| 
 | 
 | ||||||
| 	def test_accents |   def test_accents | ||||||
| 		source = '<?xml version="1.0" encoding="ISO-8859-1"?> |     source = '<?xml version="1.0" encoding="ISO-8859-1"?> | ||||||
| <g> | <g> | ||||||
| <f  a="é" /> | <f  a="é" /> | ||||||
| </g>' | </g>' | ||||||
| 		doc = REXML::Document.new( source ) |     doc = REXML::Document.new( source ) | ||||||
| 		a = doc.elements['/g/f'].attribute('a') |     a = doc.elements['/g/f'].attribute('a') | ||||||
|                 if a.value.respond_to? :force_encoding |                 if a.value.respond_to? :force_encoding | ||||||
|                   a.value.force_encoding('binary') |                   a.value.force_encoding('binary') | ||||||
|                 end |                 end | ||||||
| 		assert_equal( 'é', a.value) |     assert_equal( 'é', a.value) | ||||||
| 		doc = REXML::Document.parse_stream( |     doc = REXML::Document.parse_stream( | ||||||
| 			File::new(fixture_path("stream_accents.xml")), |       File::new(fixture_path("stream_accents.xml")), | ||||||
| 			AccentListener::new |       AccentListener::new | ||||||
| 			) |       ) | ||||||
| 	end |   end | ||||||
| end | end | ||||||
| 
 | 
 | ||||||
| class MyREXMLListener | class MyREXMLListener | ||||||
|  | @ -118,12 +118,12 @@ class MyREXMLListener | ||||||
| end | end | ||||||
| 
 | 
 | ||||||
| class REXMLTester < BaseTester | class REXMLTester < BaseTester | ||||||
| 	def setup |   def setup | ||||||
| 		@listener = MyREXMLListener.new |     @listener = MyREXMLListener.new | ||||||
| 	end |   end | ||||||
| 
 | 
 | ||||||
| 	def test_character_reference_2 |   def test_character_reference_2 | ||||||
| 		t6 = %Q{<string>
</string>} |     t6 = %Q{<string>
</string>} | ||||||
| 		assert_equal( t6.strip, REXML::Document.new(t6).to_s ) |     assert_equal( t6.strip, REXML::Document.new(t6).to_s ) | ||||||
| 	end |   end | ||||||
| end | end | ||||||
|  |  | ||||||
|  | @ -2,6 +2,20 @@ require 'test/unit' | ||||||
| require 'rexml/document' | require 'rexml/document' | ||||||
| 
 | 
 | ||||||
| class OrderTester < Test::Unit::TestCase | 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 |   def initialize n | ||||||
|     @doc = REXML::Document.new(DOC) |     @doc = REXML::Document.new(DOC) | ||||||
|     @figs = REXML::XPath.match(@doc,'//figure') |     @figs = REXML::XPath.match(@doc,'//figure') | ||||||
|  | @ -21,18 +35,3 @@ class OrderTester < Test::Unit::TestCase | ||||||
|     assert_equal 'fig4', @figs[3].attributes['src'] |     assert_equal 'fig4', @figs[3].attributes['src'] | ||||||
|   end |   end | ||||||
| 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 |  | ||||||
|  |  | ||||||
|  | @ -2,8 +2,6 @@ | ||||||
| require 'test/unit' | require 'test/unit' | ||||||
| require 'rexml/document' | require 'rexml/document' | ||||||
| 
 | 
 | ||||||
| p [REXML::VERSION, RUBY_VERSION, RUBY_RELEASE_DATE] |  | ||||||
| 
 |  | ||||||
| # daz - for report by Dan Kohn in: | # daz - for report by Dan Kohn in: | ||||||
| #  http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/156328 | #  http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/156328 | ||||||
| class XPathTesterDd < Test::Unit::TestCase | class XPathTesterDd < Test::Unit::TestCase | ||||||
|  |  | ||||||
|  | @ -32,7 +32,7 @@ class StreamTester < Test::Unit::TestCase | ||||||
|     <!DOCTYPE foo [ |     <!DOCTYPE foo [ | ||||||
|       <!ENTITY ent "replace"> |       <!ENTITY ent "replace"> | ||||||
|       <!ATTLIST a |       <!ATTLIST a | ||||||
| 	     xmlns:human CDATA #FIXED "http://www.foo.com/human"> |        xmlns:human CDATA #FIXED "http://www.foo.com/human"> | ||||||
|       <!ELEMENT bar (#PCDATA)> |       <!ELEMENT bar (#PCDATA)> | ||||||
|       <!NOTATION n1 PUBLIC "-//HM//NOTATION TEST1//EN" 'urn:x-henrikmartensson.org:test5'> |       <!NOTATION n1 PUBLIC "-//HM//NOTATION TEST1//EN" 'urn:x-henrikmartensson.org:test5'> | ||||||
|     ]> |     ]> | ||||||
|  |  | ||||||
										
											
												File diff suppressed because it is too large
												Load diff
											
										
									
								
							|  | @ -10,39 +10,39 @@ class TestRexmlXpathAttributeQuery < Test::Unit::TestCase | ||||||
|   # xmlstr1 and xmlstr2 only differ in the second line - namespaces in the root element |   # xmlstr1 and xmlstr2 only differ in the second line - namespaces in the root element | ||||||
|   @@xmlstr1 = '<?xml version="1.0" encoding="UTF-8"?> |   @@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"> | <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> |   <id>http://www.google.com/calendar/feeds/me%40gmail.com</id> | ||||||
| 	<entry> |   <entry> | ||||||
| 		<id>http://www.google.com/calendar/feeds/me%40gmail.com/me%40gmail.com</id> |     <id>http://www.google.com/calendar/feeds/me%40gmail.com/me%40gmail.com</id> | ||||||
| 		<published>2007-05-16T13:42:27.942Z</published> |     <published>2007-05-16T13:42:27.942Z</published> | ||||||
| 		<updated>2007-05-15T03:29:28.000Z</updated> |     <updated>2007-05-15T03:29:28.000Z</updated> | ||||||
| 		<title type="text">My Calendar</title> |     <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="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="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"/> |     <link rel="self" type="application/atom+xml" href="http://www.google.com/calendar/feeds/me%40gmail.com/me%40gmail.com"/> | ||||||
| 		<author> |     <author> | ||||||
| 			<name>Me</name> |       <name>Me</name> | ||||||
| 			<email>me@gmail.com</email> |       <email>me@gmail.com</email> | ||||||
| 		</author> |     </author> | ||||||
| 	</entry> |   </entry> | ||||||
| </feed>' | </feed>' | ||||||
| 
 | 
 | ||||||
|    |    | ||||||
|   @@xmlstr2 = '<?xml version="1.0" encoding="UTF-8"?> |   @@xmlstr2 = '<?xml version="1.0" encoding="UTF-8"?> | ||||||
| <feed> | <feed> | ||||||
| 	<id>http://www.google.com/calendar/feeds/me%40gmail.com</id> |   <id>http://www.google.com/calendar/feeds/me%40gmail.com</id> | ||||||
| 	<entry> |   <entry> | ||||||
| 		<id>http://www.google.com/calendar/feeds/me%40gmail.com/me%40gmail.com</id> |     <id>http://www.google.com/calendar/feeds/me%40gmail.com/me%40gmail.com</id> | ||||||
| 		<published>2007-05-16T13:42:27.942Z</published> |     <published>2007-05-16T13:42:27.942Z</published> | ||||||
| 		<updated>2007-05-15T03:29:28.000Z</updated> |     <updated>2007-05-15T03:29:28.000Z</updated> | ||||||
| 		<title type="text">My Calendar</title> |     <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="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="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"/> |     <link rel="self" type="application/atom+xml" href="http://www.google.com/calendar/feeds/me%40gmail.com/me%40gmail.com"/> | ||||||
| 		<author> |     <author> | ||||||
| 			<name>Me</name> |       <name>Me</name> | ||||||
| 			<email>me@gmail.com</email> |       <email>me@gmail.com</email> | ||||||
| 		</author> |     </author> | ||||||
| 	</entry> |   </entry> | ||||||
| </feed>' | </feed>' | ||||||
|    |    | ||||||
|   # Fails |   # Fails | ||||||
|  |  | ||||||
|  | @ -1,10 +1,9 @@ | ||||||
| require "test/unit/testcase" | require "test/unit/testcase" | ||||||
| require "test/unit/ui/console/testrunner" |  | ||||||
| require "rexml/document" | require "rexml/document" | ||||||
| 
 | 
 | ||||||
| class XPathAxesTester < Test::Unit::TestCase | class XPathAxesTester < Test::Unit::TestCase | ||||||
| 	include REXML |   include REXML | ||||||
| 	SOURCE = <<-EOF |   SOURCE = <<-EOF | ||||||
|     <a id='1'> |     <a id='1'> | ||||||
|       <e id='2'> |       <e id='2'> | ||||||
|         <f id='3'/> |         <f id='3'/> | ||||||
|  | @ -15,9 +14,9 @@ class XPathAxesTester < Test::Unit::TestCase | ||||||
|     </a> |     </a> | ||||||
|     EOF |     EOF | ||||||
| 
 | 
 | ||||||
| 	def setup |   def setup | ||||||
| 	  @@doc = Document.new(SOURCE) unless defined? @@doc |     @@doc = Document.new(SOURCE) unless defined? @@doc | ||||||
| 	end |   end | ||||||
| 
 | 
 | ||||||
|   def test_preceding_sibling_axis |   def test_preceding_sibling_axis | ||||||
|     context = XPath.first(@@doc,"/a/e/f[last()]") |     context = XPath.first(@@doc,"/a/e/f[last()]") | ||||||
|  | @ -37,6 +36,3 @@ class XPathAxesTester < Test::Unit::TestCase | ||||||
|   end |   end | ||||||
| end | end | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| #Test::Unit::UI::Console::TestRunner.run(XPathAxesTester.suite) |  | ||||||
| 
 |  | ||||||
|  |  | ||||||
|  | @ -4,7 +4,7 @@ require "rexml/xpath" | ||||||
| require "rexml/parsers/xpathparser" | require "rexml/parsers/xpathparser" | ||||||
| 
 | 
 | ||||||
| class XPathPredicateTester < Test::Unit::TestCase | class XPathPredicateTester < Test::Unit::TestCase | ||||||
| 	include REXML |   include REXML | ||||||
|   SRC=<<-EOL |   SRC=<<-EOL | ||||||
|   <article> |   <article> | ||||||
|      <section role="subdivision" id="1"> |      <section role="subdivision" id="1"> | ||||||
|  |  | ||||||
|  | @ -53,8 +53,8 @@ class XpathTestCase < Test::Unit::TestCase | ||||||
|     # why isn't the text's parent node2? |     # why isn't the text's parent node2? | ||||||
|     # Also look at Comment, etc. |     # Also look at Comment, etc. | ||||||
|     assert_same(node2, textnode.parent) |     assert_same(node2, textnode.parent) | ||||||
| 		comment = REXML::Comment.new('Test comment', node2) |     comment = REXML::Comment.new('Test comment', node2) | ||||||
| 		assert_same(node2, comment.parent) |     assert_same(node2, comment.parent) | ||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
|   def test_ancestors |   def test_ancestors | ||||||
|  | @ -62,7 +62,7 @@ class XpathTestCase < Test::Unit::TestCase | ||||||
|     node2 = REXML::Element.new('b', node1) |     node2 = REXML::Element.new('b', node1) | ||||||
|     textnode = REXML::Text.new('test', false, node2) |     textnode = REXML::Text.new('test', false, node2) | ||||||
|     #textnode.parent = node2   # should be unnecessary |     #textnode.parent = node2   # should be unnecessary | ||||||
| 		assert_same node2, textnode.parent |     assert_same node2, textnode.parent | ||||||
|     nodes = @doc.get_elements('//b/ancestor::*') |     nodes = @doc.get_elements('//b/ancestor::*') | ||||||
|     assert_equal(1, nodes.size, "<b> has one element ancestor") |     assert_equal(1, nodes.size, "<b> has one element ancestor") | ||||||
|     nodes = @doc.get_elements('//b/ancestor::node()') |     nodes = @doc.get_elements('//b/ancestor::node()') | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 kou
						kou