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:
parent
b316fd3e1c
commit
431a253000
|
@ -794,7 +794,7 @@ module Oga
|
|||
# @return [Float]
|
||||
#
|
||||
def on_int(ast_node, context)
|
||||
return ast_node.children[0].to_f
|
||||
return ast_node.children[0]
|
||||
end
|
||||
|
||||
##
|
||||
|
|
|
@ -37,7 +37,7 @@ describe Oga::XPath::Evaluator do
|
|||
end
|
||||
|
||||
example 'convert an integer to a string' do
|
||||
@evaluator.evaluate('string(10)').should == '10.0'
|
||||
@evaluator.evaluate('string(10)').should == '10'
|
||||
end
|
||||
|
||||
example 'convert a float to a string' do
|
||||
|
|
|
@ -12,8 +12,8 @@ describe Oga::XPath::Evaluator do
|
|||
@number.should == 1
|
||||
end
|
||||
|
||||
example 'return integers as floats' do
|
||||
@number.is_a?(Float).should == true
|
||||
example 'return integers as Fixnums' do
|
||||
@number.is_a?(Fixnum).should == true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue