[前][次][番号順一覧][スレッド一覧]

ruby-changes:50872

From: kou <ko1@a...>
Date: Wed, 4 Apr 2018 00:51:13 +0900 (JST)
Subject: [ruby-changes:50872] kou:r63079 (trunk): rexml: Fix a XPath bug of name(node-set)

kou	2018-04-04 00:51:08 +0900 (Wed, 04 Apr 2018)

  New Revision: 63079

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=63079

  Log:
    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.

  Modified files:
    trunk/lib/rexml/functions.rb
    trunk/test/rexml/test_jaxen.rb
Index: lib/rexml/functions.rb
===================================================================
--- lib/rexml/functions.rb	(revision 63078)
+++ lib/rexml/functions.rb	(revision 63079)
@@ -86,10 +86,14 @@ module REXML https://github.com/ruby/ruby/blob/trunk/lib/rexml/functions.rb#L86
     # Helper method.
     def Functions::get_namespace( 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
         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
           yield node_set
         end
Index: test/rexml/test_jaxen.rb
===================================================================
--- test/rexml/test_jaxen.rb	(revision 63078)
+++ test/rexml/test_jaxen.rb	(revision 63079)
@@ -13,11 +13,11 @@ module REXMLTests https://github.com/ruby/ruby/blob/trunk/test/rexml/test_jaxen.rb#L13
     include REXML
 
     def test_axis ; process_test_case("axis") ; end
-    def _test_basic ; process_test_case("basic") ; end
-    def _test_basicupdate ; process_test_case("basicupdate") ; end
-    def _test_contents ; process_test_case("contents") ; end
-    def _test_defaultNamespace ; process_test_case("defaultNamespace") ; end
-    def _test_fibo ; process_test_case("fibo") ; end
+    def test_basic ; process_test_case("basic") ; end
+    def test_basicupdate ; process_test_case("basicupdate") ; end
+    def test_contents ; process_test_case("contents") ; end
+    def test_defaultNamespace ; process_test_case("defaultNamespace") ; end
+    def test_fibo ; process_test_case("fibo") ; end
     def _test_id ; process_test_case("id") ; end
     def _test_jaxen24 ; process_test_case("jaxen24") ; end
     def _test_lang ; process_test_case("lang") ; end
@@ -77,26 +77,34 @@ module REXMLTests https://github.com/ruby/ruby/blob/trunk/test/rexml/test_jaxen.rb#L77
     # processes a tests/document/context/valueOf or tests/document/context/test/valueOf node
     def process_value_of(context, variables, namespaces, value_of)
       expected = value_of.text
-      matched = XPath.first(context,
-                            value_of.attributes["select"],
-                            namespaces,
-                            variables)
+      xpath = value_of.attributes["select"]
+      matched = XPath.first(context, xpath, 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?
-        assert_nil(matched)
+        assert_nil(matched, message)
       else
         case matched
         when Element
-          assert_equal(expected, matched.name)
+          assert_equal(expected, matched.text, message)
         when Attribute, Text, Comment, TrueClass, FalseClass
-          assert_equal(expected, matched.to_s)
+          assert_equal(expected, matched.to_s, message)
         when Instruction
-          assert_equal(expected, matched.content)
-        when Integer
-          assert_equal(exected.to_f, matched)
+          assert_equal(expected, matched.content, message)
+        when Integer, Float
+          assert_equal(expected.to_f, matched, message)
         when String
-          assert_equal(expected, matched)
+          assert_equal(expected, matched, message)
         else
-          flunk("Unexpected match value: <#{matched.inspect}>")
+          flunk("#{message}\n" +
+                "Unexpected match value: <#{matched.inspect}>")
         end
       end
     end

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]