[前][次][番号順一覧][スレッド一覧]

ruby-changes:64258

From: Nobuyoshi <ko1@a...>
Date: Fri, 18 Dec 2020 13:03:54 +0900 (JST)
Subject: [ruby-changes:64258] 34f0606217 (master): Added tests for [Feature #17314]

https://git.ruby-lang.org/ruby.git/commit/?id=34f0606217

From 34f06062174882a98ebef998c50ad8d4f7fc0f2e Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Fri, 18 Dec 2020 13:03:22 +0900
Subject: Added tests for [Feature #17314]


diff --git a/test/ruby/test_module.rb b/test/ruby/test_module.rb
index 037715b..e228786 100644
--- a/test/ruby/test_module.rb
+++ b/test/ruby/test_module.rb
@@ -840,6 +840,11 @@ class TestModule < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_module.rb#L840
     assert_equal(:aClass1, o.aClass1)
     assert_equal(:aClass2, o.aClass2)
 
+    o = (c = Class.new(AClass)).new
+    c.class_eval {public [:aClass1, :aClass2]}
+    assert_equal(:aClass1, o.aClass1)
+    assert_equal(:aClass2, o.aClass2)
+
     o = AClass.new
     assert_equal(:aClass, o.aClass)
     assert_raise(NoMethodError, /private method/) {o.aClass1}
@@ -857,6 +862,11 @@ class TestModule < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_module.rb#L862
     assert_raise(NoMethodError, /private method/) {o.aClass}
     assert_raise(NoMethodError, /private method/) {o.aClass2}
 
+    o = (c = Class.new(AClass)).new
+    c.class_eval {private [:aClass, :aClass2]}
+    assert_raise(NoMethodError, /private method/) {o.aClass}
+    assert_raise(NoMethodError, /private method/) {o.aClass2}
+
     o = AClass.new
     assert_equal(:aClass, o.aClass)
     assert_raise(NoMethodError, /private method/) {o.aClass1}
@@ -883,6 +893,13 @@ class TestModule < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_module.rb#L893
     assert_equal(:aClass, c.new._aClass(o))
     assert_equal(:aClass1, c.new._aClass1(o))
 
+    o = (c = Class.new(aclass)).new
+    c.class_eval {protected [:aClass, :aClass1]}
+    assert_raise(NoMethodError, /protected method/) {o.aClass}
+    assert_raise(NoMethodError, /protected method/) {o.aClass1}
+    assert_equal(:aClass, c.new._aClass(o))
+    assert_equal(:aClass1, c.new._aClass1(o))
+
     o = AClass.new
     assert_equal(:aClass, o.aClass)
     assert_raise(NoMethodError, /private method/) {o.aClass1}
@@ -1215,6 +1232,15 @@ class TestModule < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_module.rb#L1232
     assert_raise(NameError) do
       c.instance_eval { attr_reader :"." }
     end
+
+    assert_equal([:a], c.class_eval { attr :a })
+    assert_equal([:b, :c], c.class_eval { attr :b, :c })
+    assert_equal([:d], c.class_eval { attr_reader :d })
+    assert_equal([:e, :f], c.class_eval { attr_reader :e, :f })
+    assert_equal([:g=], c.class_eval { attr_writer :g })
+    assert_equal([:h=, :i=], c.class_eval { attr_writer :h, :i })
+    assert_equal([:g, :g=], c.class_eval { attr_accessor :g })
+    assert_equal([:h, :h=, :i, :i=], c.class_eval { attr_accessor :h, :i })
   end
 
   def test_alias_method
@@ -1224,9 +1250,10 @@ class TestModule < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_module.rb#L1250
     o = c.new
     assert_respond_to(o, :foo)
     assert_not_respond_to(o, :bar)
-    c.class_eval {alias_method :bar, :foo}
+    r = c.class_eval {alias_method :bar, :foo}
     assert_respond_to(o, :bar)
     assert_equal(:foo, o.bar)
+    assert_equal(:bar, r)
   end
 
   def test_undef
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]