diff options
Diffstat (limited to 'test/ruby/test_super.rb')
| -rw-r--r-- | test/ruby/test_super.rb | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/test/ruby/test_super.rb b/test/ruby/test_super.rb index 6a575b88c5..25bad2242a 100644 --- a/test/ruby/test_super.rb +++ b/test/ruby/test_super.rb @@ -8,6 +8,7 @@ class TestSuper < Test::Unit::TestCase def array(*a) a end def optional(a = 0) a end def keyword(**a) a end + def forward(*a) a end end class Single1 < Base def single(*) super end @@ -63,6 +64,16 @@ class TestSuper < Test::Unit::TestCase [x, y] end end + class Forward < Base + def forward(...) + w = super() + x = super + y = super(...) + a = 1 + z = super(a, ...) + [w, x, y, z] + end + end def test_single1 assert_equal(1, Single1.new.single(1)) @@ -133,6 +144,11 @@ class TestSuper < Test::Unit::TestCase def test_keyword2 assert_equal([{foo: "changed1"}, {foo: "changed2"}], Keyword2.new.keyword) end + def test_forwardable(...) + assert_equal([[],[],[],[1]], Forward.new.forward()) + assert_equal([[],[1,2],[1,2],[1,1,2]], Forward.new.forward(1,2)) + assert_equal([[],[:test],[:test],[1,:test]], Forward.new.forward(:test, ...)) + end class A def tt(aa) @@ -558,6 +574,18 @@ class TestSuper < Test::Unit::TestCase end end + def test_zsuper_kw_splat_not_mutable + extend(Module.new{def a(**k) k[:a] = 1 end}) + extend(Module.new do + def a(**k) + before = k.dup + super + [before, k] + end + end) + assert_equal(*a) + end + def test_from_eval bug10263 = '[ruby-core:65122] [Bug #10263a]' a = Class.new do @@ -605,6 +633,40 @@ class TestSuper < Test::Unit::TestCase } end + def test_super_with_included_prepended_module_method_caching_bug_20716 + a = Module.new do + def test(*args) + super + end + end + + b = Module.new do + def test(a) + a + end + end + + c = Class.new + + b.prepend(a) + c.include(b) + + assert_equal(1, c.new.test(1)) + + b.class_eval do + begin + verbose_bak, $VERBOSE = $VERBOSE, nil + def test + :test + end + ensure + $VERBOSE = verbose_bak + end + end + + assert_equal(:test, c.new.test) + end + class TestFor_super_with_modified_rest_parameter_base def foo *args args @@ -697,4 +759,19 @@ class TestSuper < Test::Unit::TestCase inherited = inherited_class.new assert_equal 2, inherited.test # it may read index=1 while it should be index=2 end + + def test_super_in_basic_object + assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}") + begin; + class ::BasicObject + def no_super + super() + rescue ::NameError + :ok + end + end + + assert_equal :ok, "[Bug #21694]".no_super + end; + end end |
