mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
rexml: Fix a XPath bug of name(node-set)
[Bug #14600] * lib/rexml/functions.rb: Fix a bug that "name(node-set)" returns element instead of element name. * test/rexml/test_jaxen.rb: Enable more tests. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63079 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
a03e6e5e28
commit
c592ce4023
2 changed files with 31 additions and 19 deletions
|
@ -86,10 +86,14 @@ module REXML
|
||||||
# Helper method.
|
# Helper method.
|
||||||
def Functions::get_namespace( node_set = nil )
|
def Functions::get_namespace( node_set = nil )
|
||||||
if node_set == nil
|
if node_set == nil
|
||||||
yield @@context[:node] if defined? @@context[:node].namespace
|
yield @@context[:node] if @@context[:node].respond_to?(:namespace)
|
||||||
else
|
else
|
||||||
if node_set.respond_to? :each
|
if node_set.respond_to? :each
|
||||||
node_set.each { |node| yield node if defined? node.namespace }
|
result = []
|
||||||
|
node_set.each do |node|
|
||||||
|
result << yield(node) if node.respond_to?(:namespace)
|
||||||
|
end
|
||||||
|
result
|
||||||
elsif node_set.respond_to? :namespace
|
elsif node_set.respond_to? :namespace
|
||||||
yield node_set
|
yield node_set
|
||||||
end
|
end
|
||||||
|
|
|
@ -13,11 +13,11 @@ module REXMLTests
|
||||||
include REXML
|
include REXML
|
||||||
|
|
||||||
def test_axis ; process_test_case("axis") ; end
|
def test_axis ; process_test_case("axis") ; end
|
||||||
def _test_basic ; process_test_case("basic") ; end
|
def test_basic ; process_test_case("basic") ; end
|
||||||
def _test_basicupdate ; process_test_case("basicupdate") ; end
|
def test_basicupdate ; process_test_case("basicupdate") ; end
|
||||||
def _test_contents ; process_test_case("contents") ; end
|
def test_contents ; process_test_case("contents") ; end
|
||||||
def _test_defaultNamespace ; process_test_case("defaultNamespace") ; end
|
def test_defaultNamespace ; process_test_case("defaultNamespace") ; end
|
||||||
def _test_fibo ; process_test_case("fibo") ; end
|
def test_fibo ; process_test_case("fibo") ; end
|
||||||
def _test_id ; process_test_case("id") ; end
|
def _test_id ; process_test_case("id") ; end
|
||||||
def _test_jaxen24 ; process_test_case("jaxen24") ; end
|
def _test_jaxen24 ; process_test_case("jaxen24") ; end
|
||||||
def _test_lang ; process_test_case("lang") ; end
|
def _test_lang ; process_test_case("lang") ; end
|
||||||
|
@ -77,26 +77,34 @@ module REXMLTests
|
||||||
# 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 process_value_of(context, variables, namespaces, value_of)
|
def process_value_of(context, variables, namespaces, value_of)
|
||||||
expected = value_of.text
|
expected = value_of.text
|
||||||
matched = XPath.first(context,
|
xpath = value_of.attributes["select"]
|
||||||
value_of.attributes["select"],
|
matched = XPath.first(context, xpath, namespaces, variables)
|
||||||
namespaces,
|
|
||||||
variables)
|
message = ""
|
||||||
|
context.each_with_index do |node, i|
|
||||||
|
message << "Node#{i}:\n"
|
||||||
|
message << node.to_s
|
||||||
|
end
|
||||||
|
message << "XPath: <#{xpath}>\n"
|
||||||
|
message << "Matched <#{matched.class}>"
|
||||||
|
|
||||||
if expected.nil?
|
if expected.nil?
|
||||||
assert_nil(matched)
|
assert_nil(matched, message)
|
||||||
else
|
else
|
||||||
case matched
|
case matched
|
||||||
when Element
|
when Element
|
||||||
assert_equal(expected, matched.name)
|
assert_equal(expected, matched.text, message)
|
||||||
when Attribute, Text, Comment, TrueClass, FalseClass
|
when Attribute, Text, Comment, TrueClass, FalseClass
|
||||||
assert_equal(expected, matched.to_s)
|
assert_equal(expected, matched.to_s, message)
|
||||||
when Instruction
|
when Instruction
|
||||||
assert_equal(expected, matched.content)
|
assert_equal(expected, matched.content, message)
|
||||||
when Integer
|
when Integer, Float
|
||||||
assert_equal(exected.to_f, matched)
|
assert_equal(expected.to_f, matched, message)
|
||||||
when String
|
when String
|
||||||
assert_equal(expected, matched)
|
assert_equal(expected, matched, message)
|
||||||
else
|
else
|
||||||
flunk("Unexpected match value: <#{matched.inspect}>")
|
flunk("#{message}\n" +
|
||||||
|
"Unexpected match value: <#{matched.inspect}>")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue