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