2015-12-16 00:07:31 -05:00
|
|
|
# frozen_string_literal: false
|
2013-03-26 10:55:04 -04:00
|
|
|
require_relative 'helper'
|
2011-12-17 22:44:09 -05:00
|
|
|
require 'bigdecimal'
|
2011-10-03 17:21:31 -04:00
|
|
|
|
|
|
|
module Psych
|
|
|
|
###
|
|
|
|
# Test numerics from YAML spec:
|
|
|
|
# http://yaml.org/type/float.html
|
|
|
|
# http://yaml.org/type/int.html
|
|
|
|
class TestNumeric < TestCase
|
2012-11-16 22:11:22 -05:00
|
|
|
def setup
|
|
|
|
@old_debug = $DEBUG
|
|
|
|
$DEBUG = true
|
|
|
|
end
|
|
|
|
|
|
|
|
def teardown
|
|
|
|
$DEBUG = @old_debug
|
|
|
|
end
|
|
|
|
|
2013-01-09 14:26:45 -05:00
|
|
|
def test_load_float_with_dot
|
|
|
|
assert_equal 1.0, Psych.load('--- 1.')
|
|
|
|
end
|
|
|
|
|
2011-10-03 17:21:31 -04:00
|
|
|
def test_non_float_with_0
|
|
|
|
str = Psych.load('--- 090')
|
|
|
|
assert_equal '090', str
|
|
|
|
end
|
2011-12-17 22:44:09 -05:00
|
|
|
|
|
|
|
def test_big_decimal_tag
|
|
|
|
decimal = BigDecimal("12.34")
|
|
|
|
assert_match "!ruby/object:BigDecimal", Psych.dump(decimal)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_big_decimal_round_trip
|
|
|
|
decimal = BigDecimal("12.34")
|
|
|
|
assert_cycle decimal
|
|
|
|
end
|
2012-11-16 22:11:22 -05:00
|
|
|
|
|
|
|
def test_does_not_attempt_numeric
|
|
|
|
str = Psych.load('--- 4 roses')
|
|
|
|
assert_equal '4 roses', str
|
|
|
|
str = Psych.load('--- 1.1.1')
|
|
|
|
assert_equal '1.1.1', str
|
|
|
|
end
|
2011-10-03 17:21:31 -04:00
|
|
|
end
|
|
|
|
end
|