From 310a2a98601168aae8c071749b5cb572b55d5046 Mon Sep 17 00:00:00 2001 From: Kouhei Sutou Date: Sat, 25 May 2019 18:28:00 +0900 Subject: [ruby/rexml] xpath: add missing value conversions for equality and relational expressions GitHub: fix #18 Reported by Mirko Budszuhn. Thanks!!! https://github.com/ruby/rexml/commit/0dca2a2ba0 --- test/rexml/xpath/test_compare.rb | 256 ++++++++++++++++++++++++++++++++++++++ test/rexml/xpath/test_node_set.rb | 84 ------------- 2 files changed, 256 insertions(+), 84 deletions(-) create mode 100644 test/rexml/xpath/test_compare.rb delete mode 100644 test/rexml/xpath/test_node_set.rb (limited to 'test/rexml') diff --git a/test/rexml/xpath/test_compare.rb b/test/rexml/xpath/test_compare.rb new file mode 100644 index 0000000000..bb666c9b12 --- /dev/null +++ b/test/rexml/xpath/test_compare.rb @@ -0,0 +1,256 @@ +# frozen_string_literal: false + +require_relative "../rexml_test_utils" + +require "rexml/document" + +module REXMLTests + class TestXPathCompare < Test::Unit::TestCase + def match(xml, xpath) + document = REXML::Document.new(xml) + REXML::XPath.match(document, xpath) + end + + class TestEqual < self + class TestNodeSet < self + def test_boolean_true + xml = <<-XML + + + + + + XML + assert_equal([true], + match(xml, "/root/child=true()")) + end + + def test_boolean_false + xml = <<-XML + + + + XML + assert_equal([false], + match(xml, "/root/child=true()")) + end + + def test_number_true + xml = <<-XML + + + 100 + 200 + + XML + assert_equal([true], + match(xml, "/root/child=100")) + end + + def test_number_false + xml = <<-XML + + + 100 + 200 + + XML + assert_equal([false], + match(xml, "/root/child=300")) + end + + def test_string_true + xml = <<-XML + + + text + string + + XML + assert_equal([true], + match(xml, "/root/child='string'")) + end + + def test_string_false + xml = <<-XML + + + text + string + + XML + assert_equal([false], + match(xml, "/root/child='nonexistent'")) + end + end + + class TestBoolean < self + def test_number_true + xml = "" + assert_equal([true], + match(xml, "true()=1")) + end + + def test_number_false + xml = "" + assert_equal([false], + match(xml, "true()=0")) + end + + def test_string_true + xml = "" + assert_equal([true], + match(xml, "true()='string'")) + end + + def test_string_false + xml = "" + assert_equal([false], + match(xml, "true()=''")) + end + end + + class TestNumber < self + def test_string_true + xml = "" + assert_equal([true], + match(xml, "1='1'")) + end + + def test_string_false + xml = "" + assert_equal([false], + match(xml, "1='2'")) + end + end + end + + class TestGreaterThan < self + class TestNodeSet < self + def test_boolean_truex + xml = <<-XML + + + + + XML + assert_equal([true], + match(xml, "/root/child>false()")) + end + + def test_boolean_false + xml = <<-XML + + + + + XML + assert_equal([false], + match(xml, "/root/child>true()")) + end + + def test_number_true + xml = <<-XML + + + 100 + 200 + + XML + assert_equal([true], + match(xml, "/root/child>199")) + end + + def test_number_false + xml = <<-XML + + + 100 + 200 + + XML + assert_equal([false], + match(xml, "/root/child>200")) + end + + def test_string_true + xml = <<-XML + + + 100 + 200 + + XML + assert_equal([true], + match(xml, "/root/child>'199'")) + end + + def test_string_false + xml = <<-XML + + + 100 + 200 + + XML + assert_equal([false], + match(xml, "/root/child>'200'")) + end + end + + class TestBoolean < self + def test_string_true + xml = "" + assert_equal([true], + match(xml, "true()>'0'")) + end + + def test_string_false + xml = "" + assert_equal([false], + match(xml, "true()>'1'")) + end + end + + class TestNumber < self + def test_boolean_true + xml = "" + assert_equal([true], + match(xml, "true()>0")) + end + + def test_number_false + xml = "" + assert_equal([false], + match(xml, "true()>1")) + end + + def test_string_true + xml = "" + assert_equal([true], + match(xml, "1>'0'")) + end + + def test_string_false + xml = "" + assert_equal([false], + match(xml, "1>'1'")) + end + end + + class TestString < self + def test_string_true + xml = "" + assert_equal([true], + match(xml, "'1'>'0'")) + end + + def test_string_false + xml = "" + assert_equal([false], + match(xml, "'1'>'1'")) + end + end + end + end +end diff --git a/test/rexml/xpath/test_node_set.rb b/test/rexml/xpath/test_node_set.rb deleted file mode 100644 index 77f26f7a6d..0000000000 --- a/test/rexml/xpath/test_node_set.rb +++ /dev/null @@ -1,84 +0,0 @@ -# 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 - assert_equal([true], - match(xml, "/root/child=true()")) - end - - def test_boolean_false - xml = <<-XML - - - - XML - assert_equal([false], - match(xml, "/root/child=true()")) - end - - def test_number_true - xml = <<-XML - - - 100 - 200 - - XML - assert_equal([true], - match(xml, "/root/child=100")) - end - - def test_number_false - xml = <<-XML - - - 100 - 200 - - XML - assert_equal([false], - match(xml, "/root/child=300")) - end - - def test_string_true - xml = <<-XML - - - text - string - - XML - assert_equal([true], - match(xml, "/root/child='string'")) - end - - def test_string_false - xml = <<-XML - - - text - string - - XML - assert_equal([false], - match(xml, "/root/child='nonexistent'")) - end - end -end -- cgit v1.2.3