ruby-changes:64136
From: Koichi <ko1@a...>
Date: Mon, 14 Dec 2020 11:58:12 +0900 (JST)
Subject: [ruby-changes:64136] 0362b4c689 (master): add tests for method cache.
https://git.ruby-lang.org/ruby.git/commit/?id=0362b4c689 From 0362b4c689e319e233691ee052cd703bf8d2baa1 Mon Sep 17 00:00:00 2001 From: Koichi Sasada <ko1@a...> Date: Mon, 14 Dec 2020 10:50:22 +0900 Subject: add tests for method cache. diff --git a/test/ruby/test_method_cache.rb b/test/ruby/test_method_cache.rb new file mode 100644 index 0000000..f3b38f1 --- /dev/null +++ b/test/ruby/test_method_cache.rb @@ -0,0 +1,65 @@ https://github.com/ruby/ruby/blob/trunk/test/ruby/test_method_cache.rb#L1 +# frozen_string_literal: true +require 'test/unit' + +class TestMethodCache < Test::Unit::TestCase + def test_undef + # clear same + c0 = Class.new do + def foo; end + undef foo + end + + assert_raise(NoMethodError) do + c0.new.foo + end + + c0.class_eval do + def foo; :ok; end + end + + assert_equal :ok, c0.new.foo + end + + def test_undef_with_subclasses + # with subclasses + c0 = Class.new do + def foo; end + undef foo + end + + c1 = Class.new(c0) + + assert_raise(NoMethodError) do + c0.new.foo + end + + c0.class_eval do + def foo; :ok; end + end + + assert_equal :ok, c0.new.foo + end + + def test_undef_with_subclasses_complicated + c0 = Class.new{ def foo; end } + c1 = Class.new(c0){ undef foo } + c2 = Class.new(c1) + c3 = Class.new(c2) + c4 = Class.new(c3) + + assert_raise(NoMethodError) do + c3.new.foo + end + + c2.class_eval do + def foo; :c2; end + end + + assert_raise(NoMethodError) do + c1.new.foo + end + + assert_equal :c2, c3.new.foo + end +end + -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/