diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/visitors/test_to_ruby.rb | 39 | ||||
-rw-r--r-- | test/visitors/test_yast_builder.rb | 16 |
2 files changed, 55 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) diff --git a/test/visitors/test_yast_builder.rb b/test/visitors/test_yast_builder.rb index 91eef1c..2832da9 100644 --- a/test/visitors/test_yast_builder.rb +++ b/test/visitors/test_yast_builder.rb @@ -41,6 +41,22 @@ module Psych assert_round_trip :foo end + def test_int + assert_round_trip 1 + assert_round_trip(-1) + assert_round_trip '1' + assert_round_trip '-1' + end + + def test_float + assert_round_trip 1.2 + assert_round_trip '1.2' + + assert Psych.load(Psych.dump(0.0 / 0.0)).nan? + assert_equal 1, Psych.load(Psych.dump(1 / 0.0)).infinite? + assert_equal(-1, Psych.load(Psych.dump(-1 / 0.0)).infinite?) + end + # http://yaml.org/type/null.html def test_nil assert_round_trip nil |