Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/rexml/xpath_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,8 @@ def expr( path_stack, nodeset, context=nil )
when :div
return left / right
when :mod
return left % right
return Float::NAN if right.zero?
return left.remainder(right)
when :mult
return left * right
when :plus
Expand Down
17 changes: 17 additions & 0 deletions test/xpath/test_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1090,6 +1090,23 @@ def test_numbers
assert_equal( 0, XPath.match( d, xp8 ).length )
end

def test_mod
d = Document.new("<a/>")
assert_equal([1.0, 1.0, -1.0, -1.0, -0.5],
[
XPath.first(d, "5 mod 2"),
XPath.first(d, "5 mod -2"),
XPath.first(d, "-5 mod 2"),
XPath.first(d, "-5 mod -2"),
XPath.first(d, "-0.5 mod 3"),
])
end

def test_mod_zero
d = Document.new("<a/>")
assert_predicate(XPath.first(d, "5 mod 0"), :nan?)
end

def test_tobis_preceding
doc_string = '<a>
<b/>
Expand Down