From 908667e45a9cbbb954530f3c46e7a73a261d5a7d Mon Sep 17 00:00:00 2001 From: knu Date: Thu, 25 Mar 2010 19:00:30 +0000 Subject: [PATCH] Add tests for Kernel#singleton_class. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@27052 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_object.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/test/ruby/test_object.rb b/test/ruby/test_object.rb index b06cdd15f1..8350fb2a94 100644 --- a/test/ruby/test_object.rb +++ b/test/ruby/test_object.rb @@ -373,4 +373,25 @@ class TestObject < Test::Unit::TestCase end end.call end + + def test_singleton_class + x = Object.new + xs = class << x; self; end + assert_equal(xs, x.singleton_class) + + y = Object.new + ys = y.singleton_class + assert_equal(class << y; self; end, ys) + + assert_equal(NilClass, nil.singleton_class) + assert_equal(TrueClass, true.singleton_class) + assert_equal(FalseClass, false.singleton_class) + + assert_raise(TypeError) do + 123.singleton_class + end + assert_raise(TypeError) do + :foo.singleton_class + end + end end