2015-12-16 00:07:31 -05:00
|
|
|
# frozen_string_literal: false
|
2013-02-24 08:10:46 -05:00
|
|
|
require_relative 'rexml_test_utils'
|
2010-09-18 04:34:37 -04:00
|
|
|
|
|
|
|
require "rexml/document"
|
|
|
|
require "rexml/xpath"
|
|
|
|
|
|
|
|
# Harness to test REXML's capabilities against the test suite from Jaxen
|
|
|
|
# ryan.a.cox@gmail.com
|
|
|
|
|
2014-05-27 08:07:40 -04:00
|
|
|
module REXMLTests
|
2014-05-27 09:10:55 -04:00
|
|
|
class JaxenTester < Test::Unit::TestCase
|
|
|
|
include REXMLTestUtils
|
|
|
|
include REXML
|
2010-09-18 04:34:37 -04:00
|
|
|
|
2014-05-27 09:10:55 -04:00
|
|
|
def test_axis ; test("axis") ; end
|
|
|
|
def test_basic ; test("basic") ; end
|
|
|
|
def test_basicupdate ; test("basicupdate") ; end
|
|
|
|
def test_contents ; test("contents") ; end
|
|
|
|
def test_defaultNamespace ; test("defaultNamespace") ; end
|
|
|
|
def test_fibo ; test("fibo") ; end
|
|
|
|
def test_id ; test("id") ; end
|
|
|
|
def test_jaxen24 ; test("jaxen24") ; end
|
|
|
|
def test_lang ; test("lang") ; end
|
|
|
|
def test_message ; test("message") ; end
|
|
|
|
def test_moreover ; test("moreover") ; end
|
|
|
|
def test_much_ado ; test("much_ado") ; end
|
|
|
|
def test_namespaces ; test("namespaces") ; end
|
|
|
|
def test_nitf ; test("nitf") ; end
|
|
|
|
def test_numbers ; test("numbers") ; end
|
|
|
|
def test_pi ; test("pi") ; end
|
|
|
|
def test_pi2 ; test("pi2") ; end
|
|
|
|
def test_simple ; test("simple") ; end
|
|
|
|
def test_testNamespaces ; test("testNamespaces") ; end
|
|
|
|
def test_text ; test("text") ; end
|
|
|
|
def test_underscore ; test("underscore") ; end
|
|
|
|
def test_web ; test("web") ; end
|
|
|
|
def test_web2 ; test("web2") ; end
|
2010-09-18 04:34:37 -04:00
|
|
|
|
2014-05-27 09:10:55 -04:00
|
|
|
private
|
|
|
|
def test( fname )
|
|
|
|
# Dir.entries( xml_dir ).each { |fname|
|
|
|
|
# if fname =~ /\.xml$/
|
2014-05-27 09:45:04 -04:00
|
|
|
doc = File.open(fixture_path(fname+".xml")) do |file|
|
|
|
|
Document.new(file)
|
|
|
|
end
|
2014-05-27 09:10:55 -04:00
|
|
|
XPath.each( doc, "/tests/document" ) {|e| handleDocument(e)}
|
|
|
|
# end
|
|
|
|
# }
|
|
|
|
end
|
2010-09-18 04:34:37 -04:00
|
|
|
|
2014-05-27 09:10:55 -04:00
|
|
|
# processes a tests/document/context node
|
|
|
|
def handleContext( testDoc, ctxElement)
|
|
|
|
testCtx = XPath.match( testDoc, ctxElement.attributes["select"] )[0]
|
|
|
|
namespaces = {}
|
|
|
|
if testCtx.class == Element
|
|
|
|
testCtx.prefixes.each { |pre| handleNamespace( testCtx, pre, namespaces ) }
|
|
|
|
end
|
|
|
|
variables = {}
|
|
|
|
XPath.each( ctxElement, "@*[namespace-uri() = 'http://jaxen.org/test-harness/var']") { |attrib| handleVariable(testCtx, variables, attrib) }
|
|
|
|
XPath.each( ctxElement, "valueOf") { |e| handleValueOf(testCtx, variables, namespaces, e) }
|
|
|
|
XPath.each( ctxElement, "test[not(@exception) or (@exception != 'true') ]") { |e| handleNominalTest(testCtx,variables, namespaces, e) }
|
|
|
|
XPath.each( ctxElement, "test[@exception = 'true']") { |e| handleExceptionalTest(testCtx,variables, namespaces, e) }
|
2010-09-18 04:34:37 -04:00
|
|
|
end
|
|
|
|
|
2014-05-27 09:10:55 -04:00
|
|
|
# processes a tests/document/context/valueOf or tests/document/context/test/valueOf node
|
|
|
|
def handleValueOf(ctx,variables, namespaces, valueOfElement)
|
|
|
|
expected = valueOfElement.text
|
|
|
|
got = XPath.match( ctx, valueOfElement.attributes["select"], namespaces, variables )[0]
|
|
|
|
assert_true( (got.nil? && expected.nil?) || !got.nil? )
|
|
|
|
case got.class
|
|
|
|
when Element
|
|
|
|
assert_equal( got.class, Element )
|
|
|
|
when Attribute, Text, Comment, TrueClass, FalseClass
|
|
|
|
assert_equal( expected, got.to_s )
|
|
|
|
when Instruction
|
|
|
|
assert_equal( expected, got.content )
|
Use Integer instead of Fixnum and Bignum.
* object.c, numeric.c, enum.c, ext/-test-/bignum/mul.c,
lib/rexml/quickpath.rb, lib/rexml/text.rb, lib/rexml/xpath_parser.rb,
lib/rubygems/specification.rb, lib/uri/generic.rb,
bootstraptest/test_eval.rb, basictest/test.rb,
test/-ext-/bignum/test_big2str.rb, test/-ext-/bignum/test_div.rb,
test/-ext-/bignum/test_mul.rb, test/-ext-/bignum/test_str2big.rb,
test/csv/test_data_converters.rb, test/date/test_date.rb,
test/json/test_json_generate.rb, test/minitest/test_minitest_mock.rb,
test/openssl/test_cipher.rb, test/rexml/test_jaxen.rb,
test/ruby/test_array.rb, test/ruby/test_basicinstructions.rb,
test/ruby/test_bignum.rb, test/ruby/test_case.rb,
test/ruby/test_class.rb, test/ruby/test_complex.rb,
test/ruby/test_enum.rb, test/ruby/test_eval.rb,
test/ruby/test_iseq.rb, test/ruby/test_literal.rb,
test/ruby/test_math.rb, test/ruby/test_module.rb,
test/ruby/test_numeric.rb, test/ruby/test_range.rb,
test/ruby/test_rational.rb, test/ruby/test_refinement.rb,
test/ruby/test_rubyvm.rb, test/ruby/test_struct.rb,
test/ruby/test_variable.rb, test/rubygems/test_gem_specification.rb,
test/thread/test_queue.rb: Use Integer instead of Fixnum and Bignum.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55029 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-17 09:15:57 -04:00
|
|
|
when Integer
|
2014-05-27 09:10:55 -04:00
|
|
|
assert_equal( exected.to_f, got )
|
|
|
|
when String
|
|
|
|
# normalize values for comparison
|
|
|
|
got = "" if got == nil or got == ""
|
|
|
|
expected = "" if expected == nil or expected == ""
|
|
|
|
assert_equal( expected, got )
|
|
|
|
else
|
|
|
|
assert_fail( "Wassup?" )
|
|
|
|
end
|
2010-09-18 04:34:37 -04:00
|
|
|
end
|
2011-05-15 07:55:52 -04:00
|
|
|
|
|
|
|
|
2014-05-27 09:10:55 -04:00
|
|
|
# processes a tests/document/context/test node ( where @exception is false or doesn't exist )
|
|
|
|
def handleNominalTest(ctx, variables, namespaces, testElement)
|
|
|
|
expected = testElement.attributes["count"]
|
|
|
|
got = XPath.match( ctx, testElement.attributes["select"], namespaces, variables )
|
|
|
|
# might be a test with no count attribute, but nested valueOf elements
|
|
|
|
assert( expected == got.size.to_s ) if !expected.nil?
|
2011-05-15 07:55:52 -04:00
|
|
|
|
2014-05-27 09:10:55 -04:00
|
|
|
XPath.each( testElement, "valueOf") { |e|
|
|
|
|
handleValueOf(got, variables, namespaces, e)
|
|
|
|
}
|
|
|
|
end
|
2011-05-15 07:55:52 -04:00
|
|
|
|
2014-05-27 09:10:55 -04:00
|
|
|
# processes a tests/document/context/test node ( where @exception is true )
|
|
|
|
def handleExceptionalTest(ctx, variables, namespaces, testElement)
|
|
|
|
assert_raise( Exception ) {
|
|
|
|
XPath.match( ctx, testElement.attributes["select"], namespaces, variables )
|
|
|
|
}
|
|
|
|
end
|
2010-09-18 04:34:37 -04:00
|
|
|
|
2014-05-27 09:10:55 -04:00
|
|
|
# processes a tests/document node
|
|
|
|
def handleDocument(docElement)
|
|
|
|
puts "- Processing document: #{docElement.attributes['url']}"
|
|
|
|
testFile = File.new( docElement.attributes["url"] )
|
|
|
|
testDoc = Document.new testFile
|
|
|
|
XPath.each( docElement, "context") { |e| handleContext(testDoc, e) }
|
|
|
|
end
|
2011-05-15 07:55:52 -04:00
|
|
|
|
2014-05-27 09:10:55 -04:00
|
|
|
# processes a variable definition in a namespace like <test var:foo="bar">
|
|
|
|
def handleVariable( ctx, variables, attrib )
|
|
|
|
puts "--- Found attribute: #{attrib.name}"
|
|
|
|
variables[attrib.name] = attrib.value
|
|
|
|
end
|
2011-05-15 07:55:52 -04:00
|
|
|
|
2014-05-27 09:10:55 -04:00
|
|
|
# processes a namespace definition like <test xmlns:foo="fiz:bang:bam">
|
|
|
|
def handleNamespace( ctx, prefix, namespaces )
|
|
|
|
puts "--- Found namespace: #{prefix}"
|
|
|
|
namespaces[prefix] = ctx.namespaces[prefix]
|
|
|
|
end
|
2011-05-15 07:55:52 -04:00
|
|
|
|
2014-05-27 09:10:55 -04:00
|
|
|
end
|
2014-05-27 06:21:10 -04:00
|
|
|
end
|