From 431a253000cf2444785db0e12f1ce57e3742e312 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Sat, 23 Aug 2014 20:22:58 +0200 Subject: [PATCH] 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. --- lib/oga/xpath/evaluator.rb | 2 +- spec/oga/xpath/evaluator/calls/string_spec.rb | 2 +- spec/oga/xpath/evaluator/types/int_spec.rb | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/oga/xpath/evaluator.rb b/lib/oga/xpath/evaluator.rb index dc59e97..6593121 100644 --- a/lib/oga/xpath/evaluator.rb +++ b/lib/oga/xpath/evaluator.rb @@ -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 ## diff --git a/spec/oga/xpath/evaluator/calls/string_spec.rb b/spec/oga/xpath/evaluator/calls/string_spec.rb index b45b543..c09e310 100644 --- a/spec/oga/xpath/evaluator/calls/string_spec.rb +++ b/spec/oga/xpath/evaluator/calls/string_spec.rb @@ -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 diff --git a/spec/oga/xpath/evaluator/types/int_spec.rb b/spec/oga/xpath/evaluator/types/int_spec.rb index 7321f2f..e2f01ad 100644 --- a/spec/oga/xpath/evaluator/types/int_spec.rb +++ b/spec/oga/xpath/evaluator/types/int_spec.rb @@ -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