зеркало из https://github.com/github/ruby.git
[ruby/bigdecimal] Fix test for Ruby 2.4
Ruby 2.4 does not have RbConfig::LIMITS. https://github.com/ruby/bigdecimal/commit/c8087523b0
This commit is contained in:
Родитель
448a67cd81
Коммит
c2c0147538
|
@ -35,6 +35,7 @@ Gem::Specification.new do |s|
|
|||
|
||||
s.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
|
||||
|
||||
s.add_development_dependency "fiddle"
|
||||
s.add_development_dependency "rake", ">= 12.3.3"
|
||||
s.add_development_dependency "rake-compiler", ">= 0.9"
|
||||
s.add_development_dependency "minitest", "< 5.0.0"
|
||||
|
|
|
@ -6,6 +6,21 @@ require 'rbconfig/sizeof'
|
|||
class TestBigDecimal < Test::Unit::TestCase
|
||||
include TestBigDecimalBase
|
||||
|
||||
if defined? RbConfig::LIMITS
|
||||
LIMITS = RbConfig::LIMITS
|
||||
else
|
||||
require 'fiddle'
|
||||
LONG_MAX = (1 << (Fiddle::SIZEOF_LONG*8 - 1)) - 1
|
||||
LONG_MIN = [LONG_MAX + 1].pack("L!").unpack("l!")[0]
|
||||
LIMITS = {
|
||||
"FIXNUM_MIN" => LONG_MIN / 2,
|
||||
"FIXNUM_MAX" => LONG_MAX / 2,
|
||||
"INT64_MIN" => -9223372036854775808,
|
||||
"INT64_MAX" => 9223372036854775807,
|
||||
"UINT64_MAX" => 18446744073709551615,
|
||||
}.freeze
|
||||
end
|
||||
|
||||
ROUNDING_MODE_MAP = [
|
||||
[ BigDecimal::ROUND_UP, :up],
|
||||
[ BigDecimal::ROUND_DOWN, :down],
|
||||
|
@ -111,20 +126,15 @@ class TestBigDecimal < Test::Unit::TestCase
|
|||
assert_equal(BigDecimal((2**100).to_s), BigDecimal(2**100))
|
||||
assert_equal(BigDecimal((-2**100).to_s), BigDecimal(-2**100))
|
||||
|
||||
assert_equal(BigDecimal(RbConfig::LIMITS["FIXNUM_MIN"].to_s),
|
||||
BigDecimal(RbConfig::LIMITS["FIXNUM_MIN"]))
|
||||
assert_equal(BigDecimal(LIMITS["FIXNUM_MIN"].to_s), BigDecimal(LIMITS["FIXNUM_MIN"]))
|
||||
|
||||
assert_equal(BigDecimal(RbConfig::LIMITS["FIXNUM_MAX"].to_s),
|
||||
BigDecimal(RbConfig::LIMITS["FIXNUM_MAX"]))
|
||||
assert_equal(BigDecimal(LIMITS["FIXNUM_MAX"].to_s), BigDecimal(LIMITS["FIXNUM_MAX"]))
|
||||
|
||||
assert_equal(BigDecimal(RbConfig::LIMITS["INT64_MIN"].to_s),
|
||||
BigDecimal(RbConfig::LIMITS["INT64_MIN"]))
|
||||
assert_equal(BigDecimal(LIMITS["INT64_MIN"].to_s), BigDecimal(LIMITS["INT64_MIN"]))
|
||||
|
||||
assert_equal(BigDecimal(RbConfig::LIMITS["INT64_MAX"].to_s),
|
||||
BigDecimal(RbConfig::LIMITS["INT64_MAX"]))
|
||||
assert_equal(BigDecimal(LIMITS["INT64_MAX"].to_s), BigDecimal(LIMITS["INT64_MAX"]))
|
||||
|
||||
assert_equal(BigDecimal(RbConfig::LIMITS["UINT64_MAX"].to_s),
|
||||
BigDecimal(RbConfig::LIMITS["UINT64_MAX"]))
|
||||
assert_equal(BigDecimal(LIMITS["UINT64_MAX"].to_s), BigDecimal(LIMITS["UINT64_MAX"]))
|
||||
end
|
||||
|
||||
def test_BigDecimal_with_rational
|
||||
|
|
Загрузка…
Ссылка в новой задаче