summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--include/mrbconf.h12
-rw-r--r--src/kernel.c2
-rw-r--r--src/sprintf.c4
-rw-r--r--test/t/kernel.rb141
4 files changed, 141 insertions, 18 deletions
diff --git a/include/mrbconf.h b/include/mrbconf.h
index 21b8fea18..f496c53d9 100644
--- a/include/mrbconf.h
+++ b/include/mrbconf.h
@@ -15,10 +15,10 @@
/* -DDISABLE_XXXX to change to drop the feature */
#define DISABLE_REGEXP /* regular expression classes */
-#undef DISABLE_KERNEL_SPRINTF /* Kernel.sprintf method */
-#undef DISABLE_MATH /* Math functions */
-#undef DISABLE_TIME /* Time class */
-#undef DISABLE_STRUCT /* Struct class */
+//#define DISABLE_SPRINTF /* Kernel.sprintf method */
+//#define DISABLE_MATH /* Math functions */
+//#define DISABLE_TIME /* Time class */
+//#define DISABLE_STRUCT /* Struct class */
#undef HAVE_UNISTD_H /* WINDOWS */
#define HAVE_UNISTD_H /* LINUX */
@@ -38,8 +38,8 @@ typedef intptr_t mrb_sym;
#ifndef DISABLE_REGEXP
#define ENABLE_REGEXP
#endif
-#ifndef DISABLE_KERNEL_SPRINTF
-#define ENABLE_KERNEL_SPRINTF
+#ifndef DISABLE_SPRINTF
+#define ENABLE_SPRINTF
#endif
#ifndef DISABLE_MATH
#define ENABLE_MATH
diff --git a/src/kernel.c b/src/kernel.c
index 5e17d4b5a..605b84124 100644
--- a/src/kernel.c
+++ b/src/kernel.c
@@ -1168,7 +1168,7 @@ mrb_init_kernel(mrb_state *mrb)
mrb_define_method(mrb, krn, "singleton_methods", mrb_obj_singleton_methods_m, ARGS_ANY()); /* 15.3.1.3.45 */
mrb_define_method(mrb, krn, "to_s", mrb_any_to_s, ARGS_NONE()); /* 15.3.1.3.46 */
-#ifdef ENABLE_KERNEL_SPRINTF
+#ifdef ENABLE_SPRINTF
mrb_define_method(mrb, krn, "sprintf", mrb_f_sprintf, ARGS_ANY()); /* in sprintf.c */
mrb_define_method(mrb, krn, "format", mrb_f_sprintf, ARGS_ANY()); /* in sprintf.c */
#endif
diff --git a/src/sprintf.c b/src/sprintf.c
index 86c3b66bc..68addef89 100644
--- a/src/sprintf.c
+++ b/src/sprintf.c
@@ -6,7 +6,7 @@
#include "mruby.h"
-#ifdef ENABLE_KERNEL_SPRINTF
+#ifdef ENABLE_SPRINTF
#include <stdio.h>
#include <string.h>
@@ -1084,4 +1084,4 @@ fmt_setup(char *buf, size_t size, int c, int flags, int width, int prec)
*buf = '\0';
}
-#endif /* ENABLE_KERNEL_SPRINTF */
+#endif /* ENABLE_SPRINTF */
diff --git a/test/t/kernel.rb b/test/t/kernel.rb
index c1f42e420..5aa7672d7 100644
--- a/test/t/kernel.rb
+++ b/test/t/kernel.rb
@@ -7,13 +7,20 @@ end
assert('Kernel.block_given?', '15.3.1.2.2') do
def bg_try(&b)
- if block_given?
+ if Kernel.block_given?
yield
else
"no block"
end
end
- (Kernel.block_given? == false) && (bg_try == "no block") && ((bg_try { "block" }) == "block") && ((bg_try do "block" end) == "block")
+
+ (Kernel.block_given? == false) and
+ # test without block
+ (bg_try == "no block") and
+ # test with block
+ ((bg_try { "block" }) == "block") and
+ # test with block
+ ((bg_try do "block" end) == "block")
end
assert('Kernel.global_variables', '15.3.1.2.4') do
@@ -32,6 +39,11 @@ assert('Kernel.lambda', '15.3.1.2.6') do
l.call and l.class == Proc
end
+# Not implemented at the moment
+#assert('Kernel.local_variables', '15.3.1.2.7') do
+# Kernel.local_variables.class == Array
+#end
+
assert('Kernel.loop', '15.3.1.2.8') do
i = 0
@@ -58,17 +70,61 @@ assert('Kernel.puts', '15.3.1.2.11') do
true
end
-# TODO fails at the moment without arguments
assert('Kernel.raise', '15.3.1.2.12') do
e_list = []
begin
- raise RuntimeError.new
+ Kernel.raise
+ rescue => e
+ e_list << e
+ end
+
+ begin
+ Kernel.raise RuntimeError.new
rescue => e
e_list << e
end
- e_list[0].class == RuntimeError
+ # result without argument
+ e_list[0].class == RuntimeError and
+ # result with RuntimeError argument
+ e_list[1].class == RuntimeError
+end
+
+assert('Kernel#__id__', '15.3.1.3.3') do
+ __id__.class == Fixnum
+end
+
+assert('Kernel#__send__', '15.3.1.3.4') do
+ # test with block
+ l = __send__(:lambda) do
+ true
+ end
+
+ l.call and l.class == Proc and
+ # test with argument
+ __send__(:respond_to?, :nil?) and
+ # test without argument and without block
+ __send__(:public_methods).class == Array
+end
+
+assert('Kernel#block_given?', '15.3.1.3.6') do
+ def bg_try(&b)
+ if block_given?
+ yield
+ else
+ "no block"
+ end
+ end
+
+ (block_given? == false) and
+ (bg_try == "no block") and
+ ((bg_try { "block" }) == "block") and
+ ((bg_try do "block" end) == "block")
+end
+
+assert('Kernel#class', '15.3.1.3.7') do
+ Kernel.class == Module
end
assert('Kernel#clone', '15.3.1.3.8') do
@@ -95,8 +151,10 @@ assert('Kernel#clone', '15.3.1.3.8') do
a.set(2)
c = a.clone
- a.get == 2 && b.get == 1 && c.get == 2 &&
- a.respond_to?(:test) == true && b.respond_to?(:test) == false && c.respond_to?(:test) == true
+ a.get == 2 and b.get == 1 and c.get == 2 &&
+ a.respond_to?(:test) == true and
+ b.respond_to?(:test) == false and
+ c.respond_to?(:test) == true
end
assert('Kernel#dup', '15.3.1.3.9') do
@@ -123,14 +181,53 @@ assert('Kernel#dup', '15.3.1.3.9') do
a.set(2)
c = a.dup
- a.get == 2 && b.get == 1 && c.get == 2 &&
- a.respond_to?(:test) == true && b.respond_to?(:test) == false && c.respond_to?(:test) == false
+ a.get == 2 and b.get == 1 and c.get == 2 and
+ a.respond_to?(:test) == true and
+ b.respond_to?(:test) == false and
+ c.respond_to?(:test) == false
+end
+
+assert('Kernel#global_variables', '15.3.1.3.14') do
+ global_variables.class == Array
end
assert('Kernel#hash', '15.3.1.3.15') do
hash == hash
end
+assert('Kernel#inspect', '15.3.1.3.17') do
+ inspect.class == String
+end
+
+assert('Kernel#instance_variables', '15.3.1.3.23') do
+ instance_variables.class == Array
+end
+
+assert('Kernel#is_a?', '15.3.1.3.24') do
+ is_a?(Kernel) and not is_a?(Array)
+end
+
+assert('Kernel#iterator?', '15.3.1.3.25') do
+ iterator? == false
+end
+
+assert('Kernel#kind_of?', '15.3.1.3.26') do
+ kind_of?(Kernel) and not kind_of?(Array)
+end
+
+assert('Kernel#lambda', '15.3.1.3.27') do
+ l = lambda do
+ true
+ end
+
+ l.call and l.class == Proc
+end
+
+# Not implemented yet
+#assert('Kernel#local_variables', '15.3.1.3.28') do
+# local_variables.class == Array
+#end
+
assert('Kernel#loop', '15.3.1.3.29') do
i = 0
@@ -150,6 +247,10 @@ assert('Kernel#nil?', '15.3.1.3.32') do
nil.nil? == true
end
+assert('Kernel#object_id', '15.3.1.3.33') do
+ object_id.class == Fixnum
+end
+
assert('Kernel#private_methods', '15.3.1.3.36') do
private_methods.class == Array
end
@@ -162,6 +263,27 @@ assert('Kernel#public_methods', '15.3.1.3.38') do
public_methods.class == Array
end
+assert('Kernel#raise', '15.3.1.3.40') do
+ e_list = []
+
+ begin
+ raise
+ rescue => e
+ e_list << e
+ end
+
+ begin
+ raise RuntimeError.new
+ rescue => e
+ e_list << e
+ end
+
+ # result without argument
+ e_list[0].class == RuntimeError and
+ # result with RuntimeError argument
+ e_list[1].class == RuntimeError
+end
+
assert('Kernel#respond_to?', '15.3.1.3.43') do
respond_to? :nil?
end
@@ -171,6 +293,7 @@ assert('Kernel#send', '15.3.1.3.44') do
l = send(:lambda) do
true
end
+
l.call and l.class == Proc and
# test with argument
send(:respond_to?, :nil?) and