diff options
author | shyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-12-12 00:46:34 +0000 |
---|---|---|
committer | shyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-12-12 00:46:34 +0000 |
commit | b57915eddc91ce0369ae8bcf82d8c4364f42ea05 (patch) | |
tree | c5296c8fd95c9ee041fe66455eb0744c3212b5c5 /test/ruby/test_string.rb | |
parent | 0b31ce0047513d1eb8f9902286215025a3742bf5 (diff) |
Add FrozenError as a subclass of RuntimeError
FrozenError will be used instead of RuntimeError for exceptions
raised when there is an attempt to modify a frozen object. The
reason for this change is to differentiate exceptions related
to frozen objects from generic exceptions such as those generated
by Kernel#raise without an exception class.
From: Jeremy Evans <code@jeremyevans.net>
Signed-off-by: Urabe Shyouhei <shyouhei@ruby-lang.org>
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61131 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_string.rb')
-rw-r--r-- | test/ruby/test_string.rb | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/test/ruby/test_string.rb b/test/ruby/test_string.rb index 7dd76f76f7..81e03aab30 100644 --- a/test/ruby/test_string.rb +++ b/test/ruby/test_string.rb @@ -62,12 +62,12 @@ class TestString < Test::Unit::TestCase def test_initialize str = S("").freeze assert_equal("", str.__send__(:initialize)) - assert_raise(RuntimeError){ str.__send__(:initialize, 'abc') } - assert_raise(RuntimeError){ str.__send__(:initialize, capacity: 1000) } - assert_raise(RuntimeError){ str.__send__(:initialize, 'abc', capacity: 1000) } - assert_raise(RuntimeError){ str.__send__(:initialize, encoding: 'euc-jp') } - assert_raise(RuntimeError){ str.__send__(:initialize, 'abc', encoding: 'euc-jp') } - assert_raise(RuntimeError){ str.__send__(:initialize, 'abc', capacity: 1000, encoding: 'euc-jp') } + assert_raise(FrozenError){ str.__send__(:initialize, 'abc') } + assert_raise(FrozenError){ str.__send__(:initialize, capacity: 1000) } + assert_raise(FrozenError){ str.__send__(:initialize, 'abc', capacity: 1000) } + assert_raise(FrozenError){ str.__send__(:initialize, encoding: 'euc-jp') } + assert_raise(FrozenError){ str.__send__(:initialize, 'abc', encoding: 'euc-jp') } + assert_raise(FrozenError){ str.__send__(:initialize, 'abc', capacity: 1000, encoding: 'euc-jp') } end def test_initialize_nonstring @@ -491,7 +491,7 @@ CODE assert_equal(S("a").hash, S("a\u0101").chomp!(S("\u0101")).hash, '[ruby-core:22414]') s = S("").freeze - assert_raise_with_message(RuntimeError, /frozen/) {s.chomp!} + assert_raise_with_message(FrozenError, /frozen/) {s.chomp!} s = S("ax") o = Struct.new(:s).new(s) @@ -499,7 +499,7 @@ CODE s.freeze "x" end - assert_raise_with_message(RuntimeError, /frozen/) {s.chomp!(o)} + assert_raise_with_message(FrozenError, /frozen/) {s.chomp!(o)} s = S("hello") assert_equal("hel", s.chomp!('lo')) @@ -617,7 +617,7 @@ CODE expected = S("\u0300".encode(Encoding::UTF_16LE)) assert_equal(expected, result, bug7090) assert_raise(TypeError) { 'foo' << :foo } - assert_raise(RuntimeError) { 'foo'.freeze.concat('bar') } + assert_raise(FrozenError) { 'foo'.freeze.concat('bar') } end def test_concat_literals @@ -1367,10 +1367,10 @@ CODE assert_equal(s2, s) fs = "".freeze - assert_raise(RuntimeError) { fs.replace("a") } - assert_raise(RuntimeError) { fs.replace(fs) } + assert_raise(FrozenError) { fs.replace("a") } + assert_raise(FrozenError) { fs.replace(fs) } assert_raise(ArgumentError) { fs.replace() } - assert_raise(RuntimeError) { fs.replace(42) } + assert_raise(FrozenError) { fs.replace(42) } end def test_reverse @@ -2272,7 +2272,7 @@ CODE end def test_frozen_check - assert_raise(RuntimeError) { + assert_raise(FrozenError) { s = "" s.sub!(/\A/) { s.freeze; "zzz" } } @@ -2710,7 +2710,7 @@ CODE assert_equal("bba", s) s = S("ax").freeze - assert_raise_with_message(RuntimeError, /frozen/) {s.delete_prefix!("a")} + assert_raise_with_message(FrozenError, /frozen/) {s.delete_prefix!("a")} s = S("ax") o = Struct.new(:s).new(s) @@ -2718,7 +2718,7 @@ CODE s.freeze "a" end - assert_raise_with_message(RuntimeError, /frozen/) {s.delete_prefix!(o)} + assert_raise_with_message(FrozenError, /frozen/) {s.delete_prefix!(o)} end def test_delete_suffix @@ -2778,7 +2778,7 @@ CODE assert_raise(TypeError) { 'hello'.delete_suffix!(/hel/) } s = S("hello").freeze - assert_raise_with_message(RuntimeError, /frozen/) {s.delete_suffix!('lo')} + assert_raise_with_message(FrozenError, /frozen/) {s.delete_suffix!('lo')} s = S("ax") o = Struct.new(:s).new(s) @@ -2786,7 +2786,7 @@ CODE s.freeze "x" end - assert_raise_with_message(RuntimeError, /frozen/) {s.delete_suffix!(o)} + assert_raise_with_message(FrozenError, /frozen/) {s.delete_suffix!(o)} s = S("hello") assert_equal("hel", s.delete_suffix!('lo')) |