Return XPath integers as actual integers.

This is to ensure that calls such as string(10) return "10" and not "10.0". It
also saves integer -> float conversions when they're not needed.
This commit is contained in:
Yorick Peterse 2014-08-23 20:22:58 +02:00
parent b316fd3e1c
commit 431a253000
3 changed files with 4 additions and 4 deletions

View File

@ -794,7 +794,7 @@ module Oga
# @return [Float] # @return [Float]
# #
def on_int(ast_node, context) def on_int(ast_node, context)
return ast_node.children[0].to_f return ast_node.children[0]
end end
## ##

View File

@ -37,7 +37,7 @@ describe Oga::XPath::Evaluator do
end end
example 'convert an integer to a string' do example 'convert an integer to a string' do
@evaluator.evaluate('string(10)').should == '10.0' @evaluator.evaluate('string(10)').should == '10'
end end
example 'convert a float to a string' do example 'convert a float to a string' do

View File

@ -12,8 +12,8 @@ describe Oga::XPath::Evaluator do
@number.should == 1 @number.should == 1
end end
example 'return integers as floats' do example 'return integers as Fixnums' do
@number.is_a?(Float).should == true @number.is_a?(Fixnum).should == true
end end
end end
end end