summaryrefslogtreecommitdiff
path: root/spec/ruby
diff options
context:
space:
mode:
authorBenoit Daloze <eregontp@gmail.com>2023-01-07 13:18:04 +0100
committerBenoit Daloze <eregontp@gmail.com>2023-01-07 13:18:04 +0100
commit28cfc0c116b6c6e40bf3b391f026a51b3b208047 (patch)
tree36d8d0ddc71d6763206be31fbd5640ea1ccb29ea /spec/ruby
parent897cf122bf491ecf00d6374d944654bc85f8ed0f (diff)
Only RangeError on CRuby for shift width >= 2**67
* It seems a better exception class too than NoMemoryError.
Diffstat (limited to 'spec/ruby')
-rw-r--r--spec/ruby/core/integer/left_shift_spec.rb21
-rw-r--r--spec/ruby/core/integer/right_shift_spec.rb21
2 files changed, 14 insertions, 28 deletions
diff --git a/spec/ruby/core/integer/left_shift_spec.rb b/spec/ruby/core/integer/left_shift_spec.rb
index ef434f7a48..0781371d93 100644
--- a/spec/ruby/core/integer/left_shift_spec.rb
+++ b/spec/ruby/core/integer/left_shift_spec.rb
@@ -191,7 +191,7 @@ describe "Integer#<< (with n << m)" do
(0 << bignum_value).should == 0
end
- it "raises RangeError or NoMemoryError when m > 0 and n != 0" do
+ 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
@@ -199,21 +199,14 @@ describe "Integer#<< (with n << m)" do
coerce_long.stub!(:to_int).and_return(limit)
coerce_bignum = mock("bignum")
coerce_bignum.stub!(:to_int).and_return(bignum_value)
- exps = [limit, bignum_value, coerce_long, coerce_bignum]
-
- matcher = raise_error(Exception) do |exc|
- if RangeError === exc
- exc.message.should == 'shift width too big'
- else
- exc.should.is_a?(NoMemoryError)
- end
- end
+ exps = [limit, coerce_long]
+ exps << bignum_value << coerce_bignum if bignum_value >= limit
exps.each { |exp|
- -> { (1 << exp) }.should matcher
- -> { (-1 << exp) }.should matcher
- -> { (bignum_value << exp) }.should matcher
- -> { (-bignum_value << exp) }.should matcher
+ -> { (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
diff --git a/spec/ruby/core/integer/right_shift_spec.rb b/spec/ruby/core/integer/right_shift_spec.rb
index c022556a06..e91613d8d1 100644
--- a/spec/ruby/core/integer/right_shift_spec.rb
+++ b/spec/ruby/core/integer/right_shift_spec.rb
@@ -213,7 +213,7 @@ describe "Integer#>> (with n >> m)" do
(0 >> -bignum_value).should == 0
end
- it "raises RangeError or NoMemoryError when m < 0 and n != 0" do
+ 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
@@ -221,21 +221,14 @@ describe "Integer#>> (with n >> m)" do
coerce_long.stub!(:to_int).and_return(-limit)
coerce_bignum = mock("bignum")
coerce_bignum.stub!(:to_int).and_return(-bignum_value)
- exps = [-limit, -bignum_value, coerce_long, coerce_bignum]
-
- matcher = raise_error(Exception) do |exc|
- if RangeError === exc
- exc.message.should == 'shift width too big'
- else
- exc.should.is_a?(NoMemoryError)
- end
- end
+ exps = [-limit, coerce_long]
+ exps << -bignum_value << coerce_bignum if bignum_value >= limit
exps.each { |exp|
- -> { (1 >> exp) }.should matcher
- -> { (-1 >> exp) }.should matcher
- -> { (bignum_value >> exp) }.should matcher
- -> { (-bignum_value >> exp) }.should matcher
+ -> { (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