Support for evaluating XPath floats.

This commit is contained in:
Yorick Peterse 2014-08-22 10:59:03 +02:00
parent 6ac3408a71
commit 99be3182ae
2 changed files with 30 additions and 0 deletions

View File

@ -768,6 +768,17 @@ module Oga
return ast_node.children[0].to_f return ast_node.children[0].to_f
end 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. # Processes a `(string)` node.
# #

View File

@ -0,0 +1,19 @@
require 'spec_helper'
describe Oga::XPath::Evaluator do
context 'float types' do
before do
document = parse('<a></a>')
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