From d2f991538dc2c9ec771249605862d0dc5bbf3a88 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Wed, 27 Aug 2014 09:37:28 +0200 Subject: [PATCH] Support for the XPath true()/false() functions. --- lib/oga/xpath/evaluator.rb | 24 ++++++++++++++++++++ spec/oga/xpath/evaluator/calls/false_spec.rb | 13 +++++++++++ spec/oga/xpath/evaluator/calls/true_spec.rb | 13 +++++++++++ 3 files changed, 50 insertions(+) create mode 100644 spec/oga/xpath/evaluator/calls/false_spec.rb create mode 100644 spec/oga/xpath/evaluator/calls/true_spec.rb diff --git a/lib/oga/xpath/evaluator.rb b/lib/oga/xpath/evaluator.rb index 8fa6a84..f999a05 100644 --- a/lib/oga/xpath/evaluator.rb +++ b/lib/oga/xpath/evaluator.rb @@ -1074,6 +1074,30 @@ module Oga return !on_call_boolean(context, expression) end + ## + # Processes the `true()` function call. + # + # This function simply returns the boolean `true`. + # + # @param [Oga::XPath::NodeSet] context + # @return [TrueClass] + # + def on_call_true(context) + return true + end + + ## + # Processes the `false()` function call. + # + # This function simply returns the boolean `false`. + # + # @param [Oga::XPath::NodeSet] context + # @return [FalseClass] + # + def on_call_false(context) + return false + end + ## # Processes an `(int)` node. # diff --git a/spec/oga/xpath/evaluator/calls/false_spec.rb b/spec/oga/xpath/evaluator/calls/false_spec.rb new file mode 100644 index 0000000..4403d0d --- /dev/null +++ b/spec/oga/xpath/evaluator/calls/false_spec.rb @@ -0,0 +1,13 @@ +require 'spec_helper' + +describe Oga::XPath::Evaluator do + context 'false() function' do + before do + @evaluator = described_class.new(parse('')) + end + + example 'return false' do + @evaluator.evaluate('false()').should == false + end + end +end diff --git a/spec/oga/xpath/evaluator/calls/true_spec.rb b/spec/oga/xpath/evaluator/calls/true_spec.rb new file mode 100644 index 0000000..5d90fd4 --- /dev/null +++ b/spec/oga/xpath/evaluator/calls/true_spec.rb @@ -0,0 +1,13 @@ +require 'spec_helper' + +describe Oga::XPath::Evaluator do + context 'true() function' do + before do + @evaluator = described_class.new(parse('')) + end + + example 'return true' do + @evaluator.evaluate('true()').should == true + end + end +end