Support for the XPath not() function.
This commit is contained in:
parent
80d235bf06
commit
4ef79bad90
|
@ -1045,6 +1045,10 @@ module Oga
|
|||
#
|
||||
# The boolean `false` is returned for all other cases.
|
||||
#
|
||||
# @param [Oga::XML::NodeSet] context
|
||||
# @param [Oga::XPath::Node] expression
|
||||
# @return [TrueClass|FalseClass]
|
||||
#
|
||||
def on_call_boolean(context, expression)
|
||||
retval = process(expression, context)
|
||||
|
||||
|
@ -1055,6 +1059,21 @@ module Oga
|
|||
end
|
||||
end
|
||||
|
||||
##
|
||||
# Processes the `not()` function call.
|
||||
#
|
||||
# This function converts the 1st argument to a boolean and returns the
|
||||
# opposite boolean value. For example, if the first argument results in
|
||||
# `true` then this function returns `false` instead.
|
||||
#
|
||||
# @param [Oga::XML::NodeSet] context
|
||||
# @param [Oga::XPath::Node] expression
|
||||
# @return [TrueClass|FalseClass]
|
||||
#
|
||||
def on_call_not(context, expression)
|
||||
return !on_call_boolean(context, expression)
|
||||
end
|
||||
|
||||
##
|
||||
# Processes an `(int)` node.
|
||||
#
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Oga::XPath::Evaluator do
|
||||
context 'not() function' do
|
||||
before do
|
||||
@document = parse('<root>foo</root>')
|
||||
@evaluator = described_class.new(@document)
|
||||
end
|
||||
|
||||
example 'return false when the argument is a non-zero integer' do
|
||||
@evaluator.evaluate('not(10)').should == false
|
||||
end
|
||||
|
||||
example 'return true when the argument is a zero integer' do
|
||||
@evaluator.evaluate('not(0)').should == true
|
||||
end
|
||||
|
||||
example 'return false when the argument is a non-empty node set' do
|
||||
@evaluator.evaluate('not(root)').should == false
|
||||
end
|
||||
|
||||
example 'return itrue when the argument is an empty node set' do
|
||||
@evaluator.evaluate('not(foo)').should == true
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue