1 # frozen_string_literal: true
2 require_relative 'helper'
10 # Test numerics from YAML spec:
11 # http://yaml.org/type/float.html
12 # http://yaml.org/type/int.html
13 class TestNumeric < TestCase
23 def test_load_float_with_dot
24 assert_equal 1.0, Psych.load('--- 1.')
27 def test_non_float_with_0
28 str = Psych.load('--- 090')
29 assert_equal '090', str
32 def test_big_decimal_tag
33 decimal = BigDecimal("12.34")
34 assert_match "!ruby/object:BigDecimal", Psych.dump(decimal)
35 end if defined?(BigDecimal)
37 def test_big_decimal_round_trip
38 decimal = BigDecimal("12.34")
41 end if defined?(BigDecimal)
43 def test_does_not_attempt_numeric
44 str = Psych.load('--- 4 roses')
45 assert_equal '4 roses', str
46 str = Psych.load('--- 1.1.1')
47 assert_equal '1.1.1', str
50 # This behavior is not to YML spec, but is kept for backwards compatibility
51 def test_string_with_commas
52 number = Psych.load('--- 12,34,56')
53 assert_equal 123456, number
56 def test_string_with_commas_with_strict_integer
57 str = Psych.load('--- 12,34,56', strict_integer: true)
58 assert_equal '12,34,56', str