summaryrefslogtreecommitdiff
path: root/test/rexml/xpath/test_node_set.rb
blob: 77f26f7a6dc9b77a547f4991f5854aaf3ada82e6 (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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# frozen_string_literal: false

require_relative "../rexml_test_utils"

require "rexml/document"

module REXMLTests
  class TestXPathNodeSet < Test::Unit::TestCase
    def match(xml, xpath)
      document = REXML::Document.new(xml)
      REXML::XPath.match(document, xpath)
    end

    def test_boolean_true
      xml = <<-XML
<?xml version="1.0" encoding="UTF-8"?>
<root>
  <child/>
  <child/>
</root>
      XML
      assert_equal([true],
                   match(xml, "/root/child=true()"))
    end

    def test_boolean_false
      xml = <<-XML
<?xml version="1.0" encoding="UTF-8"?>
<root>
</root>
      XML
      assert_equal([false],
                   match(xml, "/root/child=true()"))
    end

    def test_number_true
      xml = <<-XML
<?xml version="1.0" encoding="UTF-8"?>
<root>
  <child>100</child>
  <child>200</child>
</root>
      XML
      assert_equal([true],
                   match(xml, "/root/child=100"))
    end

    def test_number_false
      xml = <<-XML
<?xml version="1.0" encoding="UTF-8"?>
<root>
  <child>100</child>
  <child>200</child>
</root>
      XML
      assert_equal([false],
                   match(xml, "/root/child=300"))
    end

    def test_string_true
      xml = <<-XML
<?xml version="1.0" encoding="UTF-8"?>
<root>
  <child>text</child>
  <child>string</child>
</root>
      XML
      assert_equal([true],
                   match(xml, "/root/child='string'"))
    end

    def test_string_false
      xml = <<-XML
<?xml version="1.0" encoding="UTF-8"?>
<root>
  <child>text</child>
  <child>string</child>
</root>
      XML
      assert_equal([false],
                   match(xml, "/root/child='nonexistent'"))
    end
  end
end