mirror of
				https://github.com/ruby/ruby.git
				synced 2022-11-09 12:17:21 -05:00 
			
		
		
		
	[ruby/rexml] xpath local_name: fix a bug that nil is returned for nonexistent case
It must be an empty string.
81bc7cd4f5
			
			
This commit is contained in:
		
							parent
							
								
									5f78b138b1
								
							
						
					
					
						commit
						643344dc94
					
				
					 5 changed files with 48 additions and 2 deletions
				
			
		| 
						 | 
				
			
			@ -67,10 +67,11 @@ module REXML
 | 
			
		|||
    end
 | 
			
		||||
 | 
			
		||||
    # UNTESTED
 | 
			
		||||
    def Functions::local_name( node_set=nil )
 | 
			
		||||
      get_namespace( node_set ) do |node|
 | 
			
		||||
    def Functions::local_name(node_set=nil)
 | 
			
		||||
      get_namespace(node_set) do |node|
 | 
			
		||||
        return node.local_name
 | 
			
		||||
      end
 | 
			
		||||
      ""
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def Functions::namespace_uri( node_set=nil )
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3,6 +3,7 @@ require "test/unit/testcase"
 | 
			
		|||
 | 
			
		||||
require "rexml/document"
 | 
			
		||||
 | 
			
		||||
# TODO: Split me
 | 
			
		||||
module REXMLTests
 | 
			
		||||
  class FunctionsTester < Test::Unit::TestCase
 | 
			
		||||
    include REXML
 | 
			
		||||
							
								
								
									
										44
									
								
								test/rexml/functions/test_local_name.rb
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										44
									
								
								test/rexml/functions/test_local_name.rb
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,44 @@
 | 
			
		|||
# frozen_string_literal: false
 | 
			
		||||
 | 
			
		||||
require "test/unit"
 | 
			
		||||
require "rexml/document"
 | 
			
		||||
require "rexml/functions"
 | 
			
		||||
 | 
			
		||||
module REXMLTests
 | 
			
		||||
  class TestFunctionsLocalName < Test::Unit::TestCase
 | 
			
		||||
    def setup
 | 
			
		||||
      REXML::Functions.context = nil
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def test_one
 | 
			
		||||
      document = REXML::Document.new(<<-XML)
 | 
			
		||||
<root xmlns:x="http://example.com/x/">
 | 
			
		||||
  <x:child/>
 | 
			
		||||
</root>
 | 
			
		||||
      XML
 | 
			
		||||
      node_set = document.root.children
 | 
			
		||||
      assert_equal("child", REXML::Functions.local_name(node_set))
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def test_multiple
 | 
			
		||||
      document = REXML::Document.new(<<-XML)
 | 
			
		||||
<root xmlns:x="http://example.com/x/">
 | 
			
		||||
  <x:child1/>
 | 
			
		||||
  <x:child2/>
 | 
			
		||||
</root>
 | 
			
		||||
      XML
 | 
			
		||||
      node_set = document.root.children
 | 
			
		||||
      assert_equal("child1", REXML::Functions.local_name(node_set))
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def test_nonexistent
 | 
			
		||||
      assert_equal("", REXML::Functions.local_name([]))
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def test_context
 | 
			
		||||
      document = REXML::Document.new("<root/>")
 | 
			
		||||
      REXML::Functions.context = {node: document.root}
 | 
			
		||||
      assert_equal("root", REXML::Functions.local_name())
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue