diff options
Diffstat (limited to 'spec/ruby/core/integer/right_shift_spec.rb')
-rw-r--r-- | spec/ruby/core/integer/right_shift_spec.rb | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/spec/ruby/core/integer/right_shift_spec.rb b/spec/ruby/core/integer/right_shift_spec.rb index 81405667b2..e91613d8d1 100644 --- a/spec/ruby/core/integer/right_shift_spec.rb +++ b/spec/ruby/core/integer/right_shift_spec.rb @@ -213,21 +213,23 @@ describe "Integer#>> (with n >> m)" do (0 >> -bignum_value).should == 0 end - ruby_bug "#18518", ""..."3.3" do - it "raises NoMemoryError when m < 0 and n != 0" do - coerce_long = mock("long") - coerce_long.stub!(:to_int).and_return(-(2**40)) - coerce_bignum = mock("bignum") - coerce_bignum.stub!(:to_int).and_return(-bignum_value) - exps = [-(2**40), -bignum_value, coerce_long, coerce_bignum] - - exps.each { |exp| - -> { (1 >> exp) }.should raise_error(NoMemoryError) - -> { (-1 >> exp) }.should raise_error(NoMemoryError) - -> { (bignum_value >> exp) }.should raise_error(NoMemoryError) - -> { (-bignum_value >> exp) }.should raise_error(NoMemoryError) - } - end + it "raises RangeError when m < 0 and n != 0" do + # https://bugs.ruby-lang.org/issues/18518#note-9 + limit = RUBY_ENGINE == 'ruby' ? 2**67 : 2**32 + + coerce_long = mock("long") + coerce_long.stub!(:to_int).and_return(-limit) + coerce_bignum = mock("bignum") + coerce_bignum.stub!(:to_int).and_return(-bignum_value) + exps = [-limit, coerce_long] + exps << -bignum_value << coerce_bignum if bignum_value >= limit + + exps.each { |exp| + -> { (1 >> exp) }.should raise_error(RangeError, 'shift width too big') + -> { (-1 >> exp) }.should raise_error(RangeError, 'shift width too big') + -> { (bignum_value >> exp) }.should raise_error(RangeError, 'shift width too big') + -> { (-bignum_value >> exp) }.should raise_error(RangeError, 'shift width too big') + } end end end |