From 146bf4fdafefc780d65f20c983d65f9cbe3bfe2d Mon Sep 17 00:00:00 2001 From: kou Date: Fri, 17 Sep 2010 13:31:16 +0000 Subject: [PATCH] * test/rexml/: fix fixture data path. All REXML tests are worked. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29284 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 4 ++++ test/rexml/rexml_test_utils.rb | 5 +++++ test/rexml/test_contrib.rb | 14 +++++++------ test/rexml/test_encoding.rb | 8 ++++---- test/rexml/test_jaxen.rb | 10 +++++----- test/rexml/test_light.rb | 9 +++++---- test/rexml/test_lightparser.rb | 5 +++-- test/rexml/test_listener.rb | 5 ++++- test/rexml/test_order.rb | 31 +++++++++++++++-------------- test/rexml/test_rexml_issuezilla.rb | 7 +++---- test/rexml/test_sax.rb | 7 ++++--- test/rexml/test_xpath.rb | 27 +++++++++++++------------ 12 files changed, 75 insertions(+), 57 deletions(-) create mode 100644 test/rexml/rexml_test_utils.rb diff --git a/ChangeLog b/ChangeLog index 5e43c83acd..dfbf78badc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Fri Sep 17 22:29:56 2010 Kouhei Sutou + + * test/rexml/: fix fixture data path. All REXML tests are worked. + Fri Sep 17 22:15:15 2010 Kouhei Sutou * test/rexml/test_listener.rb: remove needless codes. diff --git a/test/rexml/rexml_test_utils.rb b/test/rexml/rexml_test_utils.rb new file mode 100644 index 0000000000..916e73674d --- /dev/null +++ b/test/rexml/rexml_test_utils.rb @@ -0,0 +1,5 @@ +module REXMLTestUtils + def fixture_path(*components) + File.join(File.dirname(__FILE__), "data", *components) + end +end diff --git a/test/rexml/test_contrib.rb b/test/rexml/test_contrib.rb index 1559f45a5b..54ec64299e 100644 --- a/test/rexml/test_contrib.rb +++ b/test/rexml/test_contrib.rb @@ -1,11 +1,13 @@ # coding: binary -require "test/unit/testcase" + +require "rexml_test_utils" require "rexml/document" require "rexml/parseexception" require "rexml/formatters/default" class ContribTester < Test::Unit::TestCase + include REXMLTestUtils include REXML XML_STRING_01 = <\346" @@ -85,7 +85,7 @@ class EncodingTester < Test::Unit::TestCase end def test_ticket_110 - utf16 = REXML::Document.new(File.new(File.join(TEST_DIR,"ticket_110_utf16.xml"))) + utf16 = REXML::Document.new(File.new(fixture_path("ticket_110_utf16.xml"))) assert_equal( "UTF-16", utf16.encoding ) assert( utf16[0].kind_of?(REXML::XMLDecl)) end diff --git a/test/rexml/test_jaxen.rb b/test/rexml/test_jaxen.rb index 47e631ee13..0d5396264b 100644 --- a/test/rexml/test_jaxen.rb +++ b/test/rexml/test_jaxen.rb @@ -1,11 +1,13 @@ +require 'rexml_test_utils' + require "rexml/document" require "rexml/xpath" -require 'test/unit/testcase' # Harness to test REXML's capabilities against the test suite from Jaxen # ryan.a.cox@gmail.com class JaxenTester < Test::Unit::TestCase + include REXMLTestUtils include REXML def test_axis ; test("axis") ; end @@ -32,19 +34,17 @@ class JaxenTester < Test::Unit::TestCase def test_web ; test("web") ; end def test_web2 ; test("web2") ; end + private def test( fname ) - xml_dir = "test/data" # Dir.entries( xml_dir ).each { |fname| # if fname =~ /\.xml$/ - file = File.new( File.join( xml_dir, fname+".xml" )) + file = File.new(fixture_path(fname+".xml")) doc = Document.new( file ) XPath.each( doc, "/tests/document" ) {|e| handleDocument(e)} # end # } end - private - # processes a tests/document/context node def handleContext( testDoc, ctxElement) testCtx = XPath.match( testDoc, ctxElement.attributes["select"] )[0] diff --git a/test/rexml/test_light.rb b/test/rexml/test_light.rb index d0979c84da..8db830147d 100644 --- a/test/rexml/test_light.rb +++ b/test/rexml/test_light.rb @@ -1,12 +1,13 @@ -require "test/unit/testcase" +require "rexml_test_utils" require "rexml/light/node" require "rexml/parsers/lightparser" -include REXML::Light - class LightTester < Test::Unit::TestCase + include REXMLTestUtils + include REXML::Light + def test_parse_large - parser = REXML::Parsers::LightParser.new( File.new( "test/data/documentation.xml" ) ) + parser = REXML::Parsers::LightParser.new(fixture_path("documentation.xml")) root = parser.parse end diff --git a/test/rexml/test_lightparser.rb b/test/rexml/test_lightparser.rb index 14dcdc21e7..e0d44231c6 100644 --- a/test/rexml/test_lightparser.rb +++ b/test/rexml/test_lightparser.rb @@ -1,10 +1,11 @@ -require 'test/unit/testcase' +require 'rexml_test_utils' require 'rexml/parsers/lightparser' class LightParserTester < Test::Unit::TestCase + include REXMLTestUtils include REXML def test_parsing - f = File.new( "test/data/documentation.xml" ) + f = File.new(fixture_path("documentation.xml")) parser = REXML::Parsers::LightParser.new( f ) root = parser.parse end diff --git a/test/rexml/test_listener.rb b/test/rexml/test_listener.rb index e52a7e2b0f..c9b49d9abb 100644 --- a/test/rexml/test_listener.rb +++ b/test/rexml/test_listener.rb @@ -1,9 +1,12 @@ # coding: binary +require 'rexml_test_utils' + require 'rexml/document' require 'rexml/streamlistener' class BaseTester < Test::Unit::TestCase + include REXMLTestUtils def test_empty return unless defined? @listener # Empty. @@ -90,7 +93,7 @@ class BaseTester < Test::Unit::TestCase end assert_equal( 'é', a.value) doc = REXML::Document.parse_stream( - File::new("test/data/stream_accents.xml"), + File::new(fixture_path("stream_accents.xml")), AccentListener::new ) end diff --git a/test/rexml/test_order.rb b/test/rexml/test_order.rb index d694ee33d8..db1698ff57 100644 --- a/test/rexml/test_order.rb +++ b/test/rexml/test_order.rb @@ -1,8 +1,22 @@ -require 'test/unit' +require 'rexml_test_utils' require 'rexml/document' require 'zlib' class OrderTester < Test::Unit::TestCase + include REXMLTestUtils + + TESTDOC = < + + + + + + + + +END + def setup @doc = REXML::Document.new(TESTDOC) @items = REXML::XPath.match(@doc,'//x') @@ -29,7 +43,7 @@ class OrderTester < Test::Unit::TestCase end # Provided by Tom Talbott def test_more_ordering - doc = REXML::Document.new( Zlib::GzipReader.new( File.new( 'test/data/LostineRiver.kml.gz' ) ) ) + doc = REXML::Document.new(Zlib::GzipReader.new(File.new(fixture_path('LostineRiver.kml.gz')))) actual = [ "Head south from Phinney Ave N", "Turn left at N 36th St", @@ -86,16 +100,3 @@ class OrderTester < Test::Unit::TestCase } end end - -TESTDOC = < - - - - - - - - -END - diff --git a/test/rexml/test_rexml_issuezilla.rb b/test/rexml/test_rexml_issuezilla.rb index bb878340b4..a0ebfa77dd 100644 --- a/test/rexml/test_rexml_issuezilla.rb +++ b/test/rexml/test_rexml_issuezilla.rb @@ -1,11 +1,10 @@ -#!/sw/bin/ruby - -require 'test/unit' +require 'rexml_test_utils' require 'rexml/document' class TestIssuezillaParsing < Test::Unit::TestCase + include REXMLTestUtils def test_rexml - doc = REXML::Document.new(File.new("test/data/ofbiz-issues-full-177.xml")) + doc = REXML::Document.new(File.new(fixture_path("ofbiz-issues-full-177.xml"))) ctr = 1 doc.root.each_element('//issue') do |issue| assert_equal( ctr, issue.elements['issue_id'].text.to_i ) diff --git a/test/rexml/test_sax.rb b/test/rexml/test_sax.rb index daad06c5a5..e93ce8d1e7 100644 --- a/test/rexml/test_sax.rb +++ b/test/rexml/test_sax.rb @@ -1,8 +1,9 @@ -require "test/unit/testcase" +require "rexml_test_utils" require 'rexml/sax2listener' require 'rexml/parsers/sax2parser' class SAX2Tester < Test::Unit::TestCase + include REXMLTestUtils include REXML def test_characters d = Document.new( "@blah@" ) @@ -29,7 +30,7 @@ class SAX2Tester < Test::Unit::TestCase end def test_sax2 - f = File.new("test/data/documentation.xml") + f = File.new(fixture_path("documentation.xml")) parser = Parsers::SAX2Parser.new( f ) # Listen to all events on the following elements count = 0 @@ -267,7 +268,7 @@ class SAX2Tester < Test::Unit::TestCase include REXML::SAX2Listener end def test_ticket_68 - parser = REXML::Parsers::SAX2Parser.new( File.new('test/data/ticket_68.xml') ) + parser = REXML::Parsers::SAX2Parser.new(File.new(fixture_path('ticket_68.xml'))) parser.listen( Ticket68.new ) begin parser.parse diff --git a/test/rexml/test_xpath.rb b/test/rexml/test_xpath.rb index 8c834970b5..119d4c2ab5 100644 --- a/test/rexml/test_xpath.rb +++ b/test/rexml/test_xpath.rb @@ -1,8 +1,9 @@ -require "test/unit/testcase" +require "rexml_test_utils" require "rexml/document" class XPathTester < Test::Unit::TestCase + include REXMLTestUtils include REXML SOURCE = <<-EOF @@ -128,7 +129,7 @@ class XPathTester < Test::Unit::TestCase assert_equal("b", XPath::first(c, "..").name) assert_equal("a", XPath::first(@@doc, "a/b/..").name) - doc = REXML::Document.new(File.new("test/data/project.xml")) + doc = REXML::Document.new(File.new(fixture_path("project.xml"))) c = each_test(doc.root, "./Description" ) { |child| assert_equal("Description",child.name) } @@ -185,7 +186,7 @@ class XPathTester < Test::Unit::TestCase end def no_test_ancestor - doc = REXML::Document.new(File.new("test/data/testsrc.xml")) + doc = REXML::Document.new(File.new(fixture_path("testsrc.xml"))) doc.elements.each("//item") { |el| print el.name if el.attributes['x'] puts " -- "+el.attributes['x'] @@ -208,8 +209,8 @@ class XPathTester < Test::Unit::TestCase # This method reads a document from a file, and then a series of xpaths, # also from a file. It then checks each xpath against the source file. def test_more - xmlsource = "test/data/testsrc.xml" - xpathtests = "test/data/xp.tst" + xmlsource = fixture_path("testsrc.xml") + xpathtests = fixture_path("xp.tst") doc = REXML::Document.new(File.new(xmlsource)) #results = "" @@ -313,7 +314,7 @@ class XPathTester < Test::Unit::TestCase end def test_lang - doc = Document.new(File.new("test/data/lang0.xml")) + doc = Document.new(File.new(fixture_path("lang0.xml"))) #puts IO.read( "test/lang.xml" ) #puts XPath.match( doc, "//language/*" ).size @@ -646,9 +647,9 @@ class XPathTester < Test::Unit::TestCase REXML::XPath.match(doc, '/a/c[( @id )]').size ) assert_equal( 1, REXML::XPath.match(doc.root, '/a/c[ ( @id ) ]').size ) - assert( 1, REXML::XPath.match(doc, + assert_equal( 1, REXML::XPath.match(doc, '/a/c [ ( @id ) ] ').size ) - assert( 1, REXML::XPath.match(doc, + assert_equal( 1, REXML::XPath.match(doc, ' / a / c [ ( @id ) ] ').size ) end @@ -895,7 +896,7 @@ class XPathTester < Test::Unit::TestCase def test_ticket_56 namespaces = {'h' => 'http://www.w3.org/1999/xhtml'} - finaldoc = REXML::Document.new(File.read('test/data/google.2.xml')) + finaldoc = REXML::Document.new(File.read(fixture_path('google.2.xml'))) column_headers = [] @@ -934,10 +935,10 @@ EOF def test_ticket_43 #url = http://news.search.yahoo.com/news/rss?p=market&ei=UTF-8&fl=0&x=wrt - sum = Document.new(File.new("test/data/yahoo.xml")).elements.to_a("//item").size + sum = Document.new(File.new(fixture_path("yahoo.xml"))).elements.to_a("//item").size assert_equal( 10, sum ) - text = Document.new(File.new("test/data/yahoo.xml")).elements.to_a(%Q{//title[contains(text(), "'")]}).collect{|e| e.text}.join + text = Document.new(File.new(fixture_path("yahoo.xml"))).elements.to_a(%Q{//title[contains(text(), "'")]}).collect{|e| e.text}.join assert_equal( "Broward labor market's a solid performer (Miami Herald)", text ) end @@ -995,13 +996,13 @@ EOF end def test_ticket_61_text - file = File.open( "test/data/ticket_61.xml" ) + file = File.open(fixture_path("ticket_61.xml")) doc = REXML::Document.new file ticket_61_fixture( doc, "//div[text()='Add' and @class='ButtonText']" ) end def test_ticket_61_contains - file = File.open( "test/data/ticket_61.xml" ) + file = File.open(fixture_path("ticket_61.xml")) doc = REXML::Document.new file ticket_61_fixture( doc, "//div[contains(.,'Add') and @class='ButtonText']" ) end