From d1b131e2b085e180fd6f59dd8016cd06361f93b2 Mon Sep 17 00:00:00 2001 From: Masaki Muranaka Date: Sat, 6 Apr 2013 18:22:42 +0900 Subject: Add some tests. --- test/t/comparable.rb | 15 +++++++++++++++ test/t/kernel.rb | 23 ++++++++++++++++++++++- test/t/module.rb | 23 +++++++++++++++++++++++ 3 files changed, 60 insertions(+), 1 deletion(-) diff --git a/test/t/comparable.rb b/test/t/comparable.rb index c95134246..ab81fa3ed 100644 --- a/test/t/comparable.rb +++ b/test/t/comparable.rb @@ -54,3 +54,18 @@ assert('Comparable#>=', '15.3.3.2.5') do (Foo.new >= Foo.new) == true end +assert('Comparable#between?', '15.3.3.2.6') do + class Foo + include Comparable + def <=>(x) + x + end + end + + c = Foo.new + c.between?(-1, 1) == false && + c.between?(-1, -1) == false && + c.between?( 1, 1) == false && + c.between?( 1, -1) == true && + c.between?(0, 0) == true +end diff --git a/test/t/kernel.rb b/test/t/kernel.rb index 835834359..40f73250b 100644 --- a/test/t/kernel.rb +++ b/test/t/kernel.rb @@ -155,6 +155,16 @@ assert('Kernel#clone', '15.3.1.3.8') do a.set(2) c = a.clone + immutables = [ 1, :foo, true, false, nil ] + error_count = 0 + immutables.each do |i| + begin + i.clone + rescue TypeError + error_count += 1 + end + end + a.get == 2 and b.get == 1 and c.get == 2 && a.respond_to?(:test) == true and b.respond_to?(:test) == false and @@ -185,7 +195,18 @@ assert('Kernel#dup', '15.3.1.3.9') do a.set(2) c = a.dup - a.get == 2 and b.get == 1 and c.get == 2 and + immutables = [ 1, :foo, true, false, nil ] + error_count = 0 + immutables.each do |i| + begin + i.dup + rescue TypeError + error_count += 1 + end + end + + error_count == immutables.size and + 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 diff --git a/test/t/module.rb b/test/t/module.rb index 1ff9d3aea..4b689ea5b 100644 --- a/test/t/module.rb +++ b/test/t/module.rb @@ -297,6 +297,29 @@ assert('Module#remove_method', '15.2.2.4.41') do not Test4RemoveMethod::Child.instance_methods(false).include? :hello end +assert('Module.undef_method', '15.2.2.4.42') do + module Test4UndefMethod + class Parent + def hello + end + end + + class Child < Parent + def hello + end + end + + class GrandChild < Child + end + end + + Test4UndefMethod::Child.class_eval{ undef_method :hello } + + Test4UndefMethod::Parent.new.respond_to?(:hello) and + not Test4UndefMethod::Child.new.respond_to?(:hello) and + not Test4UndefMethod::GrandChild.new.respond_to?(:hello) +end + # Not ISO specified -- cgit v1.2.3 From 91db2904124c66ee44499a6f93ceb2e56a99642c Mon Sep 17 00:00:00 2001 From: Masaki Muranaka Date: Sat, 6 Apr 2013 18:24:42 +0900 Subject: Add a comment. Kernel#require is defined in the mrbgem. --- test/t/kernel.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/t/kernel.rb b/test/t/kernel.rb index 40f73250b..abc8f260b 100644 --- a/test/t/kernel.rb +++ b/test/t/kernel.rb @@ -351,6 +351,8 @@ assert('Kernel#raise', '15.3.1.3.40') do e_list[1].class == RuntimeError end +# Kernel#require is defined in mruby-require. '15.3.1.3.42' + assert('Kernel#respond_to?', '15.3.1.3.43') do class Test4RespondTo def test_method; end -- cgit v1.2.3 From 2c0f2eb9f83bbba0c55cdf01479ee08a0eee4c40 Mon Sep 17 00:00:00 2001 From: Masaki Muranaka Date: Sun, 7 Apr 2013 12:51:13 +0900 Subject: Add ARGV constant. It is not required by ISO. Compatibility with CRuby. --- tools/mirb/mirb.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/mirb/mirb.c b/tools/mirb/mirb.c index ba400bf95..334f9359c 100644 --- a/tools/mirb/mirb.c +++ b/tools/mirb/mirb.c @@ -10,6 +10,7 @@ #include #include +#include "mruby/array.h" #include #include #include @@ -236,6 +237,7 @@ main(int argc, char **argv) fputs("Invalid mrb interpreter, exiting mirb\n", stderr); return EXIT_FAILURE; } + mrb_define_global_const(mrb, "ARGV", mrb_ary_new_capa(mrb, 0)); n = parse_args(mrb, argc, argv, &args); if (n == EXIT_FAILURE) { -- cgit v1.2.3 From 22f50fe32e0f86ef8bbcde733163fefed21059d4 Mon Sep 17 00:00:00 2001 From: h2so5 Date: Mon, 8 Apr 2013 23:38:01 +0900 Subject: Fix a memory leak in mirb --- tools/mirb/mirb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/mirb/mirb.c b/tools/mirb/mirb.c index 044d95faa..4872c474a 100644 --- a/tools/mirb/mirb.c +++ b/tools/mirb/mirb.c @@ -337,9 +337,9 @@ main(int argc, char **argv) } ruby_code[0] = '\0'; last_code_line[0] = '\0'; - mrb_parser_free(parser); mrb_gc_arena_restore(mrb, ai); } + mrb_parser_free(parser); } mrbc_context_free(mrb, cxt); mrb_close(mrb); -- cgit v1.2.3