summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorshugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-09-29 02:21:27 +0000
committershugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-09-29 02:21:27 +0000
commit0954607864bcdd81ea5f3dd2ea52f638f2f32e47 (patch)
treebf798ae8e5bc1a3e2ebdb7ded0bf8555701b8534 /test
parent039e2a35c2e410cf1679cf10b492112cc67931a9 (diff)
* vm_insnhelper.c (rb_vm_using_modules): use using_modules before
klass to fix method lookup order, and use klass even if klass is not a module to make refinements in class_eval invoked on classes work. * eval.c (rb_using_module): accept a class as the second argument. * eval.c (rb_mod_using, f_using): raise a TypeError if the argument is not a module. * test/ruby/test_refinement.rb: add new tests for the above changes. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37053 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_refinement.rb56
1 files changed, 56 insertions, 0 deletions
diff --git a/test/ruby/test_refinement.rb b/test/ruby/test_refinement.rb
index 98645745e9..476c6442c7 100644
--- a/test/ruby/test_refinement.rb
+++ b/test/ruby/test_refinement.rb
@@ -361,6 +361,34 @@ class TestRefinement < Test::Unit::TestCase
assert_equal([:m1, :m2], m2.module_eval { obj.foo })
end
+ def test_refine_module_with_double_overriding
+ m1 = Module.new {
+ def foo
+ [:m1]
+ end
+ }
+ c = Class.new {
+ include m1
+ }
+ m2 = Module.new {
+ refine m1 do
+ def foo
+ super << :m2
+ end
+ end
+ }
+ m3 = Module.new {
+ using m2
+ refine m1 do
+ def foo
+ super << :m3
+ end
+ end
+ }
+ obj = c.new
+ assert_equal([:m1, :m2, :m3], m3.module_eval { obj.foo })
+ end
+
def test_refine_module_and_call_superclass_method
m1 = Module.new
c1 = Class.new {
@@ -399,4 +427,32 @@ class TestRefinement < Test::Unit::TestCase
}
end
end
+
+ def test_refine_in_class_and_class_eval
+ c = Class.new {
+ refine Fixnum do
+ def foo
+ "c"
+ end
+ end
+ }
+ assert_equal("c", c.class_eval { 123.foo })
+ end
+
+ def test_kernel_using_class
+ c = Class.new
+ assert_raise(TypeError) do
+ using c
+ end
+ end
+
+ def test_module_using_class
+ c = Class.new
+ m = Module.new
+ assert_raise(TypeError) do
+ m.module_eval do
+ using c
+ end
+ end
+ end
end