yarv-diff:241
From: ko1 atdot.net
Date: 13 Feb 2006 16:37:43 -0000
Subject: [yarv-diff:241] r404 - in trunk: . test/ruby
Author: aamine Date: 2006-02-14 01:37:43 +0900 (Tue, 14 Feb 2006) New Revision: 404 Added: trunk/test/ruby/test_class.rb Modified: trunk/ChangeLog Log: * test/ruby/test_class.rb: new file (imported from rubicon). Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2006-02-13 16:32:33 UTC (rev 403) +++ trunk/ChangeLog 2006-02-13 16:37:43 UTC (rev 404) @@ -4,6 +4,11 @@ # from Mon, 03 May 2004 01:24:19 +0900 # +2006-02-14(Tue) 01:36:57 +0900 Minero Aoki <aamine loveruby.net> + + * test/ruby/test_class.rb: new file (imported from rubicon). + + 2006-02-14(Tue) 01:32:23 +0900 Minero Aoki <aamine loveruby.net> * test/ruby/test_module.rb: ignore PP mixins. Added: trunk/test/ruby/test_class.rb =================================================================== --- trunk/test/ruby/test_class.rb 2006-02-13 16:32:33 UTC (rev 403) +++ trunk/test/ruby/test_class.rb 2006-02-13 16:37:43 UTC (rev 404) @@ -0,0 +1,80 @@ +require 'test/unit' + +class TestClass < Test::Unit::TestCase + + # ------------------ + # Various test classes + # ------------------ + + class ClassOne + attr :num_args + @@subs = [] + def initialize(*args) + @num_args = args.size + @args = args + end + def [](n) + @args[n] + end + def ClassOne.inherited(klass) + subs.push klass + end + def subs + @@subs + end + end + + class ClassTwo < ClassOne + end + + class ClassThree < ClassOne + end + + class ClassFour < ClassThree + end + + # ------------------ + # Start of tests + # ------------------ + + def test_s_inherited + assert_equal([ClassTwo, ClassThree, ClassFour], ClassOne.new.subs) + end + + def test_s_new + c = Class.new + assert_same(Class, c.class) + assert_same(Object, c.superclass) + + c = Class.new(Fixnum) + assert_same(Class, c.class) + assert_same(Fixnum, c.superclass) + end + + def test_00_new_basic + a = ClassOne.new + assert_equal(ClassOne, a.class) + assert_equal(0, a.num_args) + + a = ClassOne.new(1, 2, 3) + assert_equal(3, a.num_args) + assert_equal(1, a[0]) + end + + def test_01_new_inherited + a = ClassTwo.new + assert_equal(ClassTwo, a.class) + assert_equal(0, a.num_args) + + a = ClassTwo.new(1, 2, 3) + assert_equal(3, a.num_args) + assert_equal(1, a[0]) + end + + def test_superclass + assert_equal(ClassOne, ClassTwo.superclass) + assert_equal(Object, ClassTwo.superclass.superclass) + assert_equal(nil, ClassTwo.superclass.superclass.superclass) + end + +end -- ML: yarv-diff quickml.atdot.net Info: http://www.atdot.net/~ko1/quickml