diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2009-09-30 13:07:06 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2009-09-30 13:07:06 -0700 |
commit | b4ea13ae1e13e03c4f9293d091d1535e52a6c17e (patch) | |
tree | 0c26d31bf056bfcce7ba081fdca3a43fdb21db52 /test/visitors/test_to_ruby.rb | |
parent | 1ecabe15cca7df942f9b3a8684145c5b8e3f0dda (diff) | |
download | psych-b4ea13ae1e13e03c4f9293d091d1535e52a6c17e.zip |
float numeric edge cases
Diffstat (limited to 'test/visitors/test_to_ruby.rb')
-rw-r--r-- | test/visitors/test_to_ruby.rb | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/test/visitors/test_to_ruby.rb b/test/visitors/test_to_ruby.rb index cc499b7..65d1297 100644 --- a/test/visitors/test_to_ruby.rb +++ b/test/visitors/test_to_ruby.rb @@ -8,6 +8,45 @@ module Psych @visitor = ToRuby.new end + def test_integer + i = Nodes::Scalar.new('1', nil, 'tag:yaml.org,2002:int') + assert_equal 1, i.to_ruby + + assert_equal 1, Nodes::Scalar.new('1').to_ruby + + i = Nodes::Scalar.new('-1', nil, 'tag:yaml.org,2002:int') + assert_equal(-1, i.to_ruby) + + assert_equal(-1, Nodes::Scalar.new('-1').to_ruby) + assert_equal 1, Nodes::Scalar.new('+1').to_ruby + end + + def test_float + i = Nodes::Scalar.new('1.2', nil, 'tag:yaml.org,2002:float') + assert_equal 1.2, i.to_ruby + + i = Nodes::Scalar.new('1.2') + assert_equal 1.2, i.to_ruby + + assert_equal 1, Nodes::Scalar.new('.Inf').to_ruby.infinite? + assert_equal 1, Nodes::Scalar.new('.Inf', nil, 'tag:yaml.org,2002:float').to_ruby.infinite? + + assert_equal(-1, Nodes::Scalar.new('-.Inf').to_ruby.infinite?) + assert_equal(-1, Nodes::Scalar.new('-.Inf', nil, 'tag:yaml.org,2002:float').to_ruby.infinite?) + + assert Nodes::Scalar.new('.NaN').to_ruby.nan? + assert Nodes::Scalar.new('.NaN', nil, 'tag:yaml.org,2002:float').to_ruby.nan? + end + + def test_exp_float + exp = 1.2e+30 + + i = Nodes::Scalar.new(exp.to_s, nil, 'tag:yaml.org,2002:float') + assert_equal exp, i.to_ruby + + assert_equal exp, Nodes::Scalar.new(exp.to_s).to_ruby + end + def test_scalar scalar = Nodes::Scalar.new('foo') assert_equal 'foo', @visitor.accept(scalar) |