Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
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!!!
- Loading branch information
Showing
with
178 additions
and 114 deletions.
- +0 −33 lib/rexml/syncenumerator.rb
- +86 −77 lib/rexml/xpath_parser.rb
- +8 −4 test/rexml/xpath/test_base.rb
- +84 −0 test/rexml/xpath/test_node_set.rb
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -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 |