From 2a15d25a5941301b5be6bc29eb4ac97d5aafe3dc Mon Sep 17 00:00:00 2001 From: kou Date: Fri, 17 Sep 2010 13:46:56 +0000 Subject: * test/rexml/: untabify. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29285 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/rexml/test_contrib.rb | 698 ++++++++++++++++++++++----------------------- 1 file changed, 349 insertions(+), 349 deletions(-) (limited to 'test/rexml/test_contrib.rb') diff --git a/test/rexml/test_contrib.rb b/test/rexml/test_contrib.rb index 54ec64299e..785169bdd0 100644 --- a/test/rexml/test_contrib.rb +++ b/test/rexml/test_contrib.rb @@ -8,9 +8,9 @@ require "rexml/formatters/default" class ContribTester < Test::Unit::TestCase include REXMLTestUtils - include REXML + include REXML -XML_STRING_01 = < @@ -31,7 +31,7 @@ XML_STRING_01 = < DELIMITER -XML_STRING_02 = < english @@ -51,129 +51,129 @@ XML_STRING_02 = < DELIMITER - # Tobias Reif - def test_bad_doctype_Tobias - source = <<-EOF - --> - - - ' - > - ] - > - EOF - doc = REXML::Document.new source - doc.write(out="") - assert(out[/>'>/] != nil, "Couldn't find >'>") - assert(out[/\]>/] != nil, "Couldn't find ]>") - end - - # Peter Verhage - def test_namespace_Peter - source = <<-EOF - - - - - - - - EOF - doc = REXML::Document.new source - assert_equal "myprog-config", doc.root.name - count = 0 - REXML::XPath.each(doc, "x:myprog-config/x:main/x:parameter", - {"x"=>"http://someurl/program/version"}) { |element| - assert_equal "name", element.attributes["name"] - count += 1; - } - assert_equal 1, count - assert_equal "myprog-config", doc.elements["config:myprog-config"].name - end - - # Tobias Reif - def test_complex_xpath_Tobias - source = <<-EOF - - - - - - - - - - - - - EOF - # elements that have child elements - # but not grandchildren - # and not children that don't have a style attribute - # and not children that have a unique style attribute - complex_path = "*[* "+ - "and not(*/node()) "+ - "and not(*[not(@style)]) "+ - "and not(*/@style != */@style)]" - doc = REXML::Document.new source - results = REXML::XPath.match( doc.root, complex_path ) - assert(results) - assert_equal 1, results.size - assert_equal "foo", results[0].name - end - - # "Chris Morris" - def test_extra_newline_on_read_Chris - text = 'test text' - e = REXML::Element.new('Test') - e.add_text(text) + # Tobias Reif + def test_bad_doctype_Tobias + source = <<-EOF + --> + + + ' + > + ] + > + EOF + doc = REXML::Document.new source + doc.write(out="") + assert(out[/>'>/] != nil, "Couldn't find >'>") + assert(out[/\]>/] != nil, "Couldn't find ]>") + end + + # Peter Verhage + def test_namespace_Peter + source = <<-EOF + + + + + + + + EOF + doc = REXML::Document.new source + assert_equal "myprog-config", doc.root.name + count = 0 + REXML::XPath.each(doc, "x:myprog-config/x:main/x:parameter", + {"x"=>"http://someurl/program/version"}) { |element| + assert_equal "name", element.attributes["name"] + count += 1; + } + assert_equal 1, count + assert_equal "myprog-config", doc.elements["config:myprog-config"].name + end + + # Tobias Reif + def test_complex_xpath_Tobias + source = <<-EOF + + + + + + + + + + + + + EOF + # elements that have child elements + # but not grandchildren + # and not children that don't have a style attribute + # and not children that have a unique style attribute + complex_path = "*[* "+ + "and not(*/node()) "+ + "and not(*[not(@style)]) "+ + "and not(*/@style != */@style)]" + doc = REXML::Document.new source + results = REXML::XPath.match( doc.root, complex_path ) + assert(results) + assert_equal 1, results.size + assert_equal "foo", results[0].name + end + + # "Chris Morris" + def test_extra_newline_on_read_Chris + text = 'test text' + e = REXML::Element.new('Test') + e.add_text(text) REXML::Formatters::Default.new.write(e,out="") - doc = REXML::Document.new(out) - outtext = doc.root.text - - assert_equal(text, outtext) - end - - # Tobias Reif - def test_other_xpath_Tobias - schema = <<-DELIM - - - - - - - - - - - - - - - - DELIM - - doc = REXML::Document.new schema - - result = REXML::XPath.first(doc.root, 'xs:element[descendant::xs:element[@ref]]') - assert result - assert_equal "svg", result.attributes['name'] - result = REXML::XPath.first(doc, 'element[descendant::element[@ref]]') - assert_nil result - end + doc = REXML::Document.new(out) + outtext = doc.root.text + + assert_equal(text, outtext) + end + + # Tobias Reif + def test_other_xpath_Tobias + schema = <<-DELIM + + + + + + + + + + + + + + + + DELIM + + doc = REXML::Document.new schema + + result = REXML::XPath.first(doc.root, 'xs:element[descendant::xs:element[@ref]]') + assert result + assert_equal "svg", result.attributes['name'] + result = REXML::XPath.first(doc, 'element[descendant::element[@ref]]') + assert_nil result + end #this first test succeeds, to check if stuff is set up correctly def test_xpath_01_TobiasReif @@ -228,8 +228,8 @@ DELIMITER end def test_umlaut - koln_iso = "K\xf6ln" - koln_utf = "K\xc3\xb6ln" + koln_iso = "K\xf6ln" + koln_utf = "K\xc3\xb6ln" source_iso = "#{koln_iso}" source_utf = "#{koln_utf}" @@ -240,16 +240,16 @@ DELIMITER source_utf.force_encoding('utf-8') end - doc = REXML::Document.new(source_iso) - assert_equal('ISO-8859-1', doc.xml_decl.encoding) - assert_equal(koln_utf, doc.root.text) - doc.write(out="") - assert_equal(source_iso, out ) - doc.xml_decl.encoding = 'UTF-8' - doc.write(out="") - assert_equal(source_utf, out) + doc = REXML::Document.new(source_iso) + assert_equal('ISO-8859-1', doc.xml_decl.encoding) + assert_equal(koln_utf, doc.root.text) + doc.write(out="") + assert_equal(source_iso, out ) + doc.xml_decl.encoding = 'UTF-8' + doc.write(out="") + assert_equal(source_utf, out) - doc = Document.new <<-EOF + doc = Document.new <<-EOF Technik @@ -265,228 +265,228 @@ Die Technik ist das R EOF - tn = XPath.first(doc, "//nebenspalte/text()[2]") - expected_iso = "Nützliches von Flashern für Flasher." + tn = XPath.first(doc, "//nebenspalte/text()[2]") + expected_iso = "Nützliches von Flashern für Flasher." expected_utf = expected_iso.unpack('C*').pack('U*') if expected_utf.respond_to? :encode - expected_iso.force_encoding("iso-8859-1") - expected_utf.force_encoding(Encoding::UTF_8) + expected_iso.force_encoding("iso-8859-1") + expected_utf.force_encoding(Encoding::UTF_8) end - assert_equal(expected_utf, tn.to_s.strip) + assert_equal(expected_utf, tn.to_s.strip) f = REXML::Formatters::Default.new f.write( tn, Output.new(o = "", "ISO-8859-1") ) - assert_equal(expected_iso, o.strip) + assert_equal(expected_iso, o.strip) - doc = Document.new File.new(fixture_path('xmlfile-bug.xml')) - tn = XPath.first(doc, "//nebenspalte/text()[2]") - assert_equal(expected_utf, tn.to_s.strip) + doc = Document.new File.new(fixture_path('xmlfile-bug.xml')) + tn = XPath.first(doc, "//nebenspalte/text()[2]") + assert_equal(expected_utf, tn.to_s.strip) f.write( tn, Output.new(o = "", "ISO-8859-1") ) - assert_equal(expected_iso, o.strip) + assert_equal(expected_iso, o.strip) end - def test_element_cloning_namespace_Chris - aDoc = REXML::Document.new '

Dummy title

' - - anElement = anElement = aDoc.elements[1] - elementAttrPrefix = anElement.attributes.get_attribute('content').prefix - - aClone = anElement.clone - cloneAttrPrefix = aClone.attributes.get_attribute('content').prefix - - assert_equal( elementAttrPrefix , cloneAttrPrefix ) - end - - def test_namespaces_in_attlist_tobias - in_string = File.open(fixture_path('foo.xml'), 'r') do |file| - file.read - end - - doc = Document.new in_string - - assert_nil XPath.first(doc,'//leg') - assert_equal 'http://www.foo.com/human', doc.root.elements[1].namespace - assert_equal 'human leg', - XPath.first(doc, '//x:leg/text()', {'x'=>'http://www.foo.com/human'}).to_s - end - - # Alun ap Rhisiart - def test_less_than_in_element_content - source = File.new(fixture_path('ProductionSupport.xml')) - h = Hash.new - doc = REXML::Document.new source - doc.elements.each("//CommonError") { |el| - h[el.elements['Key'].text] = 'okay' - } - assert(h.include?('MotorInsuranceContract(Object)>>#error:')) - end - - # XPaths provided by Thomas Sawyer - def test_various_xpath - #@doc = REXML::Document.new('

') - doc = REXML::Document.new('

3

') - - [['/r', REXML::Element], - ['/r/p/c', REXML::Element], - ['/r/attribute::a', Attribute], - ['/r/@a', Attribute], - ['/r/attribute::*', Attribute], - ['/r/@*', Attribute], - ['/r/p/c/attribute::b', Attribute], - ['/r/p/c/@b', Attribute], - ['/r/p/c/attribute::*', Attribute], - ['/r/p/c/@*', Attribute], - ['//c/attribute::b', Attribute], - ['//c/@b', Attribute], - ['//c/attribute::*', Attribute], - ['//c/@*', Attribute], - ['.//node()', REXML::Node ], - ['.//node()[@a]', REXML::Element ], - ['.//node()[@a="1"]', REXML::Element ], - ['.//node()[@b]', REXML::Element ], # no show, why? - ['.//node()[@b="2"]', REXML::Element ] - ].each do |xpath,kind| - begin - REXML::XPath.each( doc, xpath ) do |what| - assert_kind_of( kind, what, "\n\nWrong type (#{what.class}) returned for #{xpath} (expected #{kind.name})\n\n" ) - end - rescue Exception - puts "PATH WAS: #{xpath}" - raise - end - end - - [ - ['/r', 'attribute::a', Attribute ], - ['/r', '@a', Attribute ], - ['/r', 'attribute::*', Attribute ], - ['/r', '@*', Attribute ], - ['/r/p/c', 'attribute::b', Attribute ], - ['/r/p/c', '@b', Attribute ], - ['/r/p/c', 'attribute::*', Attribute ], - ['/r/p/c', '@*', Attribute ] - ].each do |nodepath, xpath, kind| - begin - context = REXML::XPath.first(doc, nodepath) - REXML::XPath.each( context, xpath ) do |what| - assert_kind_of kind, what, "Wrong type (#{what.class}) returned for #{xpath} (expected #{kind.name})\n" - end - rescue Exception - puts "PATH WAS: #{xpath}" - raise - end - end - end - - def test_entities_Holden_Glova - document = <<-EOL - - - - - - - - - - - - - ]> - - - - - uga.rb - 0444 - &rbconfig.libdir;/rexml - ... the file here - - - booga.h - 0444 - &rbconfig.includedir; - ... the file here - - - foo.so - 0555 - &rbconfig.sitearchdir;/rexml - Li4uIHRoZSBmaWxlIGhlcmU=\n - - - - - EOL - - file_xpath = '/rubynet/pkg/files/file' - - root = REXML::Document.new(document) - - root.elements.each(file_xpath) do |metadata| - text = metadata.elements['path'].get_text.value - assert text !~ /&rbconfig/, "'#{text}' failed" - end - - #Error occurred in test_package_file_opens(TC_PackageInstall): - # ArgumentError: - #illegal access mode &rbconfig.prefix;/lib/rexml - # - #[synack@Evergreen] src $ ruby --version - #ruby 1.6.7 (2002-03-01) [i686-linux-gnu] - # - #It looks like it expanded the first entity, but didn't reparse it for more - #entities. possible bug - or have I mucked this up? - end - - def test_whitespace_after_xml_decl - d = Document.new <Dummy title' + + anElement = anElement = aDoc.elements[1] + elementAttrPrefix = anElement.attributes.get_attribute('content').prefix + + aClone = anElement.clone + cloneAttrPrefix = aClone.attributes.get_attribute('content').prefix + + assert_equal( elementAttrPrefix , cloneAttrPrefix ) + end + + def test_namespaces_in_attlist_tobias + in_string = File.open(fixture_path('foo.xml'), 'r') do |file| + file.read + end + + doc = Document.new in_string + + assert_nil XPath.first(doc,'//leg') + assert_equal 'http://www.foo.com/human', doc.root.elements[1].namespace + assert_equal 'human leg', + XPath.first(doc, '//x:leg/text()', {'x'=>'http://www.foo.com/human'}).to_s + end + + # Alun ap Rhisiart + def test_less_than_in_element_content + source = File.new(fixture_path('ProductionSupport.xml')) + h = Hash.new + doc = REXML::Document.new source + doc.elements.each("//CommonError") { |el| + h[el.elements['Key'].text] = 'okay' + } + assert(h.include?('MotorInsuranceContract(Object)>>#error:')) + end + + # XPaths provided by Thomas Sawyer + def test_various_xpath + #@doc = REXML::Document.new('

') + doc = REXML::Document.new('

3

') + + [['/r', REXML::Element], + ['/r/p/c', REXML::Element], + ['/r/attribute::a', Attribute], + ['/r/@a', Attribute], + ['/r/attribute::*', Attribute], + ['/r/@*', Attribute], + ['/r/p/c/attribute::b', Attribute], + ['/r/p/c/@b', Attribute], + ['/r/p/c/attribute::*', Attribute], + ['/r/p/c/@*', Attribute], + ['//c/attribute::b', Attribute], + ['//c/@b', Attribute], + ['//c/attribute::*', Attribute], + ['//c/@*', Attribute], + ['.//node()', REXML::Node ], + ['.//node()[@a]', REXML::Element ], + ['.//node()[@a="1"]', REXML::Element ], + ['.//node()[@b]', REXML::Element ], # no show, why? + ['.//node()[@b="2"]', REXML::Element ] + ].each do |xpath,kind| + begin + REXML::XPath.each( doc, xpath ) do |what| + assert_kind_of( kind, what, "\n\nWrong type (#{what.class}) returned for #{xpath} (expected #{kind.name})\n\n" ) + end + rescue Exception + puts "PATH WAS: #{xpath}" + raise + end + end + + [ + ['/r', 'attribute::a', Attribute ], + ['/r', '@a', Attribute ], + ['/r', 'attribute::*', Attribute ], + ['/r', '@*', Attribute ], + ['/r/p/c', 'attribute::b', Attribute ], + ['/r/p/c', '@b', Attribute ], + ['/r/p/c', 'attribute::*', Attribute ], + ['/r/p/c', '@*', Attribute ] + ].each do |nodepath, xpath, kind| + begin + context = REXML::XPath.first(doc, nodepath) + REXML::XPath.each( context, xpath ) do |what| + assert_kind_of kind, what, "Wrong type (#{what.class}) returned for #{xpath} (expected #{kind.name})\n" + end + rescue Exception + puts "PATH WAS: #{xpath}" + raise + end + end + end + + def test_entities_Holden_Glova + document = <<-EOL + + + + + + + + + + + + + ]> + + + + + uga.rb + 0444 + &rbconfig.libdir;/rexml + ... the file here + + + booga.h + 0444 + &rbconfig.includedir; + ... the file here + + + foo.so + 0555 + &rbconfig.sitearchdir;/rexml + Li4uIHRoZSBmaWxlIGhlcmU=\n + + + + + EOL + + file_xpath = '/rubynet/pkg/files/file' + + root = REXML::Document.new(document) + + root.elements.each(file_xpath) do |metadata| + text = metadata.elements['path'].get_text.value + assert text !~ /&rbconfig/, "'#{text}' failed" + end + + #Error occurred in test_package_file_opens(TC_PackageInstall): + # ArgumentError: + #illegal access mode &rbconfig.prefix;/lib/rexml + # + #[synack@Evergreen] src $ ruby --version + #ruby 1.6.7 (2002-03-01) [i686-linux-gnu] + # + #It looks like it expanded the first entity, but didn't reparse it for more + #entities. possible bug - or have I mucked this up? + end + + def test_whitespace_after_xml_decl + d = Document.new < - - + + EOL - end + end - def test_external_entity - xp = '//channel/title' + def test_external_entity + xp = '//channel/title' - %w{working.rss broken.rss}.each do |path| - File.open(File.join(fixture_path(path))) do |file| - doc = REXML::Document.new file.readlines.join('') + %w{working.rss broken.rss}.each do |path| + File.open(File.join(fixture_path(path))) do |file| + doc = REXML::Document.new file.readlines.join('') - # check to make sure everything is kosher - assert_equal( doc.root.class, REXML::Element ) - assert_equal( doc.root.elements.class, REXML::Elements ) + # check to make sure everything is kosher + assert_equal( doc.root.class, REXML::Element ) + assert_equal( doc.root.elements.class, REXML::Elements ) - # get the title of the feed - assert( doc.root.elements[xp].kind_of?( REXML::Element ) ) - end - end - end + # get the title of the feed + assert( doc.root.elements[xp].kind_of?( REXML::Element ) ) + end + end + end - def test_maintain_dtd - src = %q{ + def test_maintain_dtd + src = %q{ %extern-packages; %extern-common; ]>} - doc = Document.new( src ) - doc.write( out="" ) - src = src.tr('"', "'") - out = out.tr('"', "'") - assert_equal( src, out ) - end - - def test_text_nodes_nomatch - source = "test" - d = REXML::Document.new( source ) - r = REXML::XPath.match( d, %q{/root/child[text()="no-test"]} ) - assert_equal( 0, r.size ) - end + doc = Document.new( src ) + doc.write( out="" ) + src = src.tr('"', "'") + out = out.tr('"', "'") + assert_equal( src, out ) + end + + def test_text_nodes_nomatch + source = "test" + d = REXML::Document.new( source ) + r = REXML::XPath.match( d, %q{/root/child[text()="no-test"]} ) + assert_equal( 0, r.size ) + end def test_raw_Terje_Elde f = REXML::Formatters::Default.new @@ -560,24 +560,24 @@ EOL =begin # This is a silly test, and is low priority def test_namespace_serialization_tobi_reif - doc = Document.new ' + doc = Document.new ' ' - ns = 'http://www.foo.foo' - ns_declaration={'f'=>ns} - returned = XPath.match(doc,'//f:p',ns_declaration) - # passes: - assert( (returned[0].namespace==ns), 'namespace should be '+ns) - serialized = returned.to_s - serialized_and_parsed = Document.new(serialized) - puts 'serialized: '+serialized - # ... currently brings - # prefix b is undeclared (!) - assert( (serialized_and_parsed.namespace==ns), - 'namespace should still be '+ns.inspect+ - ' and not '+serialized_and_parsed.namespace.inspect) - # ... currently results in a failure: - # 'namespace should still be "http://www.foo.foo" and not ""' + ns = 'http://www.foo.foo' + ns_declaration={'f'=>ns} + returned = XPath.match(doc,'//f:p',ns_declaration) + # passes: + assert( (returned[0].namespace==ns), 'namespace should be '+ns) + serialized = returned.to_s + serialized_and_parsed = Document.new(serialized) + puts 'serialized: '+serialized + # ... currently brings + # prefix b is undeclared (!) + assert( (serialized_and_parsed.namespace==ns), + 'namespace should still be '+ns.inspect+ + ' and not '+serialized_and_parsed.namespace.inspect) + # ... currently results in a failure: + # 'namespace should still be "http://www.foo.foo" and not ""' end =end end -- cgit v1.2.3