Support for the XPath "<=" operator.
This commit is contained in:
parent
6eacf74da4
commit
099227901a
|
@ -786,6 +786,23 @@ module Oga
|
||||||
return on_call_number(context, left) > on_call_number(context, right)
|
return on_call_number(context, left) > on_call_number(context, right)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# Processes the `<=` operator.
|
||||||
|
#
|
||||||
|
# This operator converts the left and right expression to a number and
|
||||||
|
# returns `true` if the first number is lower-than or equal to the second
|
||||||
|
# number.
|
||||||
|
#
|
||||||
|
# @param [Oga::XML::Node] ast_node
|
||||||
|
# @param [Oga::XML::NodeSet] context
|
||||||
|
# @return [TrueClass|FalseClass]
|
||||||
|
#
|
||||||
|
def on_lte(ast_node, context)
|
||||||
|
left, right = *ast_node
|
||||||
|
|
||||||
|
return on_call_number(context, left) <= on_call_number(context, right)
|
||||||
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
# Delegates function calls to specific handlers.
|
# Delegates function calls to specific handlers.
|
||||||
#
|
#
|
||||||
|
|
|
@ -0,0 +1,66 @@
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe Oga::XPath::Evaluator do
|
||||||
|
context 'lower-than-or-equal operator' do
|
||||||
|
before do
|
||||||
|
@document = parse('<root><a>10</a><b>20</b></root>')
|
||||||
|
@evaluator = described_class.new(@document)
|
||||||
|
end
|
||||||
|
|
||||||
|
example 'return true if a number is lower than another number' do
|
||||||
|
@evaluator.evaluate('10 <= 20').should == true
|
||||||
|
end
|
||||||
|
|
||||||
|
example 'return true if a number is equal to another number' do
|
||||||
|
@evaluator.evaluate('10 <= 10').should == true
|
||||||
|
end
|
||||||
|
|
||||||
|
example 'return false if a number is not lower than/equal to another number' do
|
||||||
|
@evaluator.evaluate('20 <= 10').should == false
|
||||||
|
end
|
||||||
|
|
||||||
|
example 'return true if a number is lower than a string' do
|
||||||
|
@evaluator.evaluate('10 <= "20"').should == true
|
||||||
|
end
|
||||||
|
|
||||||
|
example 'return true if a number is equal to a string' do
|
||||||
|
@evaluator.evaluate('10 <= "10"').should == true
|
||||||
|
end
|
||||||
|
|
||||||
|
example 'return true if a string is lower than a number' do
|
||||||
|
@evaluator.evaluate('"10" <= 20').should == true
|
||||||
|
end
|
||||||
|
|
||||||
|
example 'return true if a string is equal to a number' do
|
||||||
|
@evaluator.evaluate('"10" <= 10').should == true
|
||||||
|
end
|
||||||
|
|
||||||
|
example 'return true if a string is lower than another string' do
|
||||||
|
@evaluator.evaluate('"10" <= "20"').should == true
|
||||||
|
end
|
||||||
|
|
||||||
|
example 'return true if a number is lower than a node set' do
|
||||||
|
@evaluator.evaluate('10 <= root/b').should == true
|
||||||
|
end
|
||||||
|
|
||||||
|
example 'return true if a number is equal to a node set' do
|
||||||
|
@evaluator.evaluate('10 <= root/a').should == true
|
||||||
|
end
|
||||||
|
|
||||||
|
example 'return true if a string is lower than a node set' do
|
||||||
|
@evaluator.evaluate('"10" <= root/b').should == true
|
||||||
|
end
|
||||||
|
|
||||||
|
example 'return true if a string is equal to a node set' do
|
||||||
|
@evaluator.evaluate('"10" <= root/a').should == true
|
||||||
|
end
|
||||||
|
|
||||||
|
example 'return true if a node set is lower than another node set' do
|
||||||
|
@evaluator.evaluate('root/a <= root/b').should == true
|
||||||
|
end
|
||||||
|
|
||||||
|
example 'return true if a node set is equal to another node set' do
|
||||||
|
@evaluator.evaluate('root/b <= root/b').should == true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue