summaryrefslogtreecommitdiff
path: root/test/ruby/test_object.rb
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-04-08 03:05:15 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-04-08 03:05:15 +0000
commitae13ab24669e787a73a98a533d4bd7db8c4b49ab (patch)
tree97b8c5eb99f5237a02a60a0d044471ca64ec9803 /test/ruby/test_object.rb
parent6cb682a48005f43f3f1599d6c510523de237040d (diff)
* object.c (rb_obj_ivar_set): call to_str for string only once.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40178 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_object.rb')
-rw-r--r--test/ruby/test_object.rb19
1 files changed, 19 insertions, 0 deletions
diff --git a/test/ruby/test_object.rb b/test/ruby/test_object.rb
index b1df99d76e..1da7f250c2 100644
--- a/test/ruby/test_object.rb
+++ b/test/ruby/test_object.rb
@@ -176,6 +176,12 @@ class TestObject < Test::Unit::TestCase
assert_raise(NameError) { o.instance_variable_get(:foo) }
assert_raise(NameError) { o.instance_variable_get("bar") }
assert_raise(TypeError) { o.instance_variable_get(1) }
+
+ n = Object.new
+ def n.to_str; @count = defined?(@count) ? @count + 1 : 1; "@foo"; end
+ def n.count; @count; end
+ assert_equal(:foo, o.instance_variable_get(n))
+ assert_equal(1, n.count)
end
def test_instance_variable_set
@@ -185,6 +191,13 @@ class TestObject < Test::Unit::TestCase
assert_raise(NameError) { o.instance_variable_set(:foo, 1) }
assert_raise(NameError) { o.instance_variable_set("bar", 1) }
assert_raise(TypeError) { o.instance_variable_set(1, 1) }
+
+ n = Object.new
+ def n.to_str; @count = defined?(@count) ? @count + 1 : 1; "@foo"; end
+ def n.count; @count; end
+ o.instance_variable_set(n, :bar)
+ assert_equal(:bar, o.instance_eval { @foo })
+ assert_equal(1, n.count)
end
def test_instance_variable_defined
@@ -195,6 +208,12 @@ class TestObject < Test::Unit::TestCase
assert_raise(NameError) { o.instance_variable_defined?(:foo) }
assert_raise(NameError) { o.instance_variable_defined?("bar") }
assert_raise(TypeError) { o.instance_variable_defined?(1) }
+
+ n = Object.new
+ def n.to_str; @count = defined?(@count) ? @count + 1 : 1; "@foo"; end
+ def n.count; @count; end
+ assert_equal(true, o.instance_variable_defined?(n))
+ assert_equal(1, n.count)
end
def test_remove_instance_variable