summaryrefslogtreecommitdiff
path: root/test/ruby
diff options
context:
space:
mode:
Diffstat (limited to 'test/ruby')
-rw-r--r--test/ruby/test_method.rb15
-rw-r--r--test/ruby/test_module.rb51
2 files changed, 66 insertions, 0 deletions
diff --git a/test/ruby/test_method.rb b/test/ruby/test_method.rb
index 6d0f6acf35..1514c26f5c 100644
--- a/test/ruby/test_method.rb
+++ b/test/ruby/test_method.rb
@@ -180,6 +180,15 @@ class TestMethod < Test::Unit::TestCase
assert_equal(Array.instance_method(:map).hash, Array.instance_method(:collect).hash)
end
+ def test_owner
+ c = Class.new do
+ def foo; end
+ end
+ assert_equal(c, c.instance_method(:foo).owner)
+ c2 = Class.new(c)
+ assert_equal(c, c2.instance_method(:foo).owner)
+ end
+
def test_receiver_name_owner
o = Object.new
def o.foo; end
@@ -534,17 +543,23 @@ class TestMethod < Test::Unit::TestCase
def test_alias_owner
bug7613 = '[ruby-core:51105]'
+ bug7993 = '[Bug #7993]'
c = Class.new {
def foo
end
+ prepend Module.new
+ attr_reader :zot
}
x = c.new
class << x
alias bar foo
end
+ assert_equal(c, c.instance_method(:foo).owner)
assert_equal(c, x.method(:foo).owner)
assert_equal(x.singleton_class, x.method(:bar).owner)
assert(x.method(:foo) != x.method(:bar), bug7613)
+ assert_equal(c, x.method(:zot).owner, bug7993)
+ assert_equal(c, c.instance_method(:zot).owner, bug7993)
end
def test_gced_bmethod
diff --git a/test/ruby/test_module.rb b/test/ruby/test_module.rb
index 915a1b9feb..aa2d82841f 100644
--- a/test/ruby/test_module.rb
+++ b/test/ruby/test_module.rb
@@ -1555,6 +1555,57 @@ class TestModule < Test::Unit::TestCase
assert_include(im, mixin, bug8025)
end
+ def test_prepend_super_in_alias
+ bug7842 = '[Bug #7842]'
+
+ p = labeled_module("P") do
+ def m; "P"+super; end
+ end
+ a = labeled_class("A") do
+ def m; "A"; end
+ end
+ b = labeled_class("B", a) do
+ def m; "B"+super; end
+ alias m2 m
+ prepend p
+ alias m3 m
+ end
+ assert_equal("BA", b.new.m2, bug7842)
+ assert_equal("PBA", b.new.m3, bug7842)
+ end
+
+ def test_include_super_in_alias
+ bug9236 = '[Bug #9236]'
+
+ fun = labeled_module("Fun") do
+ def hello
+ orig_hello
+ end
+ end
+
+ m1 = labeled_module("M1") do
+ def hello
+ 'hello!'
+ end
+ end
+
+ m2 = labeled_module("M2") do
+ def hello
+ super
+ end
+ end
+
+ foo = labeled_class("Foo") do
+ include m1
+ include m2
+
+ alias orig_hello hello
+ include fun
+ end
+
+ assert_equal('hello!', foo.new.hello, bug9236)
+ end
+
def test_class_variables
m = Module.new
m.class_variable_set(:@@foo, 1)