1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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
This commit is contained in:
kou 2010-09-17 13:31:16 +00:00
parent d357d7279a
commit 146bf4fdaf
12 changed files with 75 additions and 57 deletions

View file

@ -1,3 +1,7 @@
Fri Sep 17 22:29:56 2010 Kouhei Sutou <kou@cozmixng.org>
* test/rexml/: fix fixture data path. All REXML tests are worked.
Fri Sep 17 22:15:15 2010 Kouhei Sutou <kou@cozmixng.org> Fri Sep 17 22:15:15 2010 Kouhei Sutou <kou@cozmixng.org>
* test/rexml/test_listener.rb: remove needless codes. * test/rexml/test_listener.rb: remove needless codes.

View file

@ -0,0 +1,5 @@
module REXMLTestUtils
def fixture_path(*components)
File.join(File.dirname(__FILE__), "data", *components)
end
end

View file

@ -1,11 +1,13 @@
# coding: binary # coding: binary
require "test/unit/testcase"
require "rexml_test_utils"
require "rexml/document" require "rexml/document"
require "rexml/parseexception" require "rexml/parseexception"
require "rexml/formatters/default" require "rexml/formatters/default"
class ContribTester < Test::Unit::TestCase class ContribTester < Test::Unit::TestCase
include REXMLTestUtils
include REXML include REXML
XML_STRING_01 = <<DELIMITER XML_STRING_01 = <<DELIMITER
@ -275,7 +277,7 @@ EOF
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('test/data/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") )
@ -295,7 +297,7 @@ EOF
end end
def test_namespaces_in_attlist_tobias def test_namespaces_in_attlist_tobias
in_string = File.open('test/data/foo.xml', 'r') do |file| in_string = File.open(fixture_path('foo.xml'), 'r') do |file|
file.read file.read
end end
@ -309,7 +311,7 @@ EOF
# Alun ap Rhisiart # Alun ap Rhisiart
def test_less_than_in_element_content def test_less_than_in_element_content
source = File.new('test/data/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|
@ -450,8 +452,8 @@ EOL
def test_external_entity def test_external_entity
xp = '//channel/title' xp = '//channel/title'
%w{data/working.rss data/broken.rss}.each do |path| %w{working.rss broken.rss}.each do |path|
File.open(File.join( "test", 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

View file

@ -1,13 +1,13 @@
# coding: binary # coding: binary
require "test/unit/testcase"
require "rexml_test_utils"
require 'rexml/source' require 'rexml/source'
class EncodingTester < Test::Unit::TestCase class EncodingTester < Test::Unit::TestCase
include REXMLTestUtils
include REXML include REXML
TEST_DIR="test/data"
def setup def setup
@encoded = "<?xml version='1.0' encoding='ISO-8859-3'?>"+ @encoded = "<?xml version='1.0' encoding='ISO-8859-3'?>"+
"<a><b>\346</b></a>" "<a><b>\346</b></a>"
@ -85,7 +85,7 @@ class EncodingTester < Test::Unit::TestCase
end end
def test_ticket_110 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_equal( "UTF-16", utf16.encoding )
assert( utf16[0].kind_of?(REXML::XMLDecl)) assert( utf16[0].kind_of?(REXML::XMLDecl))
end end

View file

@ -1,11 +1,13 @@
require 'rexml_test_utils'
require "rexml/document" require "rexml/document"
require "rexml/xpath" require "rexml/xpath"
require 'test/unit/testcase'
# Harness to test REXML's capabilities against the test suite from Jaxen # Harness to test REXML's capabilities against the test suite from Jaxen
# ryan.a.cox@gmail.com # ryan.a.cox@gmail.com
class JaxenTester < Test::Unit::TestCase class JaxenTester < Test::Unit::TestCase
include REXMLTestUtils
include REXML include REXML
def test_axis ; test("axis") ; end def test_axis ; test("axis") ; end
@ -32,19 +34,17 @@ class JaxenTester < Test::Unit::TestCase
def test_web ; test("web") ; end def test_web ; test("web") ; end
def test_web2 ; test("web2") ; end def test_web2 ; test("web2") ; end
private
def test( fname ) def test( fname )
xml_dir = "test/data"
# Dir.entries( xml_dir ).each { |fname| # Dir.entries( xml_dir ).each { |fname|
# if fname =~ /\.xml$/ # if fname =~ /\.xml$/
file = File.new( File.join( xml_dir, fname+".xml" )) file = File.new(fixture_path(fname+".xml"))
doc = Document.new( file ) doc = Document.new( file )
XPath.each( doc, "/tests/document" ) {|e| handleDocument(e)} XPath.each( doc, "/tests/document" ) {|e| handleDocument(e)}
# end # end
# } # }
end end
private
# 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]

View file

@ -1,12 +1,13 @@
require "test/unit/testcase" require "rexml_test_utils"
require "rexml/light/node" require "rexml/light/node"
require "rexml/parsers/lightparser" require "rexml/parsers/lightparser"
include REXML::Light
class LightTester < Test::Unit::TestCase class LightTester < Test::Unit::TestCase
include REXMLTestUtils
include REXML::Light
def test_parse_large 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 root = parser.parse
end end

View file

@ -1,10 +1,11 @@
require 'test/unit/testcase' require 'rexml_test_utils'
require 'rexml/parsers/lightparser' require 'rexml/parsers/lightparser'
class LightParserTester < Test::Unit::TestCase class LightParserTester < Test::Unit::TestCase
include REXMLTestUtils
include REXML include REXML
def test_parsing def test_parsing
f = File.new( "test/data/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

View file

@ -1,9 +1,12 @@
# coding: binary # coding: binary
require 'rexml_test_utils'
require 'rexml/document' require 'rexml/document'
require 'rexml/streamlistener' require 'rexml/streamlistener'
class BaseTester < Test::Unit::TestCase class BaseTester < Test::Unit::TestCase
include REXMLTestUtils
def test_empty def test_empty
return unless defined? @listener return unless defined? @listener
# Empty. # Empty.
@ -90,7 +93,7 @@ class BaseTester < Test::Unit::TestCase
end end
assert_equal( 'é', a.value) assert_equal( 'é', a.value)
doc = REXML::Document.parse_stream( doc = REXML::Document.parse_stream(
File::new("test/data/stream_accents.xml"), File::new(fixture_path("stream_accents.xml")),
AccentListener::new AccentListener::new
) )
end end

View file

@ -1,8 +1,22 @@
require 'test/unit' require 'rexml_test_utils'
require 'rexml/document' require 'rexml/document'
require 'zlib' require 'zlib'
class OrderTester < Test::Unit::TestCase class OrderTester < Test::Unit::TestCase
include REXMLTestUtils
TESTDOC = <<END
<a>
<b/>
<x id='1'/>
<c/>
<d>
<x id='2'/>
</d>
<x id='3'/>
</a>
END
def setup def setup
@doc = REXML::Document.new(TESTDOC) @doc = REXML::Document.new(TESTDOC)
@items = REXML::XPath.match(@doc,'//x') @items = REXML::XPath.match(@doc,'//x')
@ -29,7 +43,7 @@ class OrderTester < Test::Unit::TestCase
end end
# Provided by Tom Talbott # Provided by Tom Talbott
def test_more_ordering 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 = [ actual = [
"Head south from Phinney Ave N", "Head south from Phinney Ave N",
"Turn left at N 36th St", "Turn left at N 36th St",
@ -86,16 +100,3 @@ class OrderTester < Test::Unit::TestCase
} }
end end
end end
TESTDOC = <<END
<a>
<b/>
<x id='1'/>
<c/>
<d>
<x id='2'/>
</d>
<x id='3'/>
</a>
END

View file

@ -1,11 +1,10 @@
#!/sw/bin/ruby require 'rexml_test_utils'
require 'test/unit'
require 'rexml/document' require 'rexml/document'
class TestIssuezillaParsing < Test::Unit::TestCase class TestIssuezillaParsing < Test::Unit::TestCase
include REXMLTestUtils
def test_rexml 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 ctr = 1
doc.root.each_element('//issue') do |issue| doc.root.each_element('//issue') do |issue|
assert_equal( ctr, issue.elements['issue_id'].text.to_i ) assert_equal( ctr, issue.elements['issue_id'].text.to_i )

View file

@ -1,8 +1,9 @@
require "test/unit/testcase" require "rexml_test_utils"
require 'rexml/sax2listener' require 'rexml/sax2listener'
require 'rexml/parsers/sax2parser' require 'rexml/parsers/sax2parser'
class SAX2Tester < Test::Unit::TestCase class SAX2Tester < Test::Unit::TestCase
include REXMLTestUtils
include REXML include REXML
def test_characters def test_characters
d = Document.new( "<A>@blah@</A>" ) d = Document.new( "<A>@blah@</A>" )
@ -29,7 +30,7 @@ class SAX2Tester < Test::Unit::TestCase
end end
def test_sax2 def test_sax2
f = File.new("test/data/documentation.xml") f = File.new(fixture_path("documentation.xml"))
parser = Parsers::SAX2Parser.new( f ) parser = Parsers::SAX2Parser.new( f )
# Listen to all events on the following elements # Listen to all events on the following elements
count = 0 count = 0
@ -267,7 +268,7 @@ class SAX2Tester < Test::Unit::TestCase
include REXML::SAX2Listener include REXML::SAX2Listener
end end
def test_ticket_68 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 ) parser.listen( Ticket68.new )
begin begin
parser.parse parser.parse

View file

@ -1,8 +1,9 @@
require "test/unit/testcase" require "rexml_test_utils"
require "rexml/document" require "rexml/document"
class XPathTester < Test::Unit::TestCase class XPathTester < Test::Unit::TestCase
include REXMLTestUtils
include REXML include REXML
SOURCE = <<-EOF SOURCE = <<-EOF
<a id='1'> <a id='1'>
@ -128,7 +129,7 @@ class XPathTester < Test::Unit::TestCase
assert_equal("b", XPath::first(c, "..").name) assert_equal("b", XPath::first(c, "..").name)
assert_equal("a", XPath::first(@@doc, "a/b/..").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| c = each_test(doc.root, "./Description" ) { |child|
assert_equal("Description",child.name) assert_equal("Description",child.name)
} }
@ -185,7 +186,7 @@ class XPathTester < Test::Unit::TestCase
end end
def no_test_ancestor 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 doc.elements.each("//item") { |el| print el.name
if el.attributes['x'] if el.attributes['x']
puts " -- "+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, # 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. # also from a file. It then checks each xpath against the source file.
def test_more def test_more
xmlsource = "test/data/testsrc.xml" xmlsource = fixture_path("testsrc.xml")
xpathtests = "test/data/xp.tst" xpathtests = fixture_path("xp.tst")
doc = REXML::Document.new(File.new(xmlsource)) doc = REXML::Document.new(File.new(xmlsource))
#results = "" #results = ""
@ -313,7 +314,7 @@ class XPathTester < Test::Unit::TestCase
end end
def test_lang 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 IO.read( "test/lang.xml" )
#puts XPath.match( doc, "//language/*" ).size #puts XPath.match( doc, "//language/*" ).size
@ -646,9 +647,9 @@ class XPathTester < Test::Unit::TestCase
REXML::XPath.match(doc, '/a/c[( @id )]').size ) REXML::XPath.match(doc, '/a/c[( @id )]').size )
assert_equal( 1, REXML::XPath.match(doc.root, assert_equal( 1, REXML::XPath.match(doc.root,
'/a/c[ ( @id ) ]').size ) '/a/c[ ( @id ) ]').size )
assert( 1, REXML::XPath.match(doc, assert_equal( 1, REXML::XPath.match(doc,
'/a/c [ ( @id ) ] ').size ) '/a/c [ ( @id ) ] ').size )
assert( 1, REXML::XPath.match(doc, assert_equal( 1, REXML::XPath.match(doc,
' / a / c [ ( @id ) ] ').size ) ' / a / c [ ( @id ) ] ').size )
end end
@ -895,7 +896,7 @@ class XPathTester < Test::Unit::TestCase
def test_ticket_56 def test_ticket_56
namespaces = {'h' => 'http://www.w3.org/1999/xhtml'} 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 = [] column_headers = []
@ -934,10 +935,10 @@ EOF
def test_ticket_43 def test_ticket_43
#url = http://news.search.yahoo.com/news/rss?p=market&ei=UTF-8&fl=0&x=wrt #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 ) 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 ) assert_equal( "Broward labor market's a solid performer (Miami Herald)", text )
end end
@ -995,13 +996,13 @@ EOF
end end
def test_ticket_61_text 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 doc = REXML::Document.new file
ticket_61_fixture( doc, "//div[text()='Add' and @class='ButtonText']" ) ticket_61_fixture( doc, "//div[text()='Add' and @class='ButtonText']" )
end end
def test_ticket_61_contains 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 doc = REXML::Document.new file
ticket_61_fixture( doc, "//div[contains(.,'Add') and @class='ButtonText']" ) ticket_61_fixture( doc, "//div[contains(.,'Add') and @class='ButtonText']" )
end end