Handle boolean values in the boolean() function.
This commit is contained in:
parent
8fb8fb17b6
commit
809ed9bfa6
|
@ -1075,12 +1075,15 @@ module Oga
|
|||
#
|
||||
def on_call_boolean(context, expression)
|
||||
retval = process(expression, context)
|
||||
bool = false
|
||||
|
||||
if retval.is_a?(Numeric)
|
||||
return !retval.nan? && !retval.zero?
|
||||
else
|
||||
return retval && !retval.empty?
|
||||
bool = !retval.nan? && !retval.zero?
|
||||
elsif retval
|
||||
bool = !retval.respond_to?(:empty?) || !retval.empty?
|
||||
end
|
||||
|
||||
return bool
|
||||
end
|
||||
|
||||
##
|
||||
|
|
|
@ -19,6 +19,14 @@ describe Oga::XPath::Evaluator do
|
|||
@evaluator.evaluate('boolean(10)').should == true
|
||||
end
|
||||
|
||||
example 'return true for a boolean true' do
|
||||
@evaluator.evaluate('boolean(true())').should == true
|
||||
end
|
||||
|
||||
example 'return false for a boolean false' do
|
||||
@evaluator.evaluate('boolean(false())').should == false
|
||||
end
|
||||
|
||||
example 'return true for a positive float' do
|
||||
@evaluator.evaluate('boolean(10.5)').should == true
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue