From cb550246136b90a63b4f75f5e7cfaccb9da08eda Mon Sep 17 00:00:00 2001 From: Yusuke Endoh Date: Sun, 28 Apr 2019 23:23:00 +0900 Subject: [PATCH] test/ruby/test_integer.rb: Add a sane test for Integer#[] --- test/ruby/test_integer.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/ruby/test_integer.rb b/test/ruby/test_integer.rb index 69347b6b11..ad088aa72f 100644 --- a/test/ruby/test_integer.rb +++ b/test/ruby/test_integer.rb @@ -10,7 +10,21 @@ class TestInteger < Test::Unit::TestCase self.class.bdsize(x) end + FIXNUM_MIN = RbConfig::LIMITS['FIXNUM_MIN'] + FIXNUM_MAX = RbConfig::LIMITS['FIXNUM_MAX'] + def test_aref + + [ + *-16..16, + *(FIXNUM_MIN-2)..(FIXNUM_MIN+2), + *(FIXNUM_MAX-2)..(FIXNUM_MAX+2), + ].each do |n| + (-64..64).each do |idx| + assert_equal((n >> idx) & 1, n[idx]) + end + end + # assert_equal(1, (1 << 0x40000000)[0x40000000], "[ruby-dev:31271]") # assert_equal(0, (-1 << 0x40000001)[0x40000000], "[ruby-dev:31271]") big_zero = 0x40000000.coerce(0)[0]