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

ruby-changes:19791

From: yugui <ko1@a...>
Date: Tue, 31 May 2011 09:12:30 +0900 (JST)
Subject: [ruby-changes:19791] yugui:r31836 (ruby_1_9_2): merges r31614 from trunk into ruby_1_9_2.

yugui	2011-05-31 09:12:19 +0900 (Tue, 31 May 2011)

  New Revision: 31836

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=31836

  Log:
    merges r31614 from trunk into ruby_1_9_2.
    --
    * test/test_singleton.rb:  Add tests from lib/singleton.rb.  Patch by
      Pete Higgins.  [Ruby 1.9 - Bug #4715]

  Modified files:
    branches/ruby_1_9_2/ChangeLog
    branches/ruby_1_9_2/test/test_singleton.rb
    branches/ruby_1_9_2/version.h

Index: ruby_1_9_2/ChangeLog
===================================================================
--- ruby_1_9_2/ChangeLog	(revision 31835)
+++ ruby_1_9_2/ChangeLog	(revision 31836)
@@ -1,3 +1,8 @@
+Wed May 18 03:14:49 2011  Eric Hodel  <drbrain@s...>
+
+	* test/test_singleton.rb:  Add tests from lib/singleton.rb.  Patch by
+	  Pete Higgins.  [Ruby 1.9 - Bug #4715]
+
 Tue May 17 20:20:49 2011  KOSAKI Motohiro  <kosaki.motohiro@g...>
 
 	* vm_core.h (rb_thread_struct): add volatile to
Index: ruby_1_9_2/version.h
===================================================================
--- ruby_1_9_2/version.h	(revision 31835)
+++ ruby_1_9_2/version.h	(revision 31836)
@@ -1,5 +1,5 @@
 #define RUBY_VERSION "1.9.2"
-#define RUBY_PATCHLEVEL 253
+#define RUBY_PATCHLEVEL 254
 #define RUBY_VERSION_MAJOR 1
 #define RUBY_VERSION_MINOR 9
 #define RUBY_VERSION_TEENY 1
Index: ruby_1_9_2/test/test_singleton.rb
===================================================================
--- ruby_1_9_2/test/test_singleton.rb	(revision 31835)
+++ ruby_1_9_2/test/test_singleton.rb	(revision 31836)
@@ -2,14 +2,102 @@
 require 'singleton'
 
 class TestSingleton < Test::Unit::TestCase
-  class C
+  class SingletonTest
     include Singleton
   end
 
   def test_marshal
-    o1 = C.instance
+    o1 = SingletonTest.instance
     m = Marshal.dump(o1)
     o2 = Marshal.load(m)
     assert_same(o1, o2)
   end
+
+  def test_instance_never_changes
+    a = SingletonTest.instance
+    b = SingletonTest.instance
+    assert_same a, b
+  end
+
+  def test_initialize_raises_exception
+    assert_raises NoMethodError do
+      SingletonTest.new
+    end
+  end
+
+  def test_allocate_raises_exception
+    assert_raises NoMethodError do
+      SingletonTest.allocate
+    end
+  end
+
+  def test_clone_raises_exception
+    exception = assert_raises TypeError do
+      SingletonTest.instance.clone
+    end
+
+    expected = "can't clone instance of singleton TestSingleton::SingletonTest"
+
+    assert_equal expected, exception.message
+  end
+
+  def test_dup_raises_exception
+    exception = assert_raises TypeError do
+      SingletonTest.instance.dup
+    end
+
+    expected = "can't dup instance of singleton TestSingleton::SingletonTest"
+
+    assert_equal expected, exception.message
+  end
+
+  def test_include_in_module_raises_exception
+    mod = Module.new
+
+    exception = assert_raises TypeError do
+      mod.class_eval do
+        include Singleton
+      end
+    end
+
+    expected = "Inclusion of the OO-Singleton module in module #{mod}"
+
+    assert_equal expected, exception.message
+  end
+
+  def test_extending_singleton_raises_exception
+    assert_raises NoMethodError do
+      'foo'.extend Singleton
+    end
+  end
+
+  def test_inheritance_works_with_overridden_inherited_method
+    super_super_called = false
+
+    outer = Class.new do
+      define_singleton_method :inherited do |sub|
+        super_super_called = true
+      end
+    end
+
+    inner = Class.new(outer) do
+      include Singleton
+    end
+
+    tester = Class.new(inner)
+
+    assert super_super_called
+
+    a = tester.instance
+    b = tester.instance
+    assert_same a, b
+  end
+
+  def test_class_level_cloning_preserves_singleton_behavior
+    klass = SingletonTest.clone
+
+    a = klass.instance
+    b = klass.instance
+    assert_same a, b
+  end
 end

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

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