summaryrefslogtreecommitdiff
path: root/test/rexml/functions/test_local_name.rb
blob: 97c9e74852424ed478a3550f152a6e63db89c724 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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