[rubygems/rubygems] Use a constant empty tar header to avoid extra allocations
[ruby.git] / test / psych / test_numeric.rb
blob4c012e4562e80d43ee39fb88ef73f26d808870ac
1 # frozen_string_literal: true
2 require_relative 'helper'
3 begin
4   require 'bigdecimal'
5 rescue LoadError
6 end
8 module Psych
9   ###
10   # Test numerics from YAML spec:
11   # http://yaml.org/type/float.html
12   # http://yaml.org/type/int.html
13   class TestNumeric < TestCase
14     def setup
15       @old_debug = $DEBUG
16       $DEBUG = true
17     end
19     def teardown
20       $DEBUG = @old_debug
21     end
23     def test_load_float_with_dot
24       assert_equal 1.0, Psych.load('--- 1.')
25     end
27     def test_non_float_with_0
28       str = Psych.load('--- 090')
29       assert_equal '090', str
30     end
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")
39       $DEBUG = false
40       assert_cycle decimal
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
48     end
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
54     end
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
59     end
60   end
61 end