summaryrefslogtreecommitdiff
path: root/test/bigdecimal/test_bigdecimal.rb
diff options
context:
space:
mode:
authorKenta Murata <mrkn@mrkn.jp>2021-01-01 16:00:23 +0900
committerKenta Murata <mrkn@mrkn.jp>2021-01-02 00:54:09 +0900
commitc2c0147538f72e37a6c718456751bc5776bebd93 (patch)
treed807b329597322682058603de6e9f5e22ccc1208 /test/bigdecimal/test_bigdecimal.rb
parent448a67cd812d0be0a7f1cc871daa598c3b846143 (diff)
[ruby/bigdecimal] Fix test for Ruby 2.4
Ruby 2.4 does not have RbConfig::LIMITS. https://github.com/ruby/bigdecimal/commit/c8087523b0
Diffstat (limited to 'test/bigdecimal/test_bigdecimal.rb')
-rw-r--r--test/bigdecimal/test_bigdecimal.rb30
1 files changed, 20 insertions, 10 deletions
diff --git a/test/bigdecimal/test_bigdecimal.rb b/test/bigdecimal/test_bigdecimal.rb
index c2591de..5599234 100644
--- a/test/bigdecimal/test_bigdecimal.rb
+++ b/test/bigdecimal/test_bigdecimal.rb
@@ -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