Support for the XPath "!=" operator.
This commit is contained in:
parent
9e5f15787d
commit
e1d9e62b72
|
@ -742,6 +742,18 @@ module Oga
|
|||
return left == right
|
||||
end
|
||||
|
||||
##
|
||||
# Processes the `!=` operator.
|
||||
#
|
||||
# This operator does the exact opposite of the `=` operator. See {#on_eq}
|
||||
# for more information.
|
||||
#
|
||||
# @see [#on_eq]
|
||||
#
|
||||
def on_neq(ast_node, context)
|
||||
return !on_eq(ast_node, context)
|
||||
end
|
||||
|
||||
##
|
||||
# Delegates function calls to specific handlers.
|
||||
#
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Oga::XPath::Evaluator do
|
||||
context 'not-equal operator' do
|
||||
before do
|
||||
@document = parse('<root><a>10</a><b>10</b></root>')
|
||||
@evaluator = described_class.new(@document)
|
||||
end
|
||||
|
||||
example 'return true if two numbers are not equal' do
|
||||
@evaluator.evaluate('10 != 20').should == true
|
||||
end
|
||||
|
||||
example 'return false if two numbers are equal' do
|
||||
@evaluator.evaluate('10 != 10').should == false
|
||||
end
|
||||
|
||||
example 'return true if a number and a string are not equal' do
|
||||
@evaluator.evaluate('10 != "20"').should == true
|
||||
end
|
||||
|
||||
example 'return true if two strings are not equal' do
|
||||
@evaluator.evaluate('"10" != "20"').should == true
|
||||
end
|
||||
|
||||
example 'return true if a string and a number are not equal' do
|
||||
@evaluator.evaluate('"10" != 20').should == true
|
||||
end
|
||||
|
||||
example 'return false if two strings are equal' do
|
||||
@evaluator.evaluate('"a" != "a"').should == false
|
||||
end
|
||||
|
||||
example 'return true if two node sets are not equal' do
|
||||
@evaluator.evaluate('root != root/b').should == true
|
||||
end
|
||||
|
||||
example 'return false if two node sets are equal' do
|
||||
@evaluator.evaluate('root/a != root/b').should == false
|
||||
end
|
||||
|
||||
example 'return true if a node set and a number are not equal' do
|
||||
@evaluator.evaluate('root/a != 20').should == true
|
||||
end
|
||||
|
||||
example 'return true if a node set and a string are not equal' do
|
||||
@evaluator.evaluate('root/a != "20"').should == true
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue