1require 'psych/helper'
2require 'bigdecimal'
3
4module Psych
5  ###
6  # Test numerics from YAML spec:
7  # http://yaml.org/type/float.html
8  # http://yaml.org/type/int.html
9  class TestNumeric < TestCase
10    def setup
11      @old_debug = $DEBUG
12      $DEBUG = true
13    end
14
15    def teardown
16      $DEBUG = @old_debug
17    end
18
19    def test_load_float_with_dot
20      assert_equal 1.0, Psych.load('--- 1.')
21    end
22
23    def test_non_float_with_0
24      str = Psych.load('--- 090')
25      assert_equal '090', str
26    end
27
28    def test_big_decimal_tag
29      decimal = BigDecimal("12.34")
30      assert_match "!ruby/object:BigDecimal", Psych.dump(decimal)
31    end
32
33    def test_big_decimal_round_trip
34      decimal = BigDecimal("12.34")
35      assert_cycle decimal
36    end
37
38    def test_does_not_attempt_numeric
39      str = Psych.load('--- 4 roses')
40      assert_equal '4 roses', str
41      str = Psych.load('--- 1.1.1')
42      assert_equal '1.1.1', str
43    end
44  end
45end
46