Start re-enabling Jaxen tests
[Bug #14600] Reported by MSP-Greg. Thanks!!! * lib/rexml/xpath_parser.rb: Fix a bug that "following_siblings::*[N]" doesn't work. * test/rexml/test_jaxen.rb: Enable only axis test for now. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63057 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
a0e6607a81
commit
f0c734660f
@ -321,9 +321,10 @@ module REXML
|
|||||||
all_siblings = node.parent.children
|
all_siblings = node.parent.children
|
||||||
current_index = all_siblings.index( node )
|
current_index = all_siblings.index( node )
|
||||||
following_siblings = all_siblings[ current_index+1 .. -1 ]
|
following_siblings = all_siblings[ current_index+1 .. -1 ]
|
||||||
results += expr( path_stack.dclone, following_siblings )
|
results += following_siblings
|
||||||
end
|
end
|
||||||
nodeset = results
|
nodeset = results
|
||||||
|
node_types = ELEMENTS
|
||||||
|
|
||||||
when :preceding_sibling
|
when :preceding_sibling
|
||||||
results = []
|
results = []
|
||||||
|
@ -12,119 +12,117 @@ module REXMLTests
|
|||||||
include REXMLTestUtils
|
include REXMLTestUtils
|
||||||
include REXML
|
include REXML
|
||||||
|
|
||||||
def test_axis ; test("axis") ; end
|
def test_axis ; process_test_case("axis") ; end
|
||||||
def test_basic ; test("basic") ; end
|
def _test_basic ; process_test_case("basic") ; end
|
||||||
def test_basicupdate ; test("basicupdate") ; end
|
def _test_basicupdate ; process_test_case("basicupdate") ; end
|
||||||
def test_contents ; test("contents") ; end
|
def _test_contents ; process_test_case("contents") ; end
|
||||||
def test_defaultNamespace ; test("defaultNamespace") ; end
|
def _test_defaultNamespace ; process_test_case("defaultNamespace") ; end
|
||||||
def test_fibo ; test("fibo") ; end
|
def _test_fibo ; process_test_case("fibo") ; end
|
||||||
def test_id ; test("id") ; end
|
def _test_id ; process_test_case("id") ; end
|
||||||
def test_jaxen24 ; test("jaxen24") ; end
|
def _test_jaxen24 ; process_test_case("jaxen24") ; end
|
||||||
def test_lang ; test("lang") ; end
|
def _test_lang ; process_test_case("lang") ; end
|
||||||
def test_message ; test("message") ; end
|
def _test_message ; process_test_case("message") ; end
|
||||||
def test_moreover ; test("moreover") ; end
|
def _test_moreover ; process_test_case("moreover") ; end
|
||||||
def test_much_ado ; test("much_ado") ; end
|
def _test_much_ado ; process_test_case("much_ado") ; end
|
||||||
def test_namespaces ; test("namespaces") ; end
|
def _test_namespaces ; process_test_case("namespaces") ; end
|
||||||
def test_nitf ; test("nitf") ; end
|
def _test_nitf ; process_test_case("nitf") ; end
|
||||||
def test_numbers ; test("numbers") ; end
|
def _test_numbers ; process_test_case("numbers") ; end
|
||||||
def test_pi ; test("pi") ; end
|
def _test_pi ; process_test_case("pi") ; end
|
||||||
def test_pi2 ; test("pi2") ; end
|
def _test_pi2 ; process_test_case("pi2") ; end
|
||||||
def test_simple ; test("simple") ; end
|
def _test_simple ; process_test_case("simple") ; end
|
||||||
def test_testNamespaces ; test("testNamespaces") ; end
|
def _test_testNamespaces ; process_test_case("testNamespaces") ; end
|
||||||
def test_text ; test("text") ; end
|
def _test_text ; process_test_case("text") ; end
|
||||||
def test_underscore ; test("underscore") ; end
|
def _test_underscore ; process_test_case("underscore") ; end
|
||||||
def test_web ; test("web") ; end
|
def _test_web ; process_test_case("web") ; end
|
||||||
def test_web2 ; test("web2") ; end
|
def _test_web2 ; process_test_case("web2") ; end
|
||||||
|
|
||||||
private
|
private
|
||||||
def test( fname )
|
def process_test_case(name)
|
||||||
# Dir.entries( xml_dir ).each { |fname|
|
xml_path = "#{name}.xml"
|
||||||
# if fname =~ /\.xml$/
|
doc = File.open(fixture_path(xml_path)) do |file|
|
||||||
doc = File.open(fixture_path(fname+".xml")) do |file|
|
Document.new(file)
|
||||||
Document.new(file)
|
end
|
||||||
end
|
test_doc = File.open(fixture_path("test/tests.xml")) do |file|
|
||||||
XPath.each( doc, "/tests/document" ) {|e| handleDocument(e)}
|
Document.new(file)
|
||||||
# end
|
end
|
||||||
# }
|
XPath.each(test_doc,
|
||||||
|
"/tests/document[@url='xml/#{xml_path}']/context") do |context|
|
||||||
|
process_context(doc, context)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# processes a tests/document/context node
|
# processes a tests/document/context node
|
||||||
def handleContext( testDoc, ctxElement)
|
def process_context(doc, context)
|
||||||
testCtx = XPath.match( testDoc, ctxElement.attributes["select"] )[0]
|
test_context = XPath.match(doc, context.attributes["select"])
|
||||||
namespaces = {}
|
namespaces = context.namespaces
|
||||||
if testCtx.class == Element
|
|
||||||
testCtx.prefixes.each { |pre| handleNamespace( testCtx, pre, namespaces ) }
|
|
||||||
end
|
|
||||||
variables = {}
|
variables = {}
|
||||||
XPath.each( ctxElement, "@*[namespace-uri() = 'http://jaxen.org/test-harness/var']") { |attrib| handleVariable(testCtx, variables, attrib) }
|
var_namespace = "http://jaxen.org/test-harness/var"
|
||||||
XPath.each( ctxElement, "valueOf") { |e| handleValueOf(testCtx, variables, namespaces, e) }
|
XPath.each(context,
|
||||||
XPath.each( ctxElement, "test[not(@exception) or (@exception != 'true') ]") { |e| handleNominalTest(testCtx,variables, namespaces, e) }
|
"@*[namespace-uri() = '#{var_namespace}']") do |attribute|
|
||||||
XPath.each( ctxElement, "test[@exception = 'true']") { |e| handleExceptionalTest(testCtx,variables, namespaces, e) }
|
variables[attribute.name] = attribute.value
|
||||||
|
end
|
||||||
|
XPath.each(context, "valueOf") do |value|
|
||||||
|
process_value_of(test_context, variables, namespaces, value)
|
||||||
|
end
|
||||||
|
XPath.each(context,
|
||||||
|
"test[not(@exception) or (@exception != 'true')]") do |test|
|
||||||
|
process_nominal_test(test_context, variables, namespaces, test)
|
||||||
|
end
|
||||||
|
XPath.each(context,
|
||||||
|
"test[@exception = 'true']") do |test|
|
||||||
|
process_exceptional_test(test_context, variables, namespaces, test)
|
||||||
|
end
|
||||||
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
|
||||||
def handleValueOf(ctx,variables, namespaces, valueOfElement)
|
def process_value_of(context, variables, namespaces, value_of)
|
||||||
expected = valueOfElement.text
|
expected = value_of.text
|
||||||
got = XPath.match( ctx, valueOfElement.attributes["select"], namespaces, variables )[0]
|
matched = XPath.first(context,
|
||||||
assert_true( (got.nil? && expected.nil?) || !got.nil? )
|
value_of.attributes["select"],
|
||||||
case got.class
|
namespaces,
|
||||||
when Element
|
variables)
|
||||||
assert_equal( got.class, Element )
|
if expected.nil?
|
||||||
when Attribute, Text, Comment, TrueClass, FalseClass
|
assert_nil(matched)
|
||||||
assert_equal( expected, got.to_s )
|
|
||||||
when Instruction
|
|
||||||
assert_equal( expected, got.content )
|
|
||||||
when Integer
|
|
||||||
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
|
else
|
||||||
assert_fail( "Wassup?" )
|
case matched
|
||||||
|
when Element
|
||||||
|
assert_equal(expected, matched.name)
|
||||||
|
when Attribute, Text, Comment, TrueClass, FalseClass
|
||||||
|
assert_equal(expected, matched.to_s)
|
||||||
|
when Instruction
|
||||||
|
assert_equal(expected, matched.content)
|
||||||
|
when Integer
|
||||||
|
assert_equal(exected.to_f, matched)
|
||||||
|
when String
|
||||||
|
assert_equal(expected, matched)
|
||||||
|
else
|
||||||
|
flunk("Unexpected match value: <#{matched.inspect}>")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
# processes a tests/document/context/test node ( where @exception is false or doesn't exist )
|
# processes a tests/document/context/test node ( where @exception is false or doesn't exist )
|
||||||
def handleNominalTest(ctx, variables, namespaces, testElement)
|
def process_nominal_test(context, variables, namespaces, test)
|
||||||
expected = testElement.attributes["count"]
|
select = test.attributes["select"]
|
||||||
got = XPath.match( ctx, testElement.attributes["select"], namespaces, variables )
|
matched = XPath.match(context, select, namespaces, variables)
|
||||||
# might be a test with no count attribute, but nested valueOf elements
|
# might be a test with no count attribute, but nested valueOf elements
|
||||||
assert( expected == got.size.to_s ) if !expected.nil?
|
expected = test.attributes["count"]
|
||||||
|
if expected
|
||||||
|
assert_equal(Integer(expected, 10),
|
||||||
|
matched.size)
|
||||||
|
end
|
||||||
|
|
||||||
XPath.each( testElement, "valueOf") { |e|
|
XPath.each(test, "valueOf") do |value_of|
|
||||||
handleValueOf(got, variables, namespaces, e)
|
process_value_of(mathched, variables, namespaces, value_of)
|
||||||
}
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# 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 process_exceptional_test(context, variables, namespaces, test)
|
||||||
assert_raise( Exception ) {
|
select = test.attributes["select"]
|
||||||
XPath.match( ctx, testElement.attributes["select"], namespaces, variables )
|
assert_raise do
|
||||||
}
|
XPath.match(context, select, namespaces, variables)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# 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
|
|
||||||
|
|
||||||
# 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
|
|
||||||
|
|
||||||
# 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
|
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user