From 564f8859a0921176e24583c55da035bde817e54c Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Tue, 26 Aug 2014 20:22:18 +0200 Subject: [PATCH] Better XPath evaluation tests for numbers. --- spec/oga/xpath/evaluator/types/float_spec.rb | 17 ++++++++++------- spec/oga/xpath/evaluator/types/int_spec.rb | 17 ++++++++++------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/spec/oga/xpath/evaluator/types/float_spec.rb b/spec/oga/xpath/evaluator/types/float_spec.rb index b236377..edd4077 100644 --- a/spec/oga/xpath/evaluator/types/float_spec.rb +++ b/spec/oga/xpath/evaluator/types/float_spec.rb @@ -3,17 +3,20 @@ require 'spec_helper' describe Oga::XPath::Evaluator do context 'float types' do before do - document = parse('') - evaluator = described_class.new(document) - @number = evaluator.evaluate('1.2') + document = parse('') + @evaluator = described_class.new(document) end - example 'return literal integers' do - @number.should == 1.2 + example 'return a float' do + @evaluator.evaluate('1.2').should == 1.2 end - example 'return integers as floats' do - @number.is_a?(Float).should == true + example 'return a negative float' do + @evaluator.evaluate('-1.2').should == -1.2 + end + + example 'return floats as a Float' do + @evaluator.evaluate('1.2').is_a?(Float).should == true end end end diff --git a/spec/oga/xpath/evaluator/types/int_spec.rb b/spec/oga/xpath/evaluator/types/int_spec.rb index 7321f2f..35364c3 100644 --- a/spec/oga/xpath/evaluator/types/int_spec.rb +++ b/spec/oga/xpath/evaluator/types/int_spec.rb @@ -3,17 +3,20 @@ require 'spec_helper' describe Oga::XPath::Evaluator do context 'integer types' do before do - document = parse('') - evaluator = described_class.new(document) - @number = evaluator.evaluate('1') + document = parse('') + @evaluator = described_class.new(document) end - example 'return literal integers' do - @number.should == 1 + example 'return an integer' do + @evaluator.evaluate('1').should == 1 end - example 'return integers as floats' do - @number.is_a?(Float).should == true + example 'return a negative integer' do + @evaluator.evaluate('-2').should == -2 + end + + example 'return integers as a Float' do + @evaluator.evaluate('1').is_a?(Float).should == true end end end