From 99be3182aec4365d7c6e3fe5bb2e9b4ff4ba96b0 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Fri, 22 Aug 2014 10:59:03 +0200 Subject: [PATCH] Support for evaluating XPath floats. --- lib/oga/xpath/evaluator.rb | 11 +++++++++++ spec/oga/xpath/evaluator/types/float_spec.rb | 19 +++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 spec/oga/xpath/evaluator/types/float_spec.rb diff --git a/lib/oga/xpath/evaluator.rb b/lib/oga/xpath/evaluator.rb index f763922..1d01f0d 100644 --- a/lib/oga/xpath/evaluator.rb +++ b/lib/oga/xpath/evaluator.rb @@ -768,6 +768,17 @@ module Oga return ast_node.children[0].to_f end + ## + # Processes an `(float)` node. + # + # @param [Oga::XPath::Node] ast_node + # @param [Oga::XML::NodeSet] context + # @return [Float] + # + def on_float(ast_node, context) + return ast_node.children[0] + end + ## # Processes a `(string)` node. # diff --git a/spec/oga/xpath/evaluator/types/float_spec.rb b/spec/oga/xpath/evaluator/types/float_spec.rb new file mode 100644 index 0000000..b236377 --- /dev/null +++ b/spec/oga/xpath/evaluator/types/float_spec.rb @@ -0,0 +1,19 @@ +require 'spec_helper' + +describe Oga::XPath::Evaluator do + context 'float types' do + before do + document = parse('') + evaluator = described_class.new(document) + @number = evaluator.evaluate('1.2') + end + + example 'return literal integers' do + @number.should == 1.2 + end + + example 'return integers as floats' do + @number.is_a?(Float).should == true + end + end +end