Remove `Kernel#class_defined?` which is not available in CRuby;
MODIFY
mrbgems/mruby-kernel-ext/test/kernel.rb
mrbgems/mruby-kernel-ext/test/kernel.rb
@@ -49,21 +49,23 @@ assert('Kernel#__method__') do
end
assert('Kernel#Integer') do
- assert_equal(123, Integer(123.999)) if class_defined?("Float")
assert_equal(26, Integer("0x1a"))
assert_equal(930, Integer("0930", 10))
assert_equal(7, Integer("111", 2))
assert_equal(0, Integer("0"))
assert_equal(0, Integer("00000"))
assert_raise(TypeError) { Integer(nil) }
+ skip unless Object.const_defined?(:Float)
+ assert_equal(123, Integer(123.999))
end
assert('Kernel#Float') do
+ skip unless Object.const_defined?(:Float)
assert_equal(1.0, Float(1))
assert_equal(123.456, Float(123.456))
assert_equal(123.456, Float("123.456"))
assert_raise(TypeError) { Float(nil) }
-end if class_defined?("Float")
+end
assert('Kernel#String') do
assert_equal("main", String(self))

MODIFY
mrbgems/mruby-numeric-ext/test/numeric.rb
mrbgems/mruby-numeric-ext/test/numeric.rb
@@ -14,8 +14,9 @@ assert('Integer#div') do
end
assert('Float#div') do
+ skip unless Object.const_defined?(:Float)
assert_float 52, 365.2425.div(7)
-end if class_defined?("Float")
+end
assert('Integer#zero?') do
assert_equal true, 0.zero?

MODIFY
mrbgems/mruby-object-ext/test/nil.rb
mrbgems/mruby-object-ext/test/nil.rb
@@ -3,8 +3,9 @@ assert('NilClass#to_a') do
end
assert('NilClass#to_f') do
+ skip unless Object.const_defined?(:Float)
assert_equal 0.0, nil.to_f
-end if class_defined?("Float")
+end
assert('NilClass#to_i') do
assert_equal 0, nil.to_i

MODIFY
mrbgems/mruby-objectspace/test/objectspace.rb
mrbgems/mruby-objectspace/test/objectspace.rb
assert('ObjectSpace.count_objects') do
h = {}
- f = Fiber.new {} if Object.const_defined? :Fiber
+ f = Fiber.new {} if Object.const_defined?(:Fiber)
ObjectSpace.count_objects(h)
assert_kind_of(Hash, h)
assert_true(h.keys.all? {|x| x.is_a?(Symbol) || x.is_a?(Integer) })

MODIFY
mrbgems/mruby-sprintf/test/sprintf.rb
mrbgems/mruby-sprintf/test/sprintf.rb
assert('String#%') do
assert_equal "one=1", "one=%d" % 1
assert_equal "1 one", "%d %s" % [ 1, "one" ]
- assert_equal "1.0", "%3.1f" % 1.01 if class_defined?("Float")
assert_equal "123 < 456", "%{num} < %<str>s" % { num: 123, str: "456" }
assert_equal 15, ("%b" % (1<<14)).size
+ skip unless Object.const_defined?(:Float)
+ assert_equal "1.0", "%3.1f" % 1.01
end
assert('String#% with inf') do
+ skip unless Object.const_defined?(:Float)
inf = Float::INFINITY
assert_equal "Inf", "%f" % inf
@@ -35,9 +37,10 @@ assert('String#% with inf') do
assert_equal " Inf", "% 3f" % inf
assert_equal " Inf", "% 4f" % inf
assert_equal " Inf", "% 5f" % inf
-end if class_defined?("Float")
+end
assert('String#% with nan') do
+ skip unless Object.const_defined?(:Float)
nan = Float::NAN
assert_equal "NaN", "%f" % nan
@@ -63,7 +66,7 @@ assert('String#% with nan') do
assert_equal " NaN", "% 3f" % nan
assert_equal " NaN", "% 4f" % nan
assert_equal " NaN", "% 5f" % nan
-end if class_defined?("Float")
+end
assert("String#% with invalid chr") do
begin

MODIFY
mrblib/float.rb
mrblib/float.rb
@@ -6,4 +6,4 @@ class Float
# mruby special - since mruby integers may be upgraded to floats,
# floats should be compatible to integers.
include Integral
-end if class_defined?("Float")
+end if Object.const_defined?(:Float)

MODIFY
mrblib/numeric.rb
mrblib/numeric.rb
@@ -104,7 +104,7 @@ module Integral
raise ArgumentError, "step can't be 0" if step == 0
return to_enum(:step, num, step) unless block
- i = if class_defined?("Float") && num.kind_of?(Float) then self.to_f else self end
+ i = if Object.const_defined?(:Float) && num.kind_of?(Float) then self.to_f else self end
if num == nil
while true
block.call(i)

MODIFY
src/kernel.c
src/kernel.c
@@ -640,16 +640,6 @@ mrb_f_raise(mrb_state *mrb, mrb_value self)
return mrb_nil_value(); /* not reached */
}
-static mrb_value
-mrb_krn_class_defined(mrb_state *mrb, mrb_value self)
-{
- mrb_value str;
-
- mrb_get_args(mrb, "S", &str);
- return mrb_bool_value(mrb_class_defined(mrb, RSTRING_PTR(str)));
-}
-
-
/* 15.3.1.3.41 */
/*
* call-seq:
@@ -847,8 +837,6 @@ mrb_init_kernel(mrb_state *mrb)
mrb_define_method(mrb, krn, "__to_int", mrb_to_int, MRB_ARGS_NONE()); /* internal */
mrb_define_method(mrb, krn, "__to_str", mrb_to_str, MRB_ARGS_NONE()); /* internal */
- mrb_define_method(mrb, krn, "class_defined?", mrb_krn_class_defined, MRB_ARGS_REQ(1));
-
mrb_include_module(mrb, mrb->object_class, mrb->kernel_module);
mrb_define_alias(mrb, mrb->module_class, "dup", "clone"); /* XXX */
}

MODIFY
test/t/array.rb
test/t/array.rb
@@ -55,9 +55,10 @@ assert('Array#[]', '15.2.12.5.4') do
assert_equal(nil, [1,2,3].[](-4))
a = [ "a", "b", "c", "d", "e" ]
- assert_equal("b", a[1.1]) if class_defined?("Float")
assert_equal(["b", "c"], a[1,2])
assert_equal(["b", "c", "d"], a[1..-2])
+ skip unless Object.const_defined?(:Float)
+ assert_equal("b", a[1.1])
end
assert('Array#[]=', '15.2.12.5.5') do

MODIFY
test/t/class.rb
test/t/class.rb
@@ -350,7 +350,7 @@ assert('singleton tests') do
7
end
end
- end if class_defined?("Float")
+ end if Object.const_defined?(:Float)
end
assert('clone Class') do

MODIFY
test/t/float.rb
test/t/float.rb
##
# Float ISO Test
-if class_defined?("Float")
+if Object.const_defined?(:Float)
assert('Float', '15.2.9') do
assert_equal Class, Float.class
@@ -206,4 +206,4 @@ assert('Float#>>') do
assert_equal(-1, -23.0 >> 128)
end
-end # class_defined?("Float")
+end # const_defined?(:Float)

MODIFY
test/t/hash.rb
test/t/hash.rb
@@ -8,8 +8,9 @@ end
assert('Hash#==', '15.2.13.4.1') do
assert_true({ 'abc' => 'abc' } == { 'abc' => 'abc' })
assert_false({ 'abc' => 'abc' } == { 'cba' => 'cba' })
- assert_true({ :equal => 1 } == { :equal => 1.0 }) if class_defined?("Float")
assert_false({ :a => 1 } == true)
+ skip unless Object.const_defined?(:Float)
+ assert_true({ :equal => 1 } == { :equal => 1.0 })
end
assert('Hash#[]', '15.2.13.4.2') do

MODIFY
test/t/integer.rb
test/t/integer.rb
@@ -7,10 +7,10 @@ end
assert('Integer#+', '15.2.8.3.1') do
a = 1+1
- b = 1+1.0 if class_defined?("Float")
+ b = 1+1.0 if Object.const_defined?(:Float)
assert_equal 2, a
- assert_equal 2.0, b if class_defined?("Float")
+ assert_equal 2.0, b if Object.const_defined?(:Float)
assert_raise(TypeError){ 0+nil }
assert_raise(TypeError){ 1+nil }
@@ -18,40 +18,38 @@ assert('Integer#+', '15.2.8.3.1') do
c = Mrbtest::FIXNUM_MAX + 1
d = Mrbtest::FIXNUM_MAX.__send__(:+, 1)
- if class_defined?("Float")
+ skip unless Object.const_defined?(:Float)
e = Mrbtest::FIXNUM_MAX + 1.0
assert_equal Float, c.class
assert_equal Float, d.class
assert_float e, c
assert_float e, d
end
-end
assert('Integer#-', '15.2.8.3.2') do
a = 2-1
- b = 2-1.0 if class_defined?("Float")
+ b = 2-1.0 if Object.const_defined?(:Float)
assert_equal 1, a
- assert_equal 1.0, b if class_defined?("Float")
+ assert_equal 1.0, b if Object.const_defined?(:Float)
c = Mrbtest::FIXNUM_MIN - 1
d = Mrbtest::FIXNUM_MIN.__send__(:-, 1)
- if class_defined?("Float")
+ skip unless Object.const_defined?(:Float)
e = Mrbtest::FIXNUM_MIN - 1.0
assert_equal Float, c.class
assert_equal Float, d.class
assert_float e, c
assert_float e, d
end
-end
assert('Integer#*', '15.2.8.3.3') do
a = 1*1
- b = 1*1.0 if class_defined?("Float")
+ b = 1*1.0 if Object.const_defined?(:Float)
assert_equal 1, a
- assert_equal 1.0, b if class_defined?("Float")
+ assert_equal 1.0, b if Object.const_defined?(:Float)
assert_raise(TypeError){ 0*nil }
assert_raise(TypeError){ 1*nil }
@@ -59,14 +57,13 @@ assert('Integer#*', '15.2.8.3.3') do
c = Mrbtest::FIXNUM_MAX * 2
d = Mrbtest::FIXNUM_MAX.__send__(:*, 2)
- if class_defined?("Float")
+ skip unless Object.const_defined?(:Float)
e = Mrbtest::FIXNUM_MAX * 2.0
assert_equal Float, c.class
assert_equal Float, d.class
assert_float e, c
assert_float e, d
end
-end
assert('Integer#/', '15.2.8.3.4') do
a = 2/1
@@ -226,8 +223,9 @@ assert('Integer#times', '15.2.8.3.22') do
end
assert('Integer#to_f', '15.2.8.3.23') do
+ skip unless Object.const_defined?(:Float)
assert_equal 1.0, 1.to_f
-end if class_defined?("Float")
+end
assert('Integer#to_i', '15.2.8.3.24') do
assert_equal 1, 1.to_i

MODIFY
test/t/numeric.rb
test/t/numeric.rb
@@ -15,7 +15,8 @@ end
assert('Numeric#abs', '15.2.7.4.3') do
assert_equal(1, 1.abs)
- assert_equal(1.0, -1.abs) if class_defined?("Float")
+ skip unless Object.const_defined?(:Float)
+ assert_equal(1.0, -1.abs)
end
assert('Numeric#pow') do

MODIFY
test/t/range.rb
test/t/range.rb
@@ -8,7 +8,8 @@ end
assert('Range#==', '15.2.14.4.1') do
assert_true (1..10) == (1..10)
assert_false (1..10) == (1..100)
- assert_true (1..10) == Range.new(1.0, 10.0) if class_defined?("Float")
+ skip unless Object.const_defined?(:Float)
+ assert_true (1..10) == Range.new(1.0, 10.0)
end
assert('Range#===', '15.2.14.4.2') do

MODIFY
test/t/string.rb
test/t/string.rb
@@ -155,7 +155,7 @@ assert('String#[]=') do
d[-10] = 'X'
end
- if class_defined?("Float")
+ if Object.const_defined?(:Float)
e = 'abc'
e[1.1] = 'X'
assert_equal 'aXc', e
@@ -618,7 +618,7 @@ assert('String#to_f', '15.2.10.5.38') do
assert_float(12345.6789, c)
assert_float(0, d)
assert_float(Float::INFINITY, e)
-end if class_defined?("Float")
+end if Object.const_defined?(:Float)
assert('String#to_i', '15.2.10.5.39') do
a = ''.to_i

Remove `Kernel#class_defined?` which is not available in CRuby; #3829