Support for the XPath ceiling() function.
This commit is contained in:
parent
c8fb1ad202
commit
a2b8e3c954
|
@ -1200,6 +1200,22 @@ module Oga
|
||||||
return number.nan? ? number : number.floor.to_f
|
return number.nan? ? number : number.floor.to_f
|
||||||
end
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# Processes the `ceiling()` function call.
|
||||||
|
#
|
||||||
|
# This function returns the ceiling of a numeric value, the result is
|
||||||
|
# returned as a float.
|
||||||
|
#
|
||||||
|
# @param [Oga::XML::NodeSet] context
|
||||||
|
# @param [Oga::XPath::Node] expression
|
||||||
|
# @return [Float]
|
||||||
|
#
|
||||||
|
def on_call_ceiling(context, expression)
|
||||||
|
number = on_call_number(context, expression)
|
||||||
|
|
||||||
|
return number.nan? ? number : number.ceil.to_f
|
||||||
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
# Processes an `(int)` node.
|
# Processes an `(int)` node.
|
||||||
#
|
#
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe Oga::XPath::Evaluator do
|
||||||
|
context 'ceiling() function' do
|
||||||
|
before do
|
||||||
|
@document = parse('<root>10.123</root>')
|
||||||
|
@evaluator = described_class.new(@document)
|
||||||
|
end
|
||||||
|
|
||||||
|
example 'return the ceiling of a literal number' do
|
||||||
|
@evaluator.evaluate('ceiling(10.123)').should == 11.0
|
||||||
|
end
|
||||||
|
|
||||||
|
example 'return the ceiling of a literal string' do
|
||||||
|
@evaluator.evaluate('ceiling("10.123")').should == 11.0
|
||||||
|
end
|
||||||
|
|
||||||
|
example 'return the ceiling of a node set' do
|
||||||
|
@evaluator.evaluate('ceiling(root)').should == 11.0
|
||||||
|
end
|
||||||
|
|
||||||
|
example 'return NaN for empty node sets' do
|
||||||
|
@evaluator.evaluate('ceiling(foo)').should be_nan
|
||||||
|
end
|
||||||
|
|
||||||
|
example 'return NaN for an empty literal string' do
|
||||||
|
@evaluator.evaluate('ceiling("")').should be_nan
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue