mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Added tests for setting ivars on frozen objs
This commit is contained in:
parent
c49fde351f
commit
51835135a0
Notes:
git
2022-06-17 00:48:28 +09:00
1 changed files with 30 additions and 0 deletions
30
test/ruby/test_frozen.rb
Normal file
30
test/ruby/test_frozen.rb
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
# frozen_string_literal: false
|
||||||
|
require 'test/unit'
|
||||||
|
|
||||||
|
class TestFrozen < Test::Unit::TestCase
|
||||||
|
def test_setting_ivar_on_frozen_obj
|
||||||
|
obj = Object.new
|
||||||
|
obj.freeze
|
||||||
|
assert_raise(FrozenError) { obj.instance_variable_set(:@a, 1) }
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_setting_ivar_on_frozen_obj_with_ivars
|
||||||
|
obj = Object.new
|
||||||
|
obj.instance_variable_set(:@a, 1)
|
||||||
|
obj.freeze
|
||||||
|
assert_raise(FrozenError) { obj.instance_variable_set(:@b, 1) }
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_setting_ivar_on_frozen_string
|
||||||
|
str = "str"
|
||||||
|
str.freeze
|
||||||
|
assert_raise(FrozenError) { str.instance_variable_set(:@a, 1) }
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_setting_ivar_on_frozen_string_with_ivars
|
||||||
|
str = "str"
|
||||||
|
str.instance_variable_set(:@a, 1)
|
||||||
|
str.freeze
|
||||||
|
assert_raise(FrozenError) { str.instance_variable_set(:@b, 1) }
|
||||||
|
end
|
||||||
|
end
|
Loading…
Add table
Add a link
Reference in a new issue