summaryrefslogtreecommitdiff
path: root/test/rexml/xpath/test_node_set.rb
diff options
context:
space:
mode:
authorKouhei Sutou <kou@clear-code.com>2019-05-25 17:06:53 +0900
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2019-08-04 11:55:31 +0900
commit6ef82943978ea5816a91c32e9ff822c73d1935f9 (patch)
treef04b130680d6817b4941e74d212df6faccd02e9a /test/rexml/xpath/test_node_set.rb
parentc46ba8e9a3b1b6c13232c1af3e9f2efd4a3eec98 (diff)
[ruby/rexml] xpath: fix a bug for equality or relational expressions
GitHub: fix #17 There is a bug when they are used against node set. They should return boolean value but they returned node set. Reported by Mirko Budszuhn. Thanks!!! https://github.com/ruby/rexml/commit/a02bf38440
Diffstat (limited to 'test/rexml/xpath/test_node_set.rb')
-rw-r--r--test/rexml/xpath/test_node_set.rb84
1 files changed, 84 insertions, 0 deletions
diff --git a/test/rexml/xpath/test_node_set.rb b/test/rexml/xpath/test_node_set.rb
new file mode 100644
index 0000000000..77f26f7a6d
--- /dev/null
+++ b/test/rexml/xpath/test_node_set.rb
@@ -0,0 +1,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