Support for evaluating XPath floats.
This commit is contained in:
parent
6ac3408a71
commit
99be3182ae
|
@ -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.
|
||||
#
|
||||
|
|
|
@ -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
|
Loading…
Reference in New Issue