Skip to content

Commit

Permalink
[ruby/bigdecimal] Fix test for Ruby 2.4
Browse files Browse the repository at this point in the history
Ruby 2.4 does not have RbConfig::LIMITS.

ruby/bigdecimal@c8087523b0
  • Loading branch information
mrkn committed Jan 1, 2021
1 parent 448a67c commit c2c0147
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
1 change: 1 addition & 0 deletions ext/bigdecimal/bigdecimal.gemspec
Expand Up @@ -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"
Expand Down
30 changes: 20 additions & 10 deletions test/bigdecimal/test_bigdecimal.rb
Expand Up @@ -6,6 +6,21 @@
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],
Expand Down Expand Up @@ -111,20 +126,15 @@ def test_BigDecimal_with_integer
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
Expand Down

0 comments on commit c2c0147

Please sign in to comment.