Commit 0719f523 authored by Yukihiro "Matz" Matsumoto's avatar Yukihiro "Matz" Matsumoto

Merge pull request #240 from bovi/superclass-improvement

Class#superclass improvement
parents 7009a1d8 0c2d7402
......@@ -822,10 +822,16 @@ mrb_class_new_class(mrb_state *mrb, mrb_value cv)
mrb_value
mrb_class_superclass(mrb_state *mrb, mrb_value klass)
{
struct RClass *c, *s;
struct RClass *c;
mrb_value superclass;
c = mrb_class_ptr(klass);
s = mrb_class_real(c->super);
return mrb_obj_value(s);
if (c->super)
superclass = mrb_obj_value(mrb_class_real(c->super));
else
superclass = mrb_nil_value();
return superclass;
}
static mrb_value
......
......@@ -13,3 +13,8 @@ assert('ArgumentError', '15.2.24') do
ArgumentError.class == Class and e2.class == ArgumentError
end
assert('ArgumentError superclass', '15.2.24.2') do
ArgumentError.superclass == StandardError
end
......@@ -5,6 +5,10 @@ assert('Array', '15.2.12') do
Array.class == Class
end
assert('Array superclass', '15.2.12.2') do
Array.superclass == Object
end
assert('Array.[]', '15.2.12.4.1') do
Array.[](1,2,3) == [1, 2, 3]
end
......
##
# BasicObject
assert('BasicObject') do
BasicObject.class == Class
end
assert('BasicObject superclass') do
BasicObject.superclass == nil
end
......@@ -5,9 +5,8 @@ assert('Class', '15.2.3') do
Class.class == Class
end
assert('Class#superclass', '15.2.3.3.4') do
class SubClass < String; end
SubClass.superclass == String
assert('Class superclass', '15.2.3.2') do
Class.superclass == Module
end
assert('Class#new', '15.2.3.3.3') do
......@@ -40,6 +39,11 @@ assert('Class#new', '15.2.3.3.3') do
# with block doesn't work yet
end
assert('Class#superclass', '15.2.3.3.4') do
class SubClass < String; end
SubClass.superclass == String
end
# Not ISO specified
assert('Class 1') do
......
......@@ -5,6 +5,10 @@ assert('Exception', '15.2.22') do
Exception.class == Class
end
assert('Exception superclass', '15.2.22.2') do
Exception.superclass == Object
end
assert('Exception.exception', '15.2.22.4.1') do
e = Exception.exception('a')
......
......@@ -5,6 +5,10 @@ assert('FalseClass', '15.2.6') do
FalseClass.class == Class
end
assert('FalseClass superclass', '15.2.6.2') do
FalseClass.superclass == Object
end
assert('FalseClass false', '15.2.6.1') do
not false
end
......
......@@ -5,6 +5,10 @@ assert('Float', '15.2.9') do
Float.class == Class
end
assert('Float superclass', '15.2.9.2') do
Float.superclass == Numeric
end
assert('Float#+', '15.2.9.3.1') do
a = 3.123456788 + 0.000000001
b = 3.123456789 + 1
......
......@@ -5,6 +5,10 @@ assert('Hash', '15.2.13') do
Hash.class == Class
end
assert('Hash superclass', '15.2.13.2') do
Hash.superclass == Object
end
assert('Hash#==', '15.2.13.4.1') do
({ 'abc' => 'abc' } == { 'abc' => 'abc' }) and
not ({ 'abc' => 'abc' } == { 'cba' => 'cba' })
......
......@@ -4,3 +4,8 @@
assert('IndexError', '15.2.33') do
IndexError.class == Class
end
assert('IndexError superclass', '15.2.33.2') do
IndexError.superclass == StandardError
end
......@@ -5,6 +5,10 @@ assert('Integer', '15.2.8') do
Integer.class == Class
end
assert('Integer superclass', '15.2.8.2') do
Integer.superclass == Numeric
end
assert('Integer#+', '15.2.8.3.1') do
a = 1+1
b = 1+1.0
......
......@@ -5,6 +5,10 @@ assert('Module', '15.2.2') do
Module.class == Class
end
assert('Module superclass', '15.2.2.2') do
Module.superclass == Object
end
assert('Module#const_defined?', '15.2.2.4.20') do
module Test4ConstDefined
Const4Test4ConstDefined = true
......
......@@ -5,6 +5,10 @@ assert('NameError', '15.2.31') do
NameError.class == Class
end
assert('NameError superclass', '15.2.31.2') do
NameError.superclass == StandardError
end
# TODO 15.2.31.2.1 NameError#name
assert('NameError#initialize', '15.2.31.2.2') do
......
......@@ -11,3 +11,8 @@ assert('NoMethodError', '15.2.32') do
NoMethodError.class == Class and e2.class == NoMethodError
end
assert('NoMethodError superclass', '15.2.32.2') do
NoMethodError.superclass == NameError
end
......@@ -5,6 +5,10 @@ assert('Numeric', '15.2.7') do
Numeric.class == Class
end
assert('Numeric superclass', '15.2.7.2') do
Numeric.superclass == Object
end
assert('Numeric#+@', '15.2.7.4.1') do
+1 == +1
end
......
......@@ -4,3 +4,8 @@
assert('Object', '15.2.1') do
Object.class == Class
end
assert('Object superclass', '15.2.1.2') do
Object.superclass == BasicObject
end
......@@ -5,6 +5,10 @@ assert('Proc', '15.2.17') do
Proc.class == Class
end
assert('Proc superclass', '15.2.17.2') do
Proc.superclass == Object
end
assert('Proc.new', '15.2.17.3.1') do
a = nil
......
......@@ -5,6 +5,10 @@ assert('Range', '15.2.14') do
Range.class == Class
end
assert('Range superclass', '15.2.14.2') do
Range.superclass == Object
end
assert('Range#==', '15.2.14.4.1') do
(1..10) == (1..10) and not (1..10) == (1..100)
end
......
......@@ -4,3 +4,8 @@
assert('RangeError', '15.2.26') do
RangeError.class == Class
end
assert('RangeError superclass', '15.2.26.2') do
RangeError.superclass == StandardError
end
......@@ -4,3 +4,8 @@
assert('StandardError', '15.2.23') do
StandardError.class == Class
end
assert('StandardError superclass', '15.2.23.2') do
StandardError.superclass == Exception
end
......@@ -5,6 +5,10 @@ assert('String', '15.2.10') do
String.class == Class
end
assert('String superclass', '15.2.10.2') do
String.superclass == Object
end
assert('String#*', '15.2.10.5.1') do
'a' * 5 == 'aaaaa'
end
......
......@@ -4,3 +4,8 @@
assert('Struct', '15.2.18') do
Struct.class == Class
end
assert('Struct superclass', '15.2.18.2') do
Struct.superclass == Object
end
......@@ -5,6 +5,10 @@ assert('Symbol', '15.2.11') do
Symbol.class == Class
end
assert('Symbol superclass', '15.2.11.2') do
Symbol.superclass == Object
end
assert('Symbol#===', '15.2.11.3.1') do
:abc === :abc and not :abc === :cba
end
......
......@@ -5,6 +5,10 @@ assert('Time', '15.2.19') do
Time.class == Class
end
assert('Time superclass', '15.2.19.2') do
Time.superclass == Object
end
assert('Time.at', '15.2.19.6.1') do
Time.at(1300000000.0)
end
......
......@@ -5,6 +5,10 @@ assert('TrueClass', '15.2.5') do
TrueClass.class == Class
end
assert('TrueClass superclass', '15.2.5.2') do
TrueClass.superclass == Object
end
assert('TrueClass true', '15.2.5.1') do
true
end
......
......@@ -4,3 +4,8 @@
assert('TypeError', '15.2.29') do
TypeError.class == Class
end
assert('TypeError superclass', '15.2.29.2') do
TypeError.superclass == StandardError
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment