From cb10b927836fcc56fc40e677497cc303e79625c5 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Sat, 2 Jun 2012 01:33:04 +0800 Subject: Add Test Case for issue #210 --- test/t/module.rb | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'test') diff --git a/test/t/module.rb b/test/t/module.rb index 854be75a5..a5331e96d 100644 --- a/test/t/module.rb +++ b/test/t/module.rb @@ -5,6 +5,53 @@ assert('Module', '15.2.2') do Module.class == Class end +assert('Module#const_defined?', '15.2.2.4.20') do + module Test4ConstDefined + Const4Test4ConstDefined = true + end + + Test4ConstDefined.const_defined?(:Const4Test4ConstDefined) and + not Test4ConstDefined.const_defined?(:NotExisting) +end + +assert('Module#const_get', '15.2.2.4.21') do + module Test4ConstGet + Const4Test4ConstGet = 42 + end + + Test4ConstGet.const_get(:Const4Test4ConstGet) == 42 +end + +assert('Module.const_missing', '15.2.2.4.22') do + e1 = nil + + module Test4ConstMissing + def const_missing(sym) + # ATM this redirect doesn't work + puts "PLEASE GO TO TEST CASE Module.const_missing!" + puts "IT IS WORKING NOW!! PLEASE FINALIZE." + puts "Thanks :)" + end + end + + begin + Test4ConstMissing.const_get(:ConstDoesntExist) + rescue => e2 + e1 = e2 + end + + e1.class == NameError +end + +assert('Module#const_get', '15.2.2.4.23') do + module Test4ConstSet + Const4Test4ConstSet = 42 + end + + Test4ConstSet.const_set(:Const4Test4ConstSet, 23) + Test4ConstSet.const_get(:Const4Test4ConstSet) == 23 +end + # TODO not implemented ATM assert('Module.constants', '15.2.2') do # TODO not implemented ATM assert('Module.nesting', '15.2.2') do -- cgit v1.2.3 From 8804c7db6585d7cf3eda735f4758007704f237af Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Sat, 2 Jun 2012 01:39:53 +0800 Subject: Add Test Case for issue #211 --- test/t/kernel.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/t/kernel.rb b/test/t/kernel.rb index cd1f2d99e..847f1baeb 100644 --- a/test/t/kernel.rb +++ b/test/t/kernel.rb @@ -112,7 +112,17 @@ assert('Kernel#respond_to?', '15.3.1.2.43') do respond_to? :nil? end -# TODO at the moment doesn't comply to ISO assert('Kernel#send', '15.3.1.2.44') do +assert('Kernel#send', '15.3.1.2.44') 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#singleton_methods', '15.3.1.2.45') do singleton_methods.class == Array -- cgit v1.2.3 From 6ec149c4e3da3b991a860250b32ca79775639592 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Sat, 2 Jun 2012 16:44:16 +0800 Subject: Add string test for string interpolation --- test/t/string.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'test') diff --git a/test/t/string.rb b/test/t/string.rb index f38790c17..ee969a696 100644 --- a/test/t/string.rb +++ b/test/t/string.rb @@ -319,3 +319,11 @@ assert('String#upcase!', '15.2.10.5.43') do a == 'ABC' end + +# Not ISO specified + +assert('String interpolation (mrb_str_concat for shared strings)') do + a = "A" * 32 + "#{a}:" == "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA:" +end + -- cgit v1.2.3 From 2c58690df132a462619d62f85963cc5a330a1378 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Sat, 2 Jun 2012 23:39:00 +0800 Subject: Add test cases for Hash --- test/t/hash.rb | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'test') diff --git a/test/t/hash.rb b/test/t/hash.rb index af662688a..df21dd1fa 100644 --- a/test/t/hash.rb +++ b/test/t/hash.rb @@ -224,3 +224,42 @@ assert('Hash#values', '15.2.13.4.28') do a.values == ['abc_value'] end + +# Not ISO specified + +assert('Hash#reject') do + h = {:one => 1, :two => 2, :three => 3, :four => 4} + ret = h.reject do |k,v| + v % 2 == 0 + end + ret == {:one => 1, :three => 3} and + h == {:one => 1, :two => 2, :three => 3, :four => 4} +end + +assert('Hash#reject!') do + h = {:one => 1, :two => 2, :three => 3, :four => 4} + ret = h.reject! do |k,v| + v % 2 == 0 + end + ret == {:one => 1, :three => 3} and + h == {:one => 1, :three => 3} +end + +assert('Hash#select') do + h = {:one => 1, :two => 2, :three => 3, :four => 4} + ret = h.select do |k,v| + v % 2 == 0 + end + ret == {:two => 2, :four => 4} and + h == {:one => 1, :two => 2, :three => 3, :four => 4} +end + +assert('Hash#select!') do + h = {:one => 1, :two => 2, :three => 3, :four => 4} + ret = h.select! do |k,v| + v % 2 == 0 + end + ret == {:two => 2, :four => 4} and + h == {:two => 2, :four => 4} +end + -- cgit v1.2.3 From 57bd8d49ec88c7f6a0432a09168af9420ae50c7e Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Sun, 3 Jun 2012 01:50:10 +0800 Subject: Add first test case for Class#new and prepare further feature tests for it --- test/t/class.rb | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'test') diff --git a/test/t/class.rb b/test/t/class.rb index 92f3df51d..3c398e923 100644 --- a/test/t/class.rb +++ b/test/t/class.rb @@ -5,6 +5,36 @@ assert('Class', '15.2.3') do Class.class == Class end +assert('Class#new', '15.2.3.3.3') do + # at the moment no exception on singleton class + #e1 = nil + #begin + # class1 = e1.singleton_class.new + #rescue => e1 + # e2 = e1 + #end + + class TestClass + def initialize args, &block + @result = if not args.nil? and block.nil? + # only arguments + :only_args + elsif not args.nil? and not block.nil? + # args and block is given + :args_and_block + else + # this should never happen + :broken + end + end + + def result; @result; end + end + + TestClass.new(:arg).result == :only_args + # with block doesn't work yet +end + # Not ISO specified assert('Class 1') do -- cgit v1.2.3 From df80b7835a5d99e2f5a25446abb53ea3e68e7709 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Sun, 3 Jun 2012 08:20:48 +0900 Subject: Add Class#superclass; a patch made by @bovi; close #234 --- src/class.c | 10 ++++++++++ test/t/class.rb | 5 +++++ 2 files changed, 15 insertions(+) (limited to 'test') diff --git a/src/class.c b/src/class.c index 544f36527..748996e62 100644 --- a/src/class.c +++ b/src/class.c @@ -819,6 +819,15 @@ mrb_class_new_class(mrb_state *mrb, mrb_value cv) return mrb_obj_value(new_class); } +mrb_value +mrb_class_superclass(mrb_state *mrb, mrb_value klass) +{ + struct RClass *c, *s; + c = mrb_class_ptr(klass); + s = c->super; + return mrb_obj_value(s); +} + static mrb_value mrb_bob_init(mrb_state *mrb, mrb_value cv) { @@ -1240,6 +1249,7 @@ mrb_init_class(mrb_state *mrb) mrb_define_method(mrb, bob, "!", mrb_bob_not, ARGS_NONE()); mrb_define_method(mrb, bob, "method_missing", mrb_bob_missing, ARGS_ANY()); /* 15.3.1.3.30 */ mrb_define_class_method(mrb, cls, "new", mrb_class_new_class, ARGS_ANY()); + mrb_define_method(mrb, cls, "superclass", mrb_class_superclass, ARGS_NONE()); mrb_define_method(mrb, cls, "new", mrb_instance_new, ARGS_ANY()); mrb_define_method(mrb, cls, "inherited", mrb_bob_init, ARGS_REQ(1)); mrb_define_method(mrb, mod, "include", mrb_mod_include, ARGS_REQ(1)); diff --git a/test/t/class.rb b/test/t/class.rb index 92f3df51d..cb056feff 100644 --- a/test/t/class.rb +++ b/test/t/class.rb @@ -5,6 +5,11 @@ 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 +end + # Not ISO specified assert('Class 1') do -- cgit v1.2.3 From 0629cf21baefd83765206036e4ceac45f7a55ca4 Mon Sep 17 00:00:00 2001 From: Kazuki Tsujimoto Date: Sun, 3 Jun 2012 17:48:02 +0900 Subject: A rescue clause with no parameter list rescues only StandardErrors --- src/codegen.c | 38 ++++++++++++++++++++++---------------- test/t/exception.rb | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 16 deletions(-) (limited to 'test') diff --git a/src/codegen.c b/src/codegen.c index 20799f9ae..117588b6e 100644 --- a/src/codegen.c +++ b/src/codegen.c @@ -834,28 +834,34 @@ codegen(codegen_scope *s, node *tree, int val) push(); while (n2) { node *n3 = n2->car; + node *n4 = n3->car; if (pos1) dispatch(s, pos1); - if (n3->car) { - node *n4 = n3->car; - - pos2 = 0; - while (n4) { + pos2 = 0; + do { + if (n4) { codegen(s, n4->car, VAL); - genop(s, MKOP_AB(OP_MOVE, cursp(), exc)); + } + else { + genop(s, MKOP_ABx(OP_GETCONST, cursp(), new_msym(s, mrb_intern(s->mrb, "StandardError")))); push(); - genop(s, MKOP_A(OP_LOADNIL, cursp())); - pop(); pop(); - genop(s, MKOP_ABC(OP_SEND, cursp(), new_msym(s, mrb_intern(s->mrb, "===")), 1)); - tmp = new_label(s); - genop(s, MKOP_AsBx(OP_JMPIF, cursp(), pos2)); - pos2 = tmp; + } + genop(s, MKOP_AB(OP_MOVE, cursp(), exc)); + push(); + genop(s, MKOP_A(OP_LOADNIL, cursp())); + pop(); pop(); + genop(s, MKOP_ABC(OP_SEND, cursp(), new_msym(s, mrb_intern(s->mrb, "===")), 1)); + tmp = new_label(s); + genop(s, MKOP_AsBx(OP_JMPIF, cursp(), pos2)); + pos2 = tmp; + if (n4) { n4 = n4->cdr; } - pos1 = new_label(s); - genop(s, MKOP_Bx(OP_JMP, 0)); - dispatch_linked(s, pos2); - } + } while (n4); + pos1 = new_label(s); + genop(s, MKOP_Bx(OP_JMP, 0)); + dispatch_linked(s, pos2); + pop(); if (n3->cdr->car) { gen_assignment(s, n3->cdr->car, exc, NOVAL); diff --git a/test/t/exception.rb b/test/t/exception.rb index 6b46314d0..d68ed8bd7 100644 --- a/test/t/exception.rb +++ b/test/t/exception.rb @@ -193,3 +193,39 @@ assert('Exception 10') do 7+7 end == 12 end + +assert('Exception 11') do + a = :ok + begin + begin + raise Exception + rescue + a = :ng + end + rescue Exception + end + a == :ok +end + +assert('Exception 12') do + a = :ok + begin + raise Exception rescue a = :ng + rescue Exception + end + a == :ok +end + +assert('Exception 13') do + a = :ng + begin + raise StandardError + rescue TypeError, ArgumentError + a = :ng + rescue + a = :ok + else + a = :ng + end + a == :ok +end -- cgit v1.2.3 From 2fff59dc8674ad6689acc5080463eede4c5bb2ab Mon Sep 17 00:00:00 2001 From: Jon Date: Sun, 3 Jun 2012 10:04:51 -0400 Subject: Check mrb_open return value for NULL --- src/codegen.c | 5 +++++ src/gc.c | 40 ++++++++++++++++++++++++++++++++++++++++ src/parse.y | 5 +++++ test/driver.c | 5 +++++ tools/mirb/mirb.c | 5 +++++ tools/mrbc/mrbc.c | 5 +++++ tools/mruby/mruby.c | 5 +++++ 7 files changed, 70 insertions(+) (limited to 'test') diff --git a/src/codegen.c b/src/codegen.c index 117588b6e..027b6777f 100644 --- a/src/codegen.c +++ b/src/codegen.c @@ -2292,6 +2292,11 @@ main() mrb_state *mrb = mrb_open(); int n; + if (mrb == NULL) { + fprintf(stderr, "Invalid mrb_state, exiting codegen test"); + return EXIT_FAILURE; + } + #if 1 n = mrb_compile_string(mrb, "p(__FILE__)\np(__LINE__)"); #else diff --git a/src/gc.c b/src/gc.c index b7c08de65..64a92d11e 100644 --- a/src/gc.c +++ b/src/gc.c @@ -934,6 +934,11 @@ test_mrb_field_write_barrier(void) mrb_state *mrb = mrb_open(); struct RBasic *obj, *value; + if (mrb == NULL) { + fprintf(stderr, "Invalid mrb_state, exiting test_mrb_field_write_barrier"); + return; + } + puts("test_mrb_field_write_barrier"); obj = RBASIC(mrb_ary_new(mrb)); value = RBASIC(mrb_str_new_cstr(mrb, "value")); @@ -997,6 +1002,11 @@ test_mrb_write_barrier(void) mrb_state *mrb = mrb_open(); struct RBasic *obj; + if (mrb == NULL) { + fprintf(stderr, "Invalid mrb_state, exiting test_mrb_write_barrier"); + return; + } + puts("test_mrb_write_barrier"); obj = RBASIC(mrb_ary_new(mrb)); paint_black(obj); @@ -1024,6 +1034,11 @@ test_add_gray_list(void) mrb_state *mrb = mrb_open(); struct RBasic *obj1, *obj2; + if (mrb == NULL) { + fprintf(stderr, "Invalid mrb_state, exiting test_add_gray_list"); + return; + } + puts("test_add_gray_list"); gc_assert(mrb->gray_list == NULL); obj1 = RBASIC(mrb_str_new_cstr(mrb, "test")); @@ -1048,6 +1063,11 @@ test_gc_gray_mark(void) struct RBasic *obj; size_t gray_num = 0; + if (mrb == NULL) { + fprintf(stderr, "Invalid mrb_state, exiting test_gc_gray_mark"); + return; + } + puts("test_gc_gray_mark"); puts(" in MRB_TT_CLASS"); @@ -1079,6 +1099,11 @@ test_incremental_gc(void) RVALUE *free; struct heap_page *page; + if (mrb == NULL) { + fprintf(stderr, "Invalid mrb_state, exiting test_incremental_gc"); + return; + } + puts("test_incremental_gc"); mrb_garbage_collect(mrb); @@ -1135,6 +1160,11 @@ test_incremental_sweep_phase(void) { mrb_state *mrb = mrb_open(); + if (mrb == NULL) { + fprintf(stderr, "Invalid mrb_state, exiting test_incremental_sweep_phase"); + return; + } + puts("test_incremental_sweep_phase"); add_heap(mrb); @@ -1158,6 +1188,11 @@ test_gc_api(void) mrb_value argv[1]; + if (mrb == NULL) { + fprintf(stderr, "Invalid mrb_state, exiting test_gc_api"); + return; + } + puts("test_gc_api"); gc_start(mrb, mrb_nil_value()); @@ -1191,6 +1226,11 @@ test_many_object_benchmark(void) mrb_value ary = mrb_ary_new(mrb); int save_point = mrb_gc_arena_save(mrb); + if (mrb == NULL) { + fprintf(stderr, "Invalid mrb_state, test_many_object_benchmark"); + return; + } + puts("test_many_object_benchmark"); for (i=0; i<1000; i++) { diff --git a/src/parse.y b/src/parse.y index eae9fb373..884290961 100644 --- a/src/parse.y +++ b/src/parse.y @@ -5518,6 +5518,11 @@ main() mrb_state *mrb = mrb_open(); int n; + if (mrb == NULL) { + fprintf(stderr, "Invalid mrb_state, exiting parser test"); + return EXIT_FAILURE; + } + n = mrb_compile_string(mrb, "\ def fib(n)\n\ if n<2\n\ diff --git a/test/driver.c b/test/driver.c index 4651d75fc..6b42d025b 100644 --- a/test/driver.c +++ b/test/driver.c @@ -36,6 +36,11 @@ main(void) /* new interpreter instance */ mrb = mrb_open(); + if (mrb == NULL) { + fprintf(stderr, "Invalid mrb_state, exiting test driver"); + return EXIT_FAILURE; + } + mrb_init_mrbtest(mrb); parser = mrb_parse_nstring(mrb, prog, strlen(prog)); diff --git a/tools/mirb/mirb.c b/tools/mirb/mirb.c index 59e5046cb..35558acfb 100644 --- a/tools/mirb/mirb.c +++ b/tools/mirb/mirb.c @@ -142,6 +142,11 @@ main(void) /* new interpreter instance */ mrb_interpreter = mrb_open(); + if (mrb_interpreter == NULL) { + fprintf(stderr, "Invalid mrb_interpreter, exiting mirb"); + return EXIT_FAILURE; + } + /* new parser instance */ parser = mrb_parser_new(mrb_interpreter); memset(ruby_code, 0, sizeof(*ruby_code)); diff --git a/tools/mrbc/mrbc.c b/tools/mrbc/mrbc.c index 3553fe646..99fea76d8 100644 --- a/tools/mrbc/mrbc.c +++ b/tools/mrbc/mrbc.c @@ -158,6 +158,11 @@ main(int argc, char **argv) struct _args args; struct mrb_parser_state *p; + if (mrb == NULL) { + fprintf(stderr, "Invalid mrb_state, exiting mrbc"); + return EXIT_FAILURE; + } + n = parse_args(mrb, argc, argv, &args); if (n < 0 || args.rfp == NULL) { diff --git a/tools/mruby/mruby.c b/tools/mruby/mruby.c index 8b227df5d..0e38879db 100644 --- a/tools/mruby/mruby.c +++ b/tools/mruby/mruby.c @@ -142,6 +142,11 @@ main(int argc, char **argv) struct _args args; struct mrb_parser_state *p; + if (mrb == NULL) { + fprintf(stderr, "Invalid mrb_state, exiting mruby"); + return EXIT_FAILURE; + } + n = parse_args(mrb, argc, argv, &args); if (n < 0 || (args.cmdline == NULL && args.rfp == NULL)) { cleanup(mrb, &args); -- cgit v1.2.3 From 5612d195ec39612b7216ff3f28d05ed089452767 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Sun, 3 Jun 2012 23:29:40 +0800 Subject: Improve Class#superclass to ISO --- src/class.c | 12 +++++++++--- test/t/class.rb | 10 +++++++--- 2 files changed, 16 insertions(+), 6 deletions(-) (limited to 'test') diff --git a/src/class.c b/src/class.c index c689552f5..594ed08bc 100644 --- a/src/class.c +++ b/src/class.c @@ -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 diff --git a/test/t/class.rb b/test/t/class.rb index d252cf590..1b809a832 100644 --- a/test/t/class.rb +++ b/test/t/class.rb @@ -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 -- cgit v1.2.3 From 00caf25b523b9ab6858e704f26f9b4bb20639a8e Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Sun, 3 Jun 2012 23:30:15 +0800 Subject: Add BasicObject Tests --- test/t/basicobject.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 test/t/basicobject.rb (limited to 'test') diff --git a/test/t/basicobject.rb b/test/t/basicobject.rb new file mode 100644 index 000000000..f7e95af89 --- /dev/null +++ b/test/t/basicobject.rb @@ -0,0 +1,11 @@ +## +# BasicObject + +assert('BasicObject') do + BasicObject.class == Class +end + +assert('BasicObject superclass') do + BasicObject.superclass == nil +end + -- cgit v1.2.3 From c78dc2930c6b8c927e6c1415ecbc13e727c3637c Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Sun, 3 Jun 2012 23:31:17 +0800 Subject: Add superclass tests for Exceptions --- test/t/argumenterror.rb | 5 +++++ test/t/exception.rb | 4 ++++ test/t/indexerror.rb | 5 +++++ test/t/nameerror.rb | 4 ++++ test/t/nomethoderror.rb | 5 +++++ test/t/rangeerror.rb | 5 +++++ test/t/standarderror.rb | 5 +++++ test/t/typeerror.rb | 5 +++++ 8 files changed, 38 insertions(+) (limited to 'test') diff --git a/test/t/argumenterror.rb b/test/t/argumenterror.rb index ca998f8de..71cf38e26 100644 --- a/test/t/argumenterror.rb +++ b/test/t/argumenterror.rb @@ -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 + diff --git a/test/t/exception.rb b/test/t/exception.rb index d68ed8bd7..22795161f 100644 --- a/test/t/exception.rb +++ b/test/t/exception.rb @@ -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') diff --git a/test/t/indexerror.rb b/test/t/indexerror.rb index d0cb81f32..d7c8ba148 100644 --- a/test/t/indexerror.rb +++ b/test/t/indexerror.rb @@ -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 + diff --git a/test/t/nameerror.rb b/test/t/nameerror.rb index 67451ecf8..8e57ac18b 100644 --- a/test/t/nameerror.rb +++ b/test/t/nameerror.rb @@ -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 diff --git a/test/t/nomethoderror.rb b/test/t/nomethoderror.rb index 9eb122158..caab04a41 100644 --- a/test/t/nomethoderror.rb +++ b/test/t/nomethoderror.rb @@ -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 + diff --git a/test/t/rangeerror.rb b/test/t/rangeerror.rb index 7edb5d2d9..57afdc4bd 100644 --- a/test/t/rangeerror.rb +++ b/test/t/rangeerror.rb @@ -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 + diff --git a/test/t/standarderror.rb b/test/t/standarderror.rb index 550c337c1..3868d7567 100644 --- a/test/t/standarderror.rb +++ b/test/t/standarderror.rb @@ -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 + diff --git a/test/t/typeerror.rb b/test/t/typeerror.rb index c4434aa24..d48db111a 100644 --- a/test/t/typeerror.rb +++ b/test/t/typeerror.rb @@ -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 + -- cgit v1.2.3 From 0c2d74020a925fa86235ae7c716aa0ede856e6e6 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Sun, 3 Jun 2012 23:31:53 +0800 Subject: Add more superclass tests --- test/t/array.rb | 4 ++++ test/t/false.rb | 4 ++++ test/t/float.rb | 4 ++++ test/t/hash.rb | 4 ++++ test/t/integer.rb | 4 ++++ test/t/module.rb | 4 ++++ test/t/numeric.rb | 4 ++++ test/t/object.rb | 5 +++++ test/t/proc.rb | 4 ++++ test/t/range.rb | 4 ++++ test/t/string.rb | 4 ++++ test/t/struct.rb | 5 +++++ test/t/symbol.rb | 4 ++++ test/t/time.rb | 4 ++++ test/t/true.rb | 4 ++++ 15 files changed, 62 insertions(+) (limited to 'test') diff --git a/test/t/array.rb b/test/t/array.rb index dba1b035d..4e53f1120 100644 --- a/test/t/array.rb +++ b/test/t/array.rb @@ -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 diff --git a/test/t/false.rb b/test/t/false.rb index c2db283c8..ae605205d 100644 --- a/test/t/false.rb +++ b/test/t/false.rb @@ -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 diff --git a/test/t/float.rb b/test/t/float.rb index fc87a5b22..5c5245c73 100644 --- a/test/t/float.rb +++ b/test/t/float.rb @@ -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 diff --git a/test/t/hash.rb b/test/t/hash.rb index df21dd1fa..04a9a1c24 100644 --- a/test/t/hash.rb +++ b/test/t/hash.rb @@ -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' }) diff --git a/test/t/integer.rb b/test/t/integer.rb index 8c112861a..872723445 100644 --- a/test/t/integer.rb +++ b/test/t/integer.rb @@ -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 diff --git a/test/t/module.rb b/test/t/module.rb index a5331e96d..95fbb7a86 100644 --- a/test/t/module.rb +++ b/test/t/module.rb @@ -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 diff --git a/test/t/numeric.rb b/test/t/numeric.rb index 924889a0e..3cdb9a8cf 100644 --- a/test/t/numeric.rb +++ b/test/t/numeric.rb @@ -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 diff --git a/test/t/object.rb b/test/t/object.rb index 96929031b..7dfaf6589 100644 --- a/test/t/object.rb +++ b/test/t/object.rb @@ -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 + diff --git a/test/t/proc.rb b/test/t/proc.rb index 6d98cb40c..c0a1cf90f 100644 --- a/test/t/proc.rb +++ b/test/t/proc.rb @@ -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 diff --git a/test/t/range.rb b/test/t/range.rb index 05bac8779..691ca7898 100644 --- a/test/t/range.rb +++ b/test/t/range.rb @@ -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 diff --git a/test/t/string.rb b/test/t/string.rb index ee969a696..964ec0e63 100644 --- a/test/t/string.rb +++ b/test/t/string.rb @@ -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 diff --git a/test/t/struct.rb b/test/t/struct.rb index c41319f8a..798cf6728 100644 --- a/test/t/struct.rb +++ b/test/t/struct.rb @@ -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 + diff --git a/test/t/symbol.rb b/test/t/symbol.rb index e9c310971..b28573e92 100644 --- a/test/t/symbol.rb +++ b/test/t/symbol.rb @@ -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 diff --git a/test/t/time.rb b/test/t/time.rb index 22fc2e7c3..7d1519f63 100644 --- a/test/t/time.rb +++ b/test/t/time.rb @@ -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 diff --git a/test/t/true.rb b/test/t/true.rb index bb648a7cd..2662f7cd8 100644 --- a/test/t/true.rb +++ b/test/t/true.rb @@ -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 -- cgit v1.2.3 From db6c374301421245ef4746f71891ec03509a4085 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Tue, 5 Jun 2012 03:11:56 +0800 Subject: Add Time tests --- test/t/time.rb | 126 +++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 119 insertions(+), 7 deletions(-) (limited to 'test') diff --git a/test/t/time.rb b/test/t/time.rb index 7d1519f63..045c5b185 100644 --- a/test/t/time.rb +++ b/test/t/time.rb @@ -1,6 +1,10 @@ ## # Time ISO Test +assert('Time.new', '15.2.3.3.3') do + Time.new.class == Time +end + assert('Time', '15.2.19') do Time.class == Class end @@ -17,23 +21,133 @@ assert('Time.gm', '15.2.19.6.2') do Time.gm(2012, 12, 23) end +assert('Time.local', '15.2.19.6.3') do + Time.local(2012, 12, 23) +end + +assert('Time.mktime', '15.2.19.6.4') do + Time.mktime(2012, 12, 23) +end + +assert('Time.now', '15.2.19.6.5') do + Time.now.class == Time +end + +assert('Time.utc', '15.2.19.6.6') do + Time.utc(2012, 12, 23) +end + +assert('Time#+', '15.2.19.7.1') do + t1 = Time.at(1300000000.0) + t2 = t1.+(60) + + t2.utc.asctime == "Sun Mar 13 07:07:40 UTC 2011" +end + +assert('Time#-', '15.2.19.7.2') do + t1 = Time.at(1300000000.0) + t2 = t1.-(60) + + t2.utc.asctime == "Sun Mar 13 07:05:40 UTC 2011" +end + +assert('Time#<=>', '15.2.19.7.3') do + t1 = Time.at(1300000000.0) + t2 = Time.at(1400000000.0) + t3 = Time.at(1500000000.0) + + t2.<=>(t1) == 1 and + t2.<=>(t2) == 0 and + t2.<=>(t3) == -1 and + t2.<=>(nil) == nil +end + assert('Time#asctime', '15.2.19.7.4') do Time.at(1300000000.0).utc.asctime == "Sun Mar 13 07:06:40 UTC 2011" end +assert('Time#ctime', '15.2.19.7.5') do + Time.at(1300000000.0).utc.ctime == "Sun Mar 13 07:06:40 UTC 2011" +end + +assert('Time#day', '15.2.19.7.6') do + Time.gm(2012, 12, 23).day == 23 +end + +assert('Time#dst?', '15.2.19.7.7') do + not Time.gm(2012, 12, 23).utc.dst? +end + +assert('Time#getgm', '15.2.19.7.8') do + Time.at(1300000000.0).getgm.asctime == "Sun Mar 13 07:06:40 UTC 2011" +end + +assert('Time#getlocal', '15.2.19.7.9') do + t1 = Time.at(1300000000.0) + t2 = Time.at(1300000000.0) + t3 = t1.getlocal + + t1 == t3 and t3 == t2.getlocal +end + +assert('Time#getutc', '15.2.19.7.10') do + Time.at(1300000000.0).getutc.asctime == "Sun Mar 13 07:06:40 UTC 2011" +end + +assert('Time#gmt?', '15.2.19.7.11') do + Time.at(1300000000.0).utc.gmt? +end + +# ATM not implemented +# assert('Time#gmt_offset', '15.2.19.7.12') do + +assert('Time#gmtime', '15.2.19.7.13') do + Time.at(1300000000.0).gmtime +end + +# ATM not implemented +# assert('Time#gmtoff', '15.2.19.7.14') do + +assert('Time#hour', '15.2.19.7.15') do + Time.gm(2012, 12, 23, 7, 6).hour == 7 +end + +# ATM doesn't really work +# assert('Time#initialize', '15.2.19.7.16') do + assert('Time#initialize_copy', '15.2.19.7.17') do time_tmp_2 = Time.at(7.0e6) time_tmp_2.clone == time_tmp_2 end +assert('Time#localtime', '15.2.19.7.18') do + t1 = Time.at(1300000000.0) + t2 = Time.at(1300000000.0) + + t1.localtime + t1 == t2.getlocal +end + assert('Time#mday', '15.2.19.7.19') do Time.gm(2012, 12, 23).mday == 23 end +assert('Time#min', '15.2.19.7.20') do + Time.gm(2012, 12, 23, 7, 6).min == 6 +end + +assert('Time#mon', '15.2.19.7.21') do + Time.gm(2012, 12, 23).mon == 12 +end + assert('Time#month', '15.2.19.7.22') do Time.gm(2012, 12, 23).month == 12 end +assert('Times#sec', '15.2.19.7.23') do + Time.gm(2012, 12, 23, 7, 6, 40).sec == 40 +end + assert('Time#to_f', '15.2.19.7.24') do Time.at(1300000000.0).to_f == 1300000000.0 end @@ -54,12 +168,15 @@ assert('Time#utc?', '15.2.19.7.28') do Time.at(1300000000.0).utc.utc? end +# ATM not implemented +# assert('Time#utc_offset', '15.2.19.7.29') do + assert('Time#wday', '15.2.19.7.30') do - Time.at(1300000000.0).utc.wday == 0 + Time.gm(2012, 12, 23).wday == 0 end assert('Time#yday', '15.2.19.7.31') do - Time.at(1300000000.0).utc.yday == 71 + Time.gm(2012, 12, 23).yday == 357 end assert('Time#year', '15.2.19.7.32') do @@ -70,8 +187,3 @@ assert('Time#zone', '15.2.19.7.33') do Time.at(1300000000.0).utc.zone == 'UTC' end -# Not ISO specified - -assert('Time#new') do - Time.new.class == Time -end -- cgit v1.2.3 From 2c7cee8a1a7886691f5103a4319fca411408b500 Mon Sep 17 00:00:00 2001 From: Paolo Bosetti Date: Mon, 4 Jun 2012 15:56:51 -0700 Subject: Added Math.sqrt() that was missing in math.c, and added relevant test case --- src/math.c | 20 ++++++++++++++++++++ test/t/math.rb | 10 ++++++++++ 2 files changed, 30 insertions(+) (limited to 'test') diff --git a/src/math.c b/src/math.c index b0d911573..eff2edcad 100644 --- a/src/math.c +++ b/src/math.c @@ -463,6 +463,25 @@ math_log10(mrb_state *mrb, mrb_value obj) return mrb_float_value(x); } +/* + * call-seq: + * Math.sqrt(numeric) -> float + * + * Returns the square root of numeric. + * + */ +static mrb_value +math_sqrt(mrb_state *mrb, mrb_value obj) +{ + mrb_float x; + + mrb_get_args(mrb, "f", &x); + x = sqrt(x); + + return mrb_float_value(x); +} + + /* * call-seq: * Math.cbrt(numeric) -> float @@ -646,6 +665,7 @@ mrb_init_math(mrb_state *mrb) mrb_define_module_function(mrb, mrb_math, "log", math_log, -1); mrb_define_module_function(mrb, mrb_math, "log2", math_log2, 1); mrb_define_module_function(mrb, mrb_math, "log10", math_log10, 1); + mrb_define_module_function(mrb, mrb_math, "sqrt", math_sqrt, 1); mrb_define_module_function(mrb, mrb_math, "cbrt", math_cbrt, 1); mrb_define_module_function(mrb, mrb_math, "frexp", math_frexp, 1); diff --git a/test/t/math.rb b/test/t/math.rb index 5b9da4cb3..47a3bf527 100644 --- a/test/t/math.rb +++ b/test/t/math.rb @@ -76,6 +76,16 @@ assert('Math.log10 10**100') do check_float(Math.log10(10**100), 100.0) end +assert('Math.sqrt') do + num = [0.0, 1.0, 2.0, 3.0, 4.0] + sqr = [0, 1, 4, 9, 16] + result = true + sqr.each_with_index do |v,i| + result &= check_float(Math.sqrt(v), num[i]) + end + result +end + assert('Math.cbrt') do num = [-2.0, -1.0, 0.0, 1.0, 2.0] cub = [-8, -1, 0, 1, 8] -- cgit v1.2.3 From 501f7f6027b99416b94f093bb30691c5ae43d7d0 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Tue, 5 Jun 2012 09:09:50 +0900 Subject: stop introducing Math::TORELANCE --- src/math.c | 6 +++--- test/assert.rb | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'test') diff --git a/src/math.c b/src/math.c index eff2edcad..63daa58d1 100644 --- a/src/math.c +++ b/src/math.c @@ -10,10 +10,11 @@ #define domain_error(msg) \ mrb_raise(mrb, E_RANGE_ERROR, "Numerical argument is out of domain - " #msg); -#define MATH_TOLERANCE 1E-12 - /* math functions not provided under Microsoft Visual C++ */ #ifdef _MSC_VER + +#define MATH_TOLERANCE 1E-12 + #define asinh(x) log(x + sqrt(pow(x,2.0) + 1)) #define acosh(x) log(x + sqrt(pow(x,2.0) - 1)) #define atanh(x) (log(1+x) - log(1-x))/2.0 @@ -631,7 +632,6 @@ mrb_init_math(mrb_state *mrb) struct RClass *mrb_math; mrb_math = mrb_define_module(mrb, "Math"); - mrb_define_const(mrb, mrb_math, "TOLERANCE", mrb_float_value(MATH_TOLERANCE)); #ifdef M_PI mrb_define_const(mrb, mrb_math, "PI", mrb_float_value(M_PI)); #else diff --git a/test/assert.rb b/test/assert.rb index 239730cb9..5cca59187 100644 --- a/test/assert.rb +++ b/test/assert.rb @@ -74,12 +74,12 @@ end # Performs fuzzy check for equality on methods returning floats # on the basis of the Math::TOLERANCE constant. def check_float(a, b) + tolerance = 1e-12 a = a.to_f b = b.to_f if a.finite? and b.finite? - (a-b).abs < Math::TOLERANCE + (a-b).abs < tolerance else true end end - -- cgit v1.2.3 From 46c9260305a7acc7ee2e1bd1d2441b56cee89f3f Mon Sep 17 00:00:00 2001 From: Masamitsu MURASE Date: Mon, 11 Jun 2012 01:39:45 +0900 Subject: Add test for slice of shared string. --- test/t/string.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/t/string.rb b/test/t/string.rb index 964ec0e63..d7182fc38 100644 --- a/test/t/string.rb +++ b/test/t/string.rb @@ -256,6 +256,9 @@ assert('String#slice', '15.2.10.5.34') do d1 = 'abc'.slice(0, 0) e1 = 'abc'.slice(1, 2) + # slice of shared string + e11 = e1.slice(0) + # args is RegExp # TODO SEGFAULT ATM @@ -265,7 +268,7 @@ assert('String#slice', '15.2.10.5.34') do a == 'a' and b == 'c' and c == nil and d == nil and a1 == nil and b1 == nil and c1 == nil and d1 == '' and - e1 == 'bc' and + e1 == 'bc' and e11 == 'b' and a3 == 'bc' and b3 == nil end -- cgit v1.2.3 From 6987ba02f8ea14531d55a8a44f8d68667076ebe8 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Tue, 12 Jun 2012 09:51:10 +0900 Subject: String#split now understands string sep --- src/string.c | 43 ++++++++++++++++++++++++------------------- test/t/string.rb | 4 +++- 2 files changed, 27 insertions(+), 20 deletions(-) (limited to 'test') diff --git a/src/string.c b/src/string.c index 1de0d9592..340402e26 100644 --- a/src/string.c +++ b/src/string.c @@ -2122,27 +2122,16 @@ static const char isspacetable[256] = { static mrb_value mrb_str_split_m(mrb_state *mrb, mrb_value str) { - mrb_value *argv; int argc; mrb_value spat = mrb_nil_value(); - mrb_value limit; enum {awk, string, regexp} split_type = string; long beg, end, i = 0; - int lim = 0; + int lim = -1; mrb_value result, tmp; - mrb_get_args(mrb, "*", &argv, &argc); - if (argc > 0) - spat = argv[0]; - if (argc > 1) - limit = argv[1]; - else - limit = mrb_nil_value(); - + argc = mrb_get_args(mrb, "|oi", &spat, &lim); if (argc == 2) { - lim = mrb_fixnum(limit); - if (lim <= 0) limit = mrb_nil_value(); - else if (lim == 1) { + if (lim == 1) { if (RSTRING_LEN(str) == 0) return mrb_ary_new_capa(mrb, 0); return mrb_ary_new_from_values(mrb, 1, &str); @@ -2201,20 +2190,36 @@ mrb_str_split_m(mrb_state *mrb, mrb_value str) else { end = ptr - bptr; skip = 0; - if (!mrb_nil_p(limit) && lim <= i) break; + if (lim >= 0 && lim <= i) break; } } else if (ascii_isspace(c)) { mrb_ary_push(mrb, result, mrb_str_subseq(mrb, str, beg, end-beg)); skip = 1; beg = ptr - bptr; - if (!mrb_nil_p(limit)) ++i; + if (lim >= 0) ++i; } else { end = ptr - bptr; } } } + else if (split_type == string) { + char *ptr = RSTRING_PTR(str); + char *temp = ptr; + char *eptr = RSTRING_END(str); + char *sptr = RSTRING_PTR(spat); + long slen = RSTRING_LEN(spat); + + while (ptr < eptr && + (end = mrb_memsearch(sptr, slen, ptr, eptr - ptr)) >= 0) { + /* Check we are at the start of a char */ + mrb_ary_push(mrb, result, mrb_str_subseq(mrb, str, ptr - temp, end)); + ptr += end + slen; + if (lim >= 0 && lim <= ++i) break; + } + beg = ptr - temp; + } else { #ifdef INCLUDE_REGEXP char *ptr = RSTRING_PTR(str); @@ -2258,20 +2263,20 @@ mrb_str_split_m(mrb_state *mrb, mrb_value str) tmp = mrb_str_subseq(mrb, str, BEG(idx), END(idx)-BEG(idx)); mrb_ary_push(mrb, result, tmp); } - if (!mrb_nil_p(limit) && lim <= ++i) break; + if (lim >= 0 && lim <= ++i) break; } #else mrb_raise(mrb, E_TYPE_ERROR, "Regexp Class not supported"); #endif //INCLUDE_REGEXP } - if (RSTRING_LEN(str) > 0 && (!mrb_nil_p(limit) || RSTRING_LEN(str) > beg || lim < 0)) { + if (RSTRING_LEN(str) > 0 && (lim >= 0 || RSTRING_LEN(str) > beg || lim < 0)) { if (RSTRING_LEN(str) == beg) tmp = mrb_str_new_empty(mrb, str); else tmp = mrb_str_subseq(mrb, str, beg, RSTRING_LEN(str)-beg); mrb_ary_push(mrb, result, tmp); } - if (mrb_nil_p(limit) && lim == 0) { + if (lim < 0) { long len; while ((len = RARRAY_LEN(result)) > 0 && (tmp = RARRAY_PTR(result)[len-1], RSTRING_LEN(tmp) == 0)) diff --git a/test/t/string.rb b/test/t/string.rb index d7182fc38..718b005a9 100644 --- a/test/t/string.rb +++ b/test/t/string.rb @@ -276,8 +276,10 @@ end assert('String#split', '15.2.10.5.35') do # without RegExp behavior is actually unspecified a = 'abc abc abc'.split + b = 'a,b,c,,d'.split(',') - a == ['abc', 'abc', 'abc'] + a == ['abc', 'abc', 'abc'] and + b == ["a", "b", "c", "", "d"] end # TODO ATM broken assert('String#sub', '15.2.10.5.36') do -- cgit v1.2.3 From 46b098e0799f67915e4deb3bf7bdfb6d4d4bcf2d Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Tue, 12 Jun 2012 12:16:18 +0900 Subject: minor correction in test/t/syntax.rb --- test/t/syntax.rb | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 test/t/syntax.rb (limited to 'test') diff --git a/test/t/syntax.rb b/test/t/syntax.rb new file mode 100644 index 000000000..7898a0b7d --- /dev/null +++ b/test/t/syntax.rb @@ -0,0 +1,47 @@ +assert('super', '11.3.4') do + test = false + begin + super + rescue NoMethodError + test = true + end + + class SuperFoo + def foo + true + end + def bar(*a) + a + end + end + class SuperBar < SuperFoo + def foo + super + end + def bar(*a) + super(*a) + end + end + bar = SuperBar.new + test &&= bar.foo + test &&= (bar.bar(1,2,3) == [1,2,3]) + test +end + +assert('yield', '11.3.5') do + begin + yield + rescue LocalJumpError + true + else + false + end +end + +assert('Abbreviated variable assignment', '11.4.2.3.2') do + a ||= 1 + b &&= 1 + c = 1 + c += 2 + a == 1 and b == nil and c == 3 +end -- cgit v1.2.3 From b32e586099d8a59bd497031f27e9763b028c0bad Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Tue, 12 Jun 2012 12:19:25 +0900 Subject: should enhance test for Array#slice --- test/t/array.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/t/array.rb b/test/t/array.rb index 4e53f1120..1cfe02af7 100644 --- a/test/t/array.rb +++ b/test/t/array.rb @@ -222,7 +222,9 @@ assert('Array#size', '15.2.12.5.28') do end assert('Array#slice', '15.2.12.5.29') do - [1,2,3].[](1) == 2 + a = "12345".slice(1, 3) + b = a.slice(0) + "#{b}:" == "2:" and [1,2,3].[](1) == 2 end assert('Array#unshift', '15.2.12.5.30') do -- cgit v1.2.3 From 5937c29281d9bf51ca85b79c8f3dea204909a073 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Tue, 12 Jun 2012 12:29:20 +0900 Subject: s.split(nil) should work like s.split() --- src/string.c | 2 +- test/t/string.rb | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/src/string.c b/src/string.c index 172b8422c..fae3392cf 100644 --- a/src/string.c +++ b/src/string.c @@ -2139,7 +2139,7 @@ mrb_str_split_m(mrb_state *mrb, mrb_value str) i = 1; } - if (argc == 0) { + if (argc == 0 || mrb_nil_p(spat)) { split_type = awk; } else { diff --git a/test/t/string.rb b/test/t/string.rb index 718b005a9..c422133e3 100644 --- a/test/t/string.rb +++ b/test/t/string.rb @@ -277,9 +277,11 @@ assert('String#split', '15.2.10.5.35') do # without RegExp behavior is actually unspecified a = 'abc abc abc'.split b = 'a,b,c,,d'.split(',') + c = 'abc abc abc'.split(nil) a == ['abc', 'abc', 'abc'] and - b == ["a", "b", "c", "", "d"] + b == ["a", "b", "c", "", "d"] and + c == ['abc', 'abc', 'abc'] end # TODO ATM broken assert('String#sub', '15.2.10.5.36') do -- cgit v1.2.3 From 30a062c165f31f31f8be65bd51d313a2d25f0bd9 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Tue, 12 Jun 2012 12:58:49 +0900 Subject: String#split("") should split per character (byte for now) --- src/string.c | 22 ++++++++++++++++------ test/t/string.rb | 11 ++++------- 2 files changed, 20 insertions(+), 13 deletions(-) (limited to 'test') diff --git a/src/string.c b/src/string.c index fcd68a2f2..14041127a 100644 --- a/src/string.c +++ b/src/string.c @@ -2208,14 +2208,24 @@ mrb_str_split_m(mrb_state *mrb, mrb_value str) char *ptr = RSTRING_PTR(str); char *temp = ptr; char *eptr = RSTRING_END(str); - char *sptr = RSTRING_PTR(spat); long slen = RSTRING_LEN(spat); - while (ptr < eptr && - (end = mrb_memsearch(sptr, slen, ptr, eptr - ptr)) >= 0) { - mrb_ary_push(mrb, result, mrb_str_subseq(mrb, str, ptr - temp, end)); - ptr += end + slen; - if (lim >= 0 && lim <= ++i) break; + if (slen == 0) { + while (ptr < eptr) { + mrb_ary_push(mrb, result, mrb_str_subseq(mrb, str, ptr-temp, 1)); + ptr++; + if (lim >= 0 && lim <= ++i) break; + } + } + else { + char *sptr = RSTRING_PTR(spat); + + while (ptr < eptr && + (end = mrb_memsearch(sptr, slen, ptr, eptr - ptr)) >= 0) { + mrb_ary_push(mrb, result, mrb_str_subseq(mrb, str, ptr - temp, end)); + ptr += end + slen; + if (lim >= 0 && lim <= ++i) break; + } } beg = ptr - temp; } diff --git a/test/t/string.rb b/test/t/string.rb index c422133e3..3338e4318 100644 --- a/test/t/string.rb +++ b/test/t/string.rb @@ -275,13 +275,10 @@ end # TODO Broken ATM assert('String#split', '15.2.10.5.35') do # without RegExp behavior is actually unspecified - a = 'abc abc abc'.split - b = 'a,b,c,,d'.split(',') - c = 'abc abc abc'.split(nil) - - a == ['abc', 'abc', 'abc'] and - b == ["a", "b", "c", "", "d"] and - c == ['abc', 'abc', 'abc'] + 'abc abc abc'.split == ['abc', 'abc', 'abc'] and + 'a,b,c,,d'.split(',') == ["a", "b", "c", "", "d"] and + 'abc abc abc'.split(nil) == ['abc', 'abc', 'abc'] and + 'abc'.split("") == ['a', 'b', 'c'] end # TODO ATM broken assert('String#sub', '15.2.10.5.36') do -- cgit v1.2.3 From f537e2bb96a85d7ca75777f64cad13fea8d4937c Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Tue, 12 Jun 2012 19:09:11 +0900 Subject: block_given? should work; close #262 --- src/kernel.c | 19 ++++++++++++------- test/t/kernel.rb | 9 ++++++++- 2 files changed, 20 insertions(+), 8 deletions(-) (limited to 'test') diff --git a/src/kernel.c b/src/kernel.c index 04e427327..f233fdf6d 100644 --- a/src/kernel.c +++ b/src/kernel.c @@ -269,12 +269,6 @@ mrb_f_send(mrb_state *mrb, mrb_value self) return mrb_funcall_with_block(mrb,self, mrb_string_value_ptr(mrb, name), argc, argv, block); } -static mrb_value -mrb_f_block_given_p(void) -{ - return mrb_false_value(); /* dummy */ -} - /* 15.3.1.2.2 */ /* 15.3.1.2.5 */ /* 15.3.1.3.6 */ @@ -302,7 +296,18 @@ mrb_f_block_given_p(void) static mrb_value mrb_f_block_given_p_m(mrb_state *mrb, mrb_value self) { - return mrb_f_block_given_p(); + mrb_callinfo *ci = mrb->ci; + mrb_value *bp, *p; + + p = mrb->stbase + ci->stackidx; + bp = mrb->stbase + ci->stackidx + 1; + ci--; + if (ci <= mrb->cibase) return mrb_false_value(); + if (ci->argc > 0) { + bp += ci->argc; + } + if (mrb_nil_p(*bp)) return mrb_false_value(); + return mrb_true_value(); } /* 15.3.1.3.7 */ diff --git a/test/t/kernel.rb b/test/t/kernel.rb index 847f1baeb..5e25d6516 100644 --- a/test/t/kernel.rb +++ b/test/t/kernel.rb @@ -6,7 +6,14 @@ assert('Kernel', '15.3.1') do end assert('Kernel.block_given?', '15.3.1.2.2') do - Kernel.block_given? == false + def bg_try(&b) + if 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") end assert('Kernel.global_variables', '15.3.1.2.4') do -- cgit v1.2.3 From bddbf20785c322111441d9e9569cf8e85c7d8c3e Mon Sep 17 00:00:00 2001 From: Masaki Muranaka Date: Wed, 13 Jun 2012 09:41:24 +0900 Subject: Assert should handle all exceptions. --- test/assert.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/assert.rb b/test/assert.rb index 5cca59187..2fc11f149 100644 --- a/test/assert.rb +++ b/test/assert.rb @@ -32,7 +32,7 @@ def assert(str = 'Assertion failed', iso = '') $ok_test += 1 print('.') end - rescue => e + rescue Exception => e $asserts.push(['Error: ', str, iso, e]) $kill_test += 1 print('X') -- cgit v1.2.3 From 73d7000b8f5c3f7d2cb12e03b0a431ec3636fe21 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Thu, 14 Jun 2012 05:15:08 +0900 Subject: remove .inspect from bs_block.rb tests --- test/t/bs_block.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/t/bs_block.rb b/test/t/bs_block.rb index b290cb914..084d3b30f 100644 --- a/test/t/bs_block.rb +++ b/test/t/bs_block.rb @@ -322,28 +322,28 @@ assert('BS Block [ruby-dev:31147]') do def m yield end - m{|&b| b}.inspect == 'nil' + m{|&b| b} == nil end assert('BS Block [ruby-dev:31160]') do def m() yield end - m {|(v,(*))|}.inspect == 'nil' + m {|(v,(*))|} == nil end assert('BS Block 31') do def m() yield end - m {|((*))|}.inspect == 'nil' + m {|((*))|} == nil end assert('BS Block [ruby-dev:31440]') do def m yield [0] end - m{|v, &b| v}.inspect == '[0]' + m{|v, &b| v} == [0] end assert('BS Block 32') do -- cgit v1.2.3 From 587e0b0137234ee4d8b18430d41f7cf07569a732 Mon Sep 17 00:00:00 2001 From: Masaki Muranaka Date: Thu, 14 Jun 2012 17:47:29 +0900 Subject: Tests for Comparable. Still not all path coverage. --- test/t/comparable.rb | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 test/t/comparable.rb (limited to 'test') diff --git a/test/t/comparable.rb b/test/t/comparable.rb new file mode 100644 index 000000000..f3c03a9b5 --- /dev/null +++ b/test/t/comparable.rb @@ -0,0 +1,56 @@ + +assert('<', '15.3.3.2.1') do + class Foo + include Comparable + def <=>(x) + 0 + end + end + + (Foo.new < Foo.new) == false +end + +assert('<=', '15.3.3.2.2') do + class Foo + include Comparable + def <=>(x) + 0 + end + end + + (Foo.new <= Foo.new) == true +end + +assert('==', '15.3.3.2.3') do + class Foo + include Comparable + def <=>(x) + 0 + end + end + + (Foo.new == Foo.new) == true +end + +assert('>', '15.3.3.2.4') do + class Foo + include Comparable + def <=>(x) + 0 + end + end + + (Foo.new > Foo.new) == false +end + +assert('>=', '15.3.3.2.5') do + class Foo + include Comparable + def <=>(x) + 0 + end + end + + (Foo.new >= Foo.new) == true +end + -- cgit v1.2.3 From cfd5f5157d06f9c62a04660843c3c02014d8a3a5 Mon Sep 17 00:00:00 2001 From: Masaki Muranaka Date: Fri, 15 Jun 2012 13:06:43 +0900 Subject: Move Subclasses of ScriptError to mrblib. --- mrblib/error.rb | 8 ++++++++ src/error.c | 3 --- test/t/exception.rb | 30 ++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/mrblib/error.rb b/mrblib/error.rb index 3fa7f21e3..1cb2b1150 100644 --- a/mrblib/error.rb +++ b/mrblib/error.rb @@ -17,5 +17,13 @@ end class ScriptError < Exception end +# ISO 15.2.38 +class SyntaxError < ScriptError +end + +# ISO 15.2.39 +class LoadError < ScriptError +end + class NotImplementedError < ScriptError end diff --git a/src/error.c b/src/error.c index 548527f07..590fad5a5 100644 --- a/src/error.c +++ b/src/error.c @@ -385,9 +385,6 @@ mrb_init_exception(mrb_state *mrb) eNameError = mrb_define_class(mrb, "NameError", mrb->eStandardError_class); /* 15.2.31 */ mrb_define_class(mrb, "NoMethodError", eNameError); /* 15.2.32 */ - // eScriptError = mrb_define_class(mrb, "ScriptError", mrb->eException_class); /* 15.2.37 */ - // mrb_define_class(mrb, "SyntaxError", eScriptError); /* 15.2.38 */ - // mrb_define_class(mrb, "LoadError", eScriptError); /* 15.2.39 */ // mrb_define_class(mrb, "SystemCallError", mrb->eStandardError_class); /* 15.2.36 */ mrb_define_class(mrb, "LocalJumpError", mrb->eStandardError_class); /* 15.2.25 */ diff --git a/test/t/exception.rb b/test/t/exception.rb index 22795161f..d7226a368 100644 --- a/test/t/exception.rb +++ b/test/t/exception.rb @@ -41,6 +41,36 @@ assert('Exception.exception', '15.2.22.4.1') do e.message == 'a' end +assert('ScriptError', '15.2.37') do + begin + raise ScriptError.new + rescue ScriptError + true + else + false + end +end + +assert('SyntaxError', '15.2.38') do + begin + raise SyntaxError.new + rescue SyntaxError + true + else + false + end +end + +assert('LoadError', '15.2.39') do + begin + raise LoadError.new + rescue LoadError + true + else + false + end +end + # Not ISO specified assert('Exception 1') do -- cgit v1.2.3 From 39f47c191557ca401b6aaceb04b395227431b62f Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Fri, 15 Jun 2012 13:55:27 +0900 Subject: remove LoadError --- mrblib/error.rb | 4 ---- test/t/exception.rb | 12 +----------- 2 files changed, 1 insertion(+), 15 deletions(-) (limited to 'test') diff --git a/mrblib/error.rb b/mrblib/error.rb index 1cb2b1150..5d49ec1e4 100644 --- a/mrblib/error.rb +++ b/mrblib/error.rb @@ -21,9 +21,5 @@ end class SyntaxError < ScriptError end -# ISO 15.2.39 -class LoadError < ScriptError -end - class NotImplementedError < ScriptError end diff --git a/test/t/exception.rb b/test/t/exception.rb index d7226a368..0aed0e2e6 100644 --- a/test/t/exception.rb +++ b/test/t/exception.rb @@ -24,7 +24,7 @@ end assert('Exception#message', '15.2.22.5.2') do e = Exception.exception('a') - + e.message == 'a' end @@ -61,16 +61,6 @@ assert('SyntaxError', '15.2.38') do end end -assert('LoadError', '15.2.39') do - begin - raise LoadError.new - rescue LoadError - true - else - false - end -end - # Not ISO specified assert('Exception 1') do -- cgit v1.2.3 From f88a8399149f9b949f31f960d56d486a423efefa Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Mon, 18 Jun 2012 09:09:00 +0900 Subject: add Struct tests --- test/t/struct.rb | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'test') diff --git a/test/t/struct.rb b/test/t/struct.rb index 798cf6728..5a74c6205 100644 --- a/test/t/struct.rb +++ b/test/t/struct.rb @@ -9,3 +9,53 @@ assert('Struct superclass', '15.2.18.2') do Struct.superclass == Object end +assert('Struct.new', '15.2.18.3.1') do + c = Struct.new(:m1, :m2) + c.superclass == Struct and + c.members == [:m1,:m2] +end + +assert('Struct#[]', '15.2.18.4.2') do + c = Struct.new(:m1, :m2) + cc = c.new(1,2) + cc[:m1] == 1 and cc["m2"] == 2 +end + +assert('Struct#[]=', '15.2.18.4.3') do + c = Struct.new(:m1, :m2) + cc = c.new(1,2) + cc[:m1] = 3 + cc[:m1] == 3 +end + +assert('Struct#each', '15.2.18.4.4') do + c = Struct.new(:m1, :m2) + cc = c.new(1,2) + a = [] + cc.each{|x| + a << x + } + a[0] == 1 and a[1] == 2 +end + +assert('Struct#each_pair', '15.2.18.4.5') do + c = Struct.new(:m1, :m2) + cc = c.new(1,2) + a = [] + cc.each_pair{|k,v| + a << [k,v] + } + a[0] == [:m1, 1] and a[1] == [:m2, 2] +end + +assert('Struct#members', '15.2.18.4.6') do + c = Struct.new(:m1, :m2) + cc = c.new(1,2) + cc.members == [:m1,:m2] +end + +assert('Struct#select', '15.2.18.4.7') do + c = Struct.new(:m1, :m2) + cc = c.new(1,2) + cc.select{|v| v % 2 == 0} == [2] +end -- cgit v1.2.3 From 83e5999d7efcad648e9ecbd64c51b305b6261999 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Mon, 18 Jun 2012 11:22:05 +0800 Subject: Make CFLAG choices in Makefiles more flexible --- Makefile | 17 ++++++++++++----- mrblib/Makefile | 17 ++++++++++++----- src/Makefile | 17 ++++++++++++----- test/Makefile | 17 ++++++++++++----- tools/mirb/Makefile | 13 ++++++++++--- tools/mrbc/Makefile | 17 ++++++++++++----- tools/mruby/Makefile | 17 ++++++++++++----- 7 files changed, 82 insertions(+), 33 deletions(-) (limited to 'test') diff --git a/Makefile b/Makefile index e7408d793..a960fc14a 100644 --- a/Makefile +++ b/Makefile @@ -7,12 +7,19 @@ export LL = gcc export AR = ar export YACC = bison -DEBUG_MODE = 1 -ifeq ($(DEBUG_MODE),1) -CFLAGS = -g -O3 -else -CFLAGS = -O3 +ifeq ($(strip $(COMPILE_MODE)),) + # default compile option + COMPILE_MODE = debug +endif + +ifeq ($(COMPILE_MODE),debug) + CFLAGS = -g -O3 +else ifeq ($(COMPILE_MODE),release) + CFLAGS = -O3 +else ifeq ($(COMPILE_MODE),small) + CFLAGS = -Os endif + ALL_CFLAGS = -Wall -Werror-implicit-function-declaration $(CFLAGS) ifeq ($(OS),Windows_NT) MAKE_FLAGS = --no-print-directory CC=$(CC) LL=$(LL) ALL_CFLAGS='$(ALL_CFLAGS)' diff --git a/mrblib/Makefile b/mrblib/Makefile index c7226ddcd..01a5a6198 100644 --- a/mrblib/Makefile +++ b/mrblib/Makefile @@ -18,12 +18,19 @@ LIBR := ../lib/libmruby.a # libraries, includes INCLUDES = -I../src -I../include -DEBUG_MODE = 1 -ifeq ($(DEBUG_MODE),1) -CFLAGS = -g -else -CFLAGS = -O3 +ifeq ($(strip $(COMPILE_MODE)),) + # default compile option + COMPILE_MODE = debug +endif + +ifeq ($(COMPILE_MODE),debug) + CFLAGS = -g -O3 +else ifeq ($(COMPILE_MODE),release) + CFLAGS = -O3 +else ifeq ($(COMPILE_MODE),small) + CFLAGS = -Os endif + ALL_CFLAGS = -Wall -Werror-implicit-function-declaration $(CFLAGS) ifeq ($(OS),Windows_NT) MAKE_FLAGS = CC=$(CC) LL=$(LL) ALL_CFLAGS="$(ALL_CFLAGS)" diff --git a/src/Makefile b/src/Makefile index 61012ea68..13f80b694 100644 --- a/src/Makefile +++ b/src/Makefile @@ -19,12 +19,19 @@ OBJS := $(OBJ1) $(OBJ2) $(OBJ3) # libraries, includes INCLUDES = -I$(BASEDIR) -I$(BASEDIR)/../include -DEBUG_MODE = 1 -ifeq ($(DEBUG_MODE),1) -CFLAGS = -g -O3 -else -CFLAGS = -O3 +ifeq ($(strip $(COMPILE_MODE)),) + # default compile option + COMPILE_MODE = debug endif + +ifeq ($(COMPILE_MODE),debug) + CFLAGS = -g -O3 +else ifeq ($(COMPILE_MODE),release) + CFLAGS = -O3 +else ifeq ($(COMPILE_MODE),small) + CFLAGS = -Os +endif + ALL_CFLAGS = -Wall -Werror-implicit-function-declaration $(CFLAGS) diff --git a/test/Makefile b/test/Makefile index 170c1dac8..921442b28 100644 --- a/test/Makefile +++ b/test/Makefile @@ -20,12 +20,19 @@ OBJS := driver.o $(MLIB) LIBS = -lm INCLUDES = -I$(BASEDIR)/../src -I$(BASEDIR)/../include -DEBUG_MODE = 1 -ifeq ($(DEBUG_MODE),1) -CFLAGS = -g -else -CFLAGS = -O3 +ifeq ($(strip $(COMPILE_MODE)),) + # default compile option + COMPILE_MODE = debug +endif + +ifeq ($(COMPILE_MODE),debug) + CFLAGS = -g -O3 +else ifeq ($(COMPILE_MODE),release) + CFLAGS = -O3 +else ifeq ($(COMPILE_MODE),small) + CFLAGS = -Os endif + ALL_CFLAGS = -Wall -Werror-implicit-function-declaration $(CFLAGS) ifeq ($(OS),Windows_NT) MAKE_FLAGS = CC=$(CC) LL=$(LL) ALL_CFLAGS="$(ALL_CFLAGS)" diff --git a/tools/mirb/Makefile b/tools/mirb/Makefile index ba307227c..52941f242 100644 --- a/tools/mirb/Makefile +++ b/tools/mirb/Makefile @@ -21,12 +21,19 @@ EXTS := $(EXT1) LIBS = -lm INCLUDES = -I$(BASEDIR) -I$(BASEDIR)/../include -DEBUG_MODE = 1 -ifeq ($(DEBUG_MODE),1) +ifeq ($(strip $(COMPILE_MODE)),) + # default compile option + COMPILE_MODE = debug +endif + +ifeq ($(COMPILE_MODE),debug) CFLAGS = -g -O3 -else +else ifeq ($(COMPILE_MODE),release) CFLAGS = -O3 +else ifeq ($(COMPILE_MODE),small) + CFLAGS = -Os endif + ALL_CFLAGS = -Wall -Werror-implicit-function-declaration $(CFLAGS) ifeq ($(OS),Windows_NT) MAKE_FLAGS = CC=$(CC) LL=$(LL) ALL_CFLAGS="$(ALL_CFLAGS)" diff --git a/tools/mrbc/Makefile b/tools/mrbc/Makefile index 99f5830e6..eea0c02cb 100644 --- a/tools/mrbc/Makefile +++ b/tools/mrbc/Makefile @@ -23,12 +23,19 @@ LIBS = -lm INCLUDES = -I$(BASEDIR) -I$(BASEDIR)/../include # compiler, linker (gcc) -DEBUG_MODE = 1 -ifeq ($(DEBUG_MODE),1) -CFLAGS = -g -O3 -else -CFLAGS = -O3 +ifeq ($(strip $(COMPILE_MODE)),) + # default compile option + COMPILE_MODE = debug +endif + +ifeq ($(COMPILE_MODE),debug) + CFLAGS = -g -O3 +else ifeq ($(COMPILE_MODE),release) + CFLAGS = -O3 +else ifeq ($(COMPILE_MODE),small) + CFLAGS = -Os endif + ALL_CFLAGS = -Wall -Werror-implicit-function-declaration $(CFLAGS) ifeq ($(OS),Windows_NT) MAKE_FLAGS = CC=$(CC) LL=$(LL) ALL_CFLAGS="$(ALL_CFLAGS)" diff --git a/tools/mruby/Makefile b/tools/mruby/Makefile index 0442bd422..9955b4302 100644 --- a/tools/mruby/Makefile +++ b/tools/mruby/Makefile @@ -26,12 +26,19 @@ LIBS = -lm INCLUDES = -I$(BASEDIR) -I$(BASEDIR)/../include # compiler, linker (gcc) -DEBUG_MODE = 1 -ifeq ($(DEBUG_MODE),1) -CFLAGS = -g -O3 -else -CFLAGS = -O3 +ifeq ($(strip $(COMPILE_MODE)),) + # default compile option + COMPILE_MODE = debug +endif + +ifeq ($(COMPILE_MODE),debug) + CFLAGS = -g -O3 +else ifeq ($(COMPILE_MODE),release) + CFLAGS = -O3 +else ifeq ($(COMPILE_MODE),small) + CFLAGS = -Os endif + ALL_CFLAGS = -Wall -Werror-implicit-function-declaration $(CFLAGS) ifeq ($(OS),Windows_NT) MAKE_FLAGS = CC=$(CC) LL=$(LL) ALL_CFLAGS="$(ALL_CFLAGS)" -- cgit v1.2.3 From 1a7bdcf156d5a150bb0a24905970b0c6065c36ae Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Tue, 19 Jun 2012 16:48:31 +0900 Subject: remove local_variables test --- test/t/kernel.rb | 8 -------- 1 file changed, 8 deletions(-) (limited to 'test') diff --git a/test/t/kernel.rb b/test/t/kernel.rb index 5e25d6516..ba708dbb7 100644 --- a/test/t/kernel.rb +++ b/test/t/kernel.rb @@ -32,10 +32,6 @@ assert('Kernel.lambda', '15.3.1.2.6') do l.call and l.class == Proc end -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 @@ -79,10 +75,6 @@ assert('Kernel#hash', '15.3.1.2.15') do hash == hash end -assert('Kernel#local_variables', '15.3.1.2.28') do - local_variables.class == Array -end - assert('Kernel#loop', '15.3.1.2.29') do i = 0 -- cgit v1.2.3 From 750a639eab6e0c5615cd7651c1ab4215a8247ef7 Mon Sep 17 00:00:00 2001 From: Masaki Muranaka Date: Thu, 21 Jun 2012 11:43:03 +0900 Subject: Add test for Array#to_s and Array#inspect. --- test/t/array.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'test') diff --git a/test/t/array.rb b/test/t/array.rb index 1cfe02af7..3f441c1cc 100644 --- a/test/t/array.rb +++ b/test/t/array.rb @@ -234,4 +234,12 @@ assert('Array#unshift', '15.2.12.5.30') do a == [1,2,3] and b == [1,2,3] end +assert('Array#to_s', '15.2.12.5.31') do + a = [2, 3, 4, 5] + r1 = a.to_s + r2 = a.inspect + + r1 == r2 and r1 == "[2, 3, 4, 5]" +end + # Not ISO specified -- cgit v1.2.3 From c09f804e2bd62fa861cf802181b26f2e01add7aa Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Thu, 21 Jun 2012 14:22:50 +0800 Subject: Skip math test in case that Math isn't implemented --- test/t/math.rb | 178 +++++++++++++++++++++++++++++---------------------------- 1 file changed, 90 insertions(+), 88 deletions(-) (limited to 'test') diff --git a/test/t/math.rb b/test/t/math.rb index 47a3bf527..d60d80ae7 100644 --- a/test/t/math.rb +++ b/test/t/math.rb @@ -1,115 +1,117 @@ ## # Math Test -assert('Math.sin 0') do - check_float(Math.sin(0), 0) -end +if MathEnabled + assert('Math.sin 0') do + check_float(Math.sin(0), 0) + end -assert('Math.sin PI/2') do - check_float(Math.sin(Math::PI / 2), 1) -end + assert('Math.sin PI/2') do + check_float(Math.sin(Math::PI / 2), 1) + end + assert('Fundamental trig identities') do + result = true + N = 15 + N.times do |i| + a = Math::PI / N * i + ca = Math::PI / 2 - a + s = Math.sin(a) + c = Math.cos(a) + t = Math.tan(a) + result &= check_float(s, Math.cos(ca)) + result &= check_float(t, 1 / Math.tan(ca)) + result &= check_float(s ** 2 + c ** 2, 1) + result &= check_float(t ** 2 + 1, (1/c) ** 2) + result &= check_float((1/t) ** 2 + 1, (1/s) ** 2) + end + result + end -assert('Fundamental trig identities') do - result = true - N = 15 - N.times do |i| - a = Math::PI / N * i - ca = Math::PI / 2 - a - s = Math.sin(a) - c = Math.cos(a) - t = Math.tan(a) - result &= check_float(s, Math.cos(ca)) - result &= check_float(t, 1 / Math.tan(ca)) - result &= check_float(s ** 2 + c ** 2, 1) - result &= check_float(t ** 2 + 1, (1/c) ** 2) - result &= check_float((1/t) ** 2 + 1, (1/s) ** 2) - end - result -end + assert('Math.erf 0') do + check_float(Math.erf(0), 0) + end -assert('Math.erf 0') do - check_float(Math.erf(0), 0) -end + assert('Math.exp 0') do + check_float(Math.exp(0), 1.0) + end -assert('Math.exp 0') do - check_float(Math.exp(0), 1.0) -end + assert('Math.exp 1') do + check_float(Math.exp(1), 2.718281828459045) + end -assert('Math.exp 1') do - check_float(Math.exp(1), 2.718281828459045) -end + assert('Math.exp 1.5') do + check_float(Math.exp(1.5), 4.4816890703380645) + end -assert('Math.exp 1.5') do - check_float(Math.exp(1.5), 4.4816890703380645) -end + assert('Math.log 1') do + check_float(Math.log(1), 0) + end -assert('Math.log 1') do - check_float(Math.log(1), 0) -end + assert('Math.log E') do + check_float(Math.log(Math::E), 1.0) + end -assert('Math.log E') do - check_float(Math.log(Math::E), 1.0) -end + assert('Math.log E**3') do + check_float(Math.log(Math::E**3), 3.0) + end -assert('Math.log E**3') do - check_float(Math.log(Math::E**3), 3.0) -end + assert('Math.log2 1') do + check_float(Math.log2(1), 0.0) + end -assert('Math.log2 1') do - check_float(Math.log2(1), 0.0) -end + assert('Math.log2 2') do + check_float(Math.log2(2), 1.0) + end -assert('Math.log2 2') do - check_float(Math.log2(2), 1.0) -end + assert('Math.log10 1') do + check_float(Math.log10(1), 0.0) + end -assert('Math.log10 1') do - check_float(Math.log10(1), 0.0) -end + assert('Math.log10 10') do + check_float(Math.log10(10), 1.0) + end -assert('Math.log10 10') do - check_float(Math.log10(10), 1.0) -end + assert('Math.log10 10**100') do + check_float(Math.log10(10**100), 100.0) + end -assert('Math.log10 10**100') do - check_float(Math.log10(10**100), 100.0) -end + assert('Math.sqrt') do + num = [0.0, 1.0, 2.0, 3.0, 4.0] + sqr = [0, 1, 4, 9, 16] + result = true + sqr.each_with_index do |v,i| + result &= check_float(Math.sqrt(v), num[i]) + end + result + end -assert('Math.sqrt') do - num = [0.0, 1.0, 2.0, 3.0, 4.0] - sqr = [0, 1, 4, 9, 16] - result = true - sqr.each_with_index do |v,i| - result &= check_float(Math.sqrt(v), num[i]) + assert('Math.cbrt') do + num = [-2.0, -1.0, 0.0, 1.0, 2.0] + cub = [-8, -1, 0, 1, 8] + result = true + cub.each_with_index do |v,i| + result &= check_float(Math.cbrt(v), num[i]) + end + result end - result -end -assert('Math.cbrt') do - num = [-2.0, -1.0, 0.0, 1.0, 2.0] - cub = [-8, -1, 0, 1, 8] - result = true - cub.each_with_index do |v,i| - result &= check_float(Math.cbrt(v), num[i]) + assert('Math.hypot') do + check_float(Math.hypot(3, 4), 5.0) end - result -end -assert('Math.hypot') do - check_float(Math.hypot(3, 4), 5.0) -end + assert('Math.frexp 1234') do + n = 1234 + fraction, exponent = Math.frexp(n) + check_float(Math.ldexp(fraction, exponent), n) + end -assert('Math.frexp 1234') do - n = 1234 - fraction, exponent = Math.frexp(n) - check_float(Math.ldexp(fraction, exponent), n) -end + assert('Math.erf 1') do + check_float(Math.erf(1), 0.842700792949715) + end -assert('Math.erf 1') do - check_float(Math.erf(1), 0.842700792949715) + assert('Math.erfc 1') do + check_float(Math.erfc(1), 0.157299207050285) + end end -assert('Math.erfc 1') do - check_float(Math.erfc(1), 0.157299207050285) -end -- cgit v1.2.3 From d88a37c1c9175a1583b02596ece978a51a64f9e0 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Thu, 21 Jun 2012 14:23:21 +0800 Subject: Skip struct test in case that Struct isn't implemented --- test/t/struct.rb | 101 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 52 insertions(+), 49 deletions(-) (limited to 'test') diff --git a/test/t/struct.rb b/test/t/struct.rb index 5a74c6205..5e86c70bf 100644 --- a/test/t/struct.rb +++ b/test/t/struct.rb @@ -1,61 +1,64 @@ ## # Struct ISO Test -assert('Struct', '15.2.18') do - Struct.class == Class -end +if StructEnabled + assert('Struct', '15.2.18') do + Struct.class == Class + end -assert('Struct superclass', '15.2.18.2') do - Struct.superclass == Object -end + assert('Struct superclass', '15.2.18.2') do + Struct.superclass == Object + end -assert('Struct.new', '15.2.18.3.1') do - c = Struct.new(:m1, :m2) - c.superclass == Struct and - c.members == [:m1,:m2] -end + assert('Struct.new', '15.2.18.3.1') do + c = Struct.new(:m1, :m2) + c.superclass == Struct and + c.members == [:m1,:m2] + end -assert('Struct#[]', '15.2.18.4.2') do - c = Struct.new(:m1, :m2) - cc = c.new(1,2) - cc[:m1] == 1 and cc["m2"] == 2 -end + assert('Struct#[]', '15.2.18.4.2') do + c = Struct.new(:m1, :m2) + cc = c.new(1,2) + cc[:m1] == 1 and cc["m2"] == 2 + end -assert('Struct#[]=', '15.2.18.4.3') do - c = Struct.new(:m1, :m2) - cc = c.new(1,2) - cc[:m1] = 3 - cc[:m1] == 3 -end + assert('Struct#[]=', '15.2.18.4.3') do + c = Struct.new(:m1, :m2) + cc = c.new(1,2) + cc[:m1] = 3 + cc[:m1] == 3 + end -assert('Struct#each', '15.2.18.4.4') do - c = Struct.new(:m1, :m2) - cc = c.new(1,2) - a = [] - cc.each{|x| - a << x - } - a[0] == 1 and a[1] == 2 -end + assert('Struct#each', '15.2.18.4.4') do + c = Struct.new(:m1, :m2) + cc = c.new(1,2) + a = [] + cc.each{|x| + a << x + } + a[0] == 1 and a[1] == 2 + end -assert('Struct#each_pair', '15.2.18.4.5') do - c = Struct.new(:m1, :m2) - cc = c.new(1,2) - a = [] - cc.each_pair{|k,v| - a << [k,v] - } - a[0] == [:m1, 1] and a[1] == [:m2, 2] -end + assert('Struct#each_pair', '15.2.18.4.5') do + c = Struct.new(:m1, :m2) + cc = c.new(1,2) + a = [] + cc.each_pair{|k,v| + a << [k,v] + } + a[0] == [:m1, 1] and a[1] == [:m2, 2] + end -assert('Struct#members', '15.2.18.4.6') do - c = Struct.new(:m1, :m2) - cc = c.new(1,2) - cc.members == [:m1,:m2] -end + assert('Struct#members', '15.2.18.4.6') do + c = Struct.new(:m1, :m2) + cc = c.new(1,2) + cc.members == [:m1,:m2] + end -assert('Struct#select', '15.2.18.4.7') do - c = Struct.new(:m1, :m2) - cc = c.new(1,2) - cc.select{|v| v % 2 == 0} == [2] + assert('Struct#select', '15.2.18.4.7') do + c = Struct.new(:m1, :m2) + cc = c.new(1,2) + cc.select{|v| v % 2 == 0} == [2] + end end + -- cgit v1.2.3 From 304b7eec0aaadf3cc45f8400e52b72ece523d30e Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Thu, 21 Jun 2012 14:23:36 +0800 Subject: Skip time test in case that Time isn't implemented --- test/t/time.rb | 278 +++++++++++++++++++++++++++++---------------------------- 1 file changed, 140 insertions(+), 138 deletions(-) (limited to 'test') diff --git a/test/t/time.rb b/test/t/time.rb index 045c5b185..2b3101e69 100644 --- a/test/t/time.rb +++ b/test/t/time.rb @@ -1,189 +1,191 @@ ## # Time ISO Test -assert('Time.new', '15.2.3.3.3') do - Time.new.class == Time -end +if TimeEnabled + assert('Time.new', '15.2.3.3.3') do + Time.new.class == Time + end -assert('Time', '15.2.19') do - Time.class == Class -end + assert('Time', '15.2.19') do + Time.class == Class + end -assert('Time superclass', '15.2.19.2') do - Time.superclass == Object -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 + assert('Time.at', '15.2.19.6.1') do + Time.at(1300000000.0) + end -assert('Time.gm', '15.2.19.6.2') do - Time.gm(2012, 12, 23) -end + assert('Time.gm', '15.2.19.6.2') do + Time.gm(2012, 12, 23) + end -assert('Time.local', '15.2.19.6.3') do - Time.local(2012, 12, 23) -end + assert('Time.local', '15.2.19.6.3') do + Time.local(2012, 12, 23) + end -assert('Time.mktime', '15.2.19.6.4') do - Time.mktime(2012, 12, 23) -end + assert('Time.mktime', '15.2.19.6.4') do + Time.mktime(2012, 12, 23) + end -assert('Time.now', '15.2.19.6.5') do - Time.now.class == Time -end + assert('Time.now', '15.2.19.6.5') do + Time.now.class == Time + end -assert('Time.utc', '15.2.19.6.6') do - Time.utc(2012, 12, 23) -end + assert('Time.utc', '15.2.19.6.6') do + Time.utc(2012, 12, 23) + end -assert('Time#+', '15.2.19.7.1') do - t1 = Time.at(1300000000.0) - t2 = t1.+(60) + assert('Time#+', '15.2.19.7.1') do + t1 = Time.at(1300000000.0) + t2 = t1.+(60) - t2.utc.asctime == "Sun Mar 13 07:07:40 UTC 2011" -end + t2.utc.asctime == "Sun Mar 13 07:07:40 UTC 2011" + end -assert('Time#-', '15.2.19.7.2') do - t1 = Time.at(1300000000.0) - t2 = t1.-(60) + assert('Time#-', '15.2.19.7.2') do + t1 = Time.at(1300000000.0) + t2 = t1.-(60) - t2.utc.asctime == "Sun Mar 13 07:05:40 UTC 2011" -end + t2.utc.asctime == "Sun Mar 13 07:05:40 UTC 2011" + end -assert('Time#<=>', '15.2.19.7.3') do - t1 = Time.at(1300000000.0) - t2 = Time.at(1400000000.0) - t3 = Time.at(1500000000.0) + assert('Time#<=>', '15.2.19.7.3') do + t1 = Time.at(1300000000.0) + t2 = Time.at(1400000000.0) + t3 = Time.at(1500000000.0) - t2.<=>(t1) == 1 and - t2.<=>(t2) == 0 and - t2.<=>(t3) == -1 and - t2.<=>(nil) == nil -end + t2.<=>(t1) == 1 and + t2.<=>(t2) == 0 and + t2.<=>(t3) == -1 and + t2.<=>(nil) == nil + end -assert('Time#asctime', '15.2.19.7.4') do - Time.at(1300000000.0).utc.asctime == "Sun Mar 13 07:06:40 UTC 2011" -end + assert('Time#asctime', '15.2.19.7.4') do + Time.at(1300000000.0).utc.asctime == "Sun Mar 13 07:06:40 UTC 2011" + end -assert('Time#ctime', '15.2.19.7.5') do - Time.at(1300000000.0).utc.ctime == "Sun Mar 13 07:06:40 UTC 2011" -end + assert('Time#ctime', '15.2.19.7.5') do + Time.at(1300000000.0).utc.ctime == "Sun Mar 13 07:06:40 UTC 2011" + end -assert('Time#day', '15.2.19.7.6') do - Time.gm(2012, 12, 23).day == 23 -end + assert('Time#day', '15.2.19.7.6') do + Time.gm(2012, 12, 23).day == 23 + end -assert('Time#dst?', '15.2.19.7.7') do - not Time.gm(2012, 12, 23).utc.dst? -end + assert('Time#dst?', '15.2.19.7.7') do + not Time.gm(2012, 12, 23).utc.dst? + end -assert('Time#getgm', '15.2.19.7.8') do - Time.at(1300000000.0).getgm.asctime == "Sun Mar 13 07:06:40 UTC 2011" -end + assert('Time#getgm', '15.2.19.7.8') do + Time.at(1300000000.0).getgm.asctime == "Sun Mar 13 07:06:40 UTC 2011" + end -assert('Time#getlocal', '15.2.19.7.9') do - t1 = Time.at(1300000000.0) - t2 = Time.at(1300000000.0) - t3 = t1.getlocal + assert('Time#getlocal', '15.2.19.7.9') do + t1 = Time.at(1300000000.0) + t2 = Time.at(1300000000.0) + t3 = t1.getlocal - t1 == t3 and t3 == t2.getlocal -end + t1 == t3 and t3 == t2.getlocal + end -assert('Time#getutc', '15.2.19.7.10') do - Time.at(1300000000.0).getutc.asctime == "Sun Mar 13 07:06:40 UTC 2011" -end + assert('Time#getutc', '15.2.19.7.10') do + Time.at(1300000000.0).getutc.asctime == "Sun Mar 13 07:06:40 UTC 2011" + end -assert('Time#gmt?', '15.2.19.7.11') do - Time.at(1300000000.0).utc.gmt? -end + assert('Time#gmt?', '15.2.19.7.11') do + Time.at(1300000000.0).utc.gmt? + end -# ATM not implemented -# assert('Time#gmt_offset', '15.2.19.7.12') do + # ATM not implemented + # assert('Time#gmt_offset', '15.2.19.7.12') do -assert('Time#gmtime', '15.2.19.7.13') do - Time.at(1300000000.0).gmtime -end + assert('Time#gmtime', '15.2.19.7.13') do + Time.at(1300000000.0).gmtime + end -# ATM not implemented -# assert('Time#gmtoff', '15.2.19.7.14') do + # ATM not implemented + # assert('Time#gmtoff', '15.2.19.7.14') do -assert('Time#hour', '15.2.19.7.15') do - Time.gm(2012, 12, 23, 7, 6).hour == 7 -end + assert('Time#hour', '15.2.19.7.15') do + Time.gm(2012, 12, 23, 7, 6).hour == 7 + end -# ATM doesn't really work -# assert('Time#initialize', '15.2.19.7.16') do + # ATM doesn't really work + # assert('Time#initialize', '15.2.19.7.16') do -assert('Time#initialize_copy', '15.2.19.7.17') do - time_tmp_2 = Time.at(7.0e6) - time_tmp_2.clone == time_tmp_2 -end + assert('Time#initialize_copy', '15.2.19.7.17') do + time_tmp_2 = Time.at(7.0e6) + time_tmp_2.clone == time_tmp_2 + end -assert('Time#localtime', '15.2.19.7.18') do - t1 = Time.at(1300000000.0) - t2 = Time.at(1300000000.0) + assert('Time#localtime', '15.2.19.7.18') do + t1 = Time.at(1300000000.0) + t2 = Time.at(1300000000.0) - t1.localtime - t1 == t2.getlocal -end + t1.localtime + t1 == t2.getlocal + end -assert('Time#mday', '15.2.19.7.19') do - Time.gm(2012, 12, 23).mday == 23 -end + assert('Time#mday', '15.2.19.7.19') do + Time.gm(2012, 12, 23).mday == 23 + end -assert('Time#min', '15.2.19.7.20') do - Time.gm(2012, 12, 23, 7, 6).min == 6 -end + assert('Time#min', '15.2.19.7.20') do + Time.gm(2012, 12, 23, 7, 6).min == 6 + end -assert('Time#mon', '15.2.19.7.21') do - Time.gm(2012, 12, 23).mon == 12 -end + assert('Time#mon', '15.2.19.7.21') do + Time.gm(2012, 12, 23).mon == 12 + end -assert('Time#month', '15.2.19.7.22') do - Time.gm(2012, 12, 23).month == 12 -end + assert('Time#month', '15.2.19.7.22') do + Time.gm(2012, 12, 23).month == 12 + end -assert('Times#sec', '15.2.19.7.23') do - Time.gm(2012, 12, 23, 7, 6, 40).sec == 40 -end + assert('Times#sec', '15.2.19.7.23') do + Time.gm(2012, 12, 23, 7, 6, 40).sec == 40 + end -assert('Time#to_f', '15.2.19.7.24') do - Time.at(1300000000.0).to_f == 1300000000.0 -end + assert('Time#to_f', '15.2.19.7.24') do + Time.at(1300000000.0).to_f == 1300000000.0 + end -assert('Time#to_i', '15.2.19.7.25') do - Time.at(1300000000.0).to_i == 1300000000 -end + assert('Time#to_i', '15.2.19.7.25') do + Time.at(1300000000.0).to_i == 1300000000 + end -assert('Time#usec', '15.2.19.7.26') do - Time.at(1300000000.0).usec == 0 -end + assert('Time#usec', '15.2.19.7.26') do + Time.at(1300000000.0).usec == 0 + end -assert('Time#utc', '15.2.19.7.27') do - Time.at(1300000000.0).utc -end + assert('Time#utc', '15.2.19.7.27') do + Time.at(1300000000.0).utc + end -assert('Time#utc?', '15.2.19.7.28') do - Time.at(1300000000.0).utc.utc? -end + assert('Time#utc?', '15.2.19.7.28') do + Time.at(1300000000.0).utc.utc? + end -# ATM not implemented -# assert('Time#utc_offset', '15.2.19.7.29') do + # ATM not implemented + # assert('Time#utc_offset', '15.2.19.7.29') do -assert('Time#wday', '15.2.19.7.30') do - Time.gm(2012, 12, 23).wday == 0 -end + assert('Time#wday', '15.2.19.7.30') do + Time.gm(2012, 12, 23).wday == 0 + end -assert('Time#yday', '15.2.19.7.31') do - Time.gm(2012, 12, 23).yday == 357 -end + assert('Time#yday', '15.2.19.7.31') do + Time.gm(2012, 12, 23).yday == 357 + end -assert('Time#year', '15.2.19.7.32') do - Time.gm(2012, 12, 23).year == 2012 -end + assert('Time#year', '15.2.19.7.32') do + Time.gm(2012, 12, 23).year == 2012 + end -assert('Time#zone', '15.2.19.7.33') do - Time.at(1300000000.0).utc.zone == 'UTC' + assert('Time#zone', '15.2.19.7.33') do + Time.at(1300000000.0).utc.zone == 'UTC' + end end -- cgit v1.2.3 From 8e89cd456cca0402c639d31031df29fceaa49ef6 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Thu, 21 Jun 2012 15:01:39 +0800 Subject: only execute math tests if math feature is activated --- test/t/math.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/t/math.rb b/test/t/math.rb index d60d80ae7..025551b82 100644 --- a/test/t/math.rb +++ b/test/t/math.rb @@ -1,7 +1,7 @@ ## # Math Test -if MathEnabled +if Object.const_defined?(:Math) assert('Math.sin 0') do check_float(Math.sin(0), 0) end -- cgit v1.2.3 From 1baa3faf3f0c8ea4fea6415e6e215e794f4993d6 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Thu, 21 Jun 2012 15:01:52 +0800 Subject: only execute time tests if time feature is activated --- test/t/time.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/t/time.rb b/test/t/time.rb index 2b3101e69..6140be1a8 100644 --- a/test/t/time.rb +++ b/test/t/time.rb @@ -1,7 +1,7 @@ ## # Time ISO Test -if TimeEnabled +if Object.const_defined?(:Time) assert('Time.new', '15.2.3.3.3') do Time.new.class == Time end -- cgit v1.2.3 From 7a410123dd1ad93359d07134bbac39a34b184cb4 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Thu, 21 Jun 2012 15:02:08 +0800 Subject: only execute struct tests if struct feature is activated --- test/t/struct.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/t/struct.rb b/test/t/struct.rb index 5e86c70bf..fff02ee56 100644 --- a/test/t/struct.rb +++ b/test/t/struct.rb @@ -1,7 +1,7 @@ ## # Struct ISO Test -if StructEnabled +if Object.const_defined?(:Struct) assert('Struct', '15.2.18') do Struct.class == Class end -- cgit v1.2.3 From 2ae84f7d8358628bd904993aef18edf27828d696 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Thu, 21 Jun 2012 16:00:04 +0800 Subject: Add execution time to tests --- test/assert.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'test') diff --git a/test/assert.rb b/test/assert.rb index 2fc11f149..9329638c9 100644 --- a/test/assert.rb +++ b/test/assert.rb @@ -2,6 +2,7 @@ $ok_test = 0 $ko_test = 0 $kill_test = 0 $asserts = [] +$test_start = Time.now if Object.const_defined?(:Time) ## # Print the assertion in a readable way @@ -68,6 +69,12 @@ def report() print('Crash: ') print($kill_test) print("\n") + + if Object.const_defined?(:Time) + print(' Time: ') + print(Time.now - $test_start) + print(" seconds\n") + end end ## @@ -83,3 +90,4 @@ def check_float(a, b) true end end + -- cgit v1.2.3 From a194f30f62d5d746e133c1c7a784b6eb3b5b7cb0 Mon Sep 17 00:00:00 2001 From: Masamitsu MURASE Date: Sun, 24 Jun 2012 04:03:46 +0900 Subject: Add test for Struct#==. --- test/t/struct.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'test') diff --git a/test/t/struct.rb b/test/t/struct.rb index fff02ee56..5cf6929b8 100644 --- a/test/t/struct.rb +++ b/test/t/struct.rb @@ -16,6 +16,13 @@ if Object.const_defined?(:Struct) c.members == [:m1,:m2] end + assert('Struct#==', '15.2.18.4.1') do + c = Struct.new(:m1, :m2) + cc1 = c.new(1,2) + cc2 = c.new(1,2) + cc1 == cc2 + end + assert('Struct#[]', '15.2.18.4.2') do c = Struct.new(:m1, :m2) cc = c.new(1,2) -- cgit v1.2.3 From 062e96960d078cb5bca48ba3b878f681871be72a Mon Sep 17 00:00:00 2001 From: Masamitsu MURASE Date: Fri, 22 Jun 2012 01:31:33 +0900 Subject: Add sample test for Kernel#clone and Kernel#dup. --- test/t/kernel.rb | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) (limited to 'test') diff --git a/test/t/kernel.rb b/test/t/kernel.rb index ba708dbb7..6531383e5 100644 --- a/test/t/kernel.rb +++ b/test/t/kernel.rb @@ -71,6 +71,62 @@ assert('Kernel.raise', '15.3.1.2.12') do e_list[0].class == RuntimeError end +assert('Kernel#clone', '15.3.1.3.8') do + class KernelCloneTest + def initialize + @v = 0 + end + + def get + @v + end + + def set(v) + @v = v + end + end + + a = KernelCloneTest.new + a.set(1) + b = a.clone + + def a.test + end + 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 +end + +assert('Kernel#dup', '15.3.1.3.9') do + class KernelDupTest + def initialize + @v = 0 + end + + def get + @v + end + + def set(v) + @v = v + end + end + + a = KernelDupTest.new + a.set(1) + b = a.dup + + def a.test + end + 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 +end + assert('Kernel#hash', '15.3.1.2.15') do hash == hash end -- cgit v1.2.3 From ccde2d3be08d215f235e7a1820ab98ddb769abe6 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Sun, 24 Jun 2012 22:30:56 +0900 Subject: update ISO chapter number in test/t/kernel.rb --- test/t/kernel.rb | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) (limited to 'test') diff --git a/test/t/kernel.rb b/test/t/kernel.rb index 6531383e5..c1f42e420 100644 --- a/test/t/kernel.rb +++ b/test/t/kernel.rb @@ -127,11 +127,11 @@ assert('Kernel#dup', '15.3.1.3.9') do a.respond_to?(:test) == true && b.respond_to?(:test) == false && c.respond_to?(:test) == false end -assert('Kernel#hash', '15.3.1.2.15') do +assert('Kernel#hash', '15.3.1.3.15') do hash == hash end -assert('Kernel#loop', '15.3.1.2.29') do +assert('Kernel#loop', '15.3.1.3.29') do i = 0 loop do @@ -142,32 +142,31 @@ assert('Kernel#loop', '15.3.1.2.29') do i == 100 end -assert('Kernel#methods', '15.3.1.2.31') do +assert('Kernel#methods', '15.3.1.3.31') do methods.class == Array end -assert('Kernel#nil?', '15.3.1.2.32') do - # TODO why is Kernel nil ???? - nil? == true +assert('Kernel#nil?', '15.3.1.3.32') do + nil.nil? == true end -assert('Kernel#private_methods', '15.3.1.2.36') do - private_methods.class == Array +assert('Kernel#private_methods', '15.3.1.3.36') do + private_methods.class == Array end -assert('Kernel#protected_methods', '15.3.1.2.37') do +assert('Kernel#protected_methods', '15.3.1.3.37') do protected_methods.class == Array end -assert('Kernel#public_methods', '15.3.1.2.38') do +assert('Kernel#public_methods', '15.3.1.3.38') do public_methods.class == Array end -assert('Kernel#respond_to?', '15.3.1.2.43') do +assert('Kernel#respond_to?', '15.3.1.3.43') do respond_to? :nil? end -assert('Kernel#send', '15.3.1.2.44') do +assert('Kernel#send', '15.3.1.3.44') do # test with block l = send(:lambda) do true @@ -179,11 +178,11 @@ assert('Kernel#send', '15.3.1.2.44') do send(:public_methods).class == Array end -assert('Kernel#singleton_methods', '15.3.1.2.45') do +assert('Kernel#singleton_methods', '15.3.1.3.45') do singleton_methods.class == Array end -assert('Kernel#to_s', '15.3.1.2.46') do +assert('Kernel#to_s', '15.3.1.3.46') do # TODO looks strange.. to_s == '' end -- cgit v1.2.3 From d3bf659bfd633aa6a6fbb5045df4289c809f03dc Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Wed, 27 Jun 2012 03:06:07 +0800 Subject: Add more kernel tests --- test/t/kernel.rb | 141 +++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 132 insertions(+), 9 deletions(-) (limited to 'test') diff --git a/test/t/kernel.rb b/test/t/kernel.rb index c1f42e420..d11e256a6 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('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('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 -- cgit v1.2.3 From e8ad94da9338e1d0ed6acf709f611e6830b16621 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Wed, 27 Jun 2012 03:12:37 +0800 Subject: Fix kernel test descriptions --- test/t/kernel.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/t/kernel.rb b/test/t/kernel.rb index d11e256a6..5aa7672d7 100644 --- a/test/t/kernel.rb +++ b/test/t/kernel.rb @@ -187,7 +187,7 @@ assert('Kernel#dup', '15.3.1.3.9') do c.respond_to?(:test) == false end -assert('global_variables', '15.3.1.3.14') do +assert('Kernel#global_variables', '15.3.1.3.14') do global_variables.class == Array end @@ -195,7 +195,7 @@ assert('Kernel#hash', '15.3.1.3.15') do hash == hash end -assert('inspect', '15.3.1.3.17') do +assert('Kernel#inspect', '15.3.1.3.17') do inspect.class == String end @@ -263,7 +263,7 @@ assert('Kernel#public_methods', '15.3.1.3.38') do public_methods.class == Array end -assert('Kernel.raise', '15.3.1.3.40') do +assert('Kernel#raise', '15.3.1.3.40') do e_list = [] begin -- cgit v1.2.3 From 65096c4c1bd1bfb6f547808fc01ab6ea223d9dc6 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Tue, 3 Jul 2012 20:59:07 +0900 Subject: add context to parser, that would hold local variable info, filename, and line number. mrbc_context argument has been added to mrb_parse_xxx() functions. Normally, you just to need to add NULL (or 0) to the last argument of the above functions. --- include/mruby/compile.h | 37 +++++++++++++++++------- src/parse.y | 77 +++++++++++++++++++++++++++++++++++++------------ test/driver.c | 12 ++------ tools/mrbc/mrbc.c | 2 +- tools/mruby/mruby.c | 15 +++++----- 5 files changed, 95 insertions(+), 48 deletions(-) (limited to 'test') diff --git a/include/mruby/compile.h b/include/mruby/compile.h index 2ea141da8..401f52854 100644 --- a/include/mruby/compile.h +++ b/include/mruby/compile.h @@ -14,13 +14,26 @@ extern "C" { #include "mruby.h" #include #include +#include + +/* load context */ +typedef struct mrbc_context { + mrb_sym *syms; + int slen; + char *filename; + int lineno; +} mrbc_context; + +mrbc_context* mrbc_context_new(mrb_state *mrb); +void mrbc_context_free(mrb_state *mrb, mrbc_context *cxt); +const char *mrbc_filename(mrb_state *mrb, mrbc_context *c, const char *s); +/* AST node structure */ typedef struct mrb_ast_node { struct mrb_ast_node *car, *cdr; } mrb_ast_node; -#include - +/* lexer states */ enum mrb_lex_state_enum { EXPR_BEG, /* ignore newline, +/- is a sign. */ EXPR_END, /* newline significant, +/- is an operator. */ @@ -36,21 +49,23 @@ enum mrb_lex_state_enum { EXPR_MAX_STATE }; +/* saved error message */ struct mrb_parser_message { int lineno; int column; char* message; }; +/* parser structure */ struct mrb_parser_state { mrb_state *mrb; struct mrb_pool *pool; mrb_ast_node *cells; const char *s, *send; FILE *f; + char *filename; int lineno; int column; - const char *filename; enum mrb_lex_state_enum lstate; int sterm; @@ -59,6 +74,8 @@ struct mrb_parser_state { unsigned int cmdarg_stack; int paren_nest; int lpar_beg; + int in_def, in_single, cmd_start; + mrb_ast_node *locals; mrb_ast_node *pb; char buf[1024]; @@ -66,9 +83,6 @@ struct mrb_parser_state { mrb_ast_node *heredoc; - int in_def, in_single, cmd_start; - mrb_ast_node *locals; - void *ylval; int nerr; @@ -82,22 +96,23 @@ struct mrb_parser_state { jmp_buf jmp; }; -/* parser structure */ struct mrb_parser_state* mrb_parser_new(mrb_state*); const char *mrb_parser_filename(struct mrb_parser_state*, const char*); -int mrb_parser_lineno(struct mrb_parser_state*, int); void mrb_parser_parse(struct mrb_parser_state*); /* utility functions */ -struct mrb_parser_state* mrb_parse_file(mrb_state*,FILE*); -struct mrb_parser_state* mrb_parse_string(mrb_state*,const char*); -struct mrb_parser_state* mrb_parse_nstring(mrb_state*,const char*,int); +struct mrb_parser_state* mrb_parse_file(mrb_state*,FILE*,mrbc_context*); +struct mrb_parser_state* mrb_parse_string(mrb_state*,const char*,mrbc_context*); +struct mrb_parser_state* mrb_parse_nstring(mrb_state*,const char*,int,mrbc_context*); int mrb_generate_code(mrb_state*, mrb_ast_node*); /* program load functions */ mrb_value mrb_load_file(mrb_state*,FILE*); mrb_value mrb_load_string(mrb_state *mrb, const char *path); mrb_value mrb_load_nstring(mrb_state *mrb, const char *path, int len); +mrb_value mrb_load_file_cxt(mrb_state*,FILE*, mrbc_context *cxt); +mrb_value mrb_load_string_cxt(mrb_state *mrb, const char *path, mrbc_context *cxt); +mrb_value mrb_load_nstring_cxt(mrb_state *mrb, const char *path, int len, mrbc_context *cxt); #if defined(__cplusplus) } /* extern "C" { */ diff --git a/src/parse.y b/src/parse.y index 7f40534b9..78d7d7a7e 100644 --- a/src/parse.y +++ b/src/parse.y @@ -4730,7 +4730,6 @@ mrb_parser_new(mrb_state *mrb) p->in_def = p->in_single = FALSE; p->capture_errors = 0; - p->lineno = 1; p->column = 0; #if defined(PARSER_TEST) || defined(PARSER_DEBUG) @@ -4740,33 +4739,56 @@ mrb_parser_new(mrb_state *mrb) return p; } +mrbc_context* +mrbc_context_new(mrb_state *mrb) +{ + mrbc_context *c; + + c = mrb_malloc(mrb, sizeof(mrbc_context)); + memset(c, 0, sizeof(mrbc_context)); + return c; +} + +void +mrbc_context_free(mrb_state *mrb, mrbc_context *cxt) +{ + mrb_free(mrb, cxt->syms); + mrb_free(mrb, cxt->filename); + mrb_free(mrb, cxt); +} + const char* -mrb_parser_filename(parser_state *p, const char *s) +mrbc_filename(mrb_state *mrb, mrbc_context *c, const char *s) { if (s) { - p->filename = strdup(s); + int len = strlen(s); + char *p = mrb_malloc(mrb, len); + + memcpy(p, s, len); + if (c->filename) mrb_free(mrb, c->filename); + c->filename = p; + c->lineno = 1; } - return p->filename; + return c->filename; } -int -mrb_parser_lineno(struct mrb_parser_state *p, int n) +static void +parser_init_cxt(parser_state *p, mrbc_context *cxt) { - if (n <= 0) { - return p->lineno; + if (cxt) { + if (cxt->lineno) p->lineno = cxt->lineno; + if (cxt->filename) p->filename = cxt->filename; } - p->column = 0; - p->lineno = n; - return n; } parser_state* -mrb_parse_file(mrb_state *mrb, FILE *f) +mrb_parse_file(mrb_state *mrb, FILE *f, mrbc_context *c) { parser_state *p; p = mrb_parser_new(mrb); if (!p) return 0; + parser_init_cxt(p, c); p->s = p->send = NULL; p->f = f; @@ -4775,12 +4797,13 @@ mrb_parse_file(mrb_state *mrb, FILE *f) } parser_state* -mrb_parse_nstring(mrb_state *mrb, const char *s, int len) +mrb_parse_nstring(mrb_state *mrb, const char *s, int len, mrbc_context *c) { parser_state *p; p = mrb_parser_new(mrb); if (!p) return 0; + parser_init_cxt(p, c); p->s = s; p->send = s + len; @@ -4789,9 +4812,9 @@ mrb_parse_nstring(mrb_state *mrb, const char *s, int len) } parser_state* -mrb_parse_string(mrb_state *mrb, const char *s) +mrb_parse_string(mrb_state *mrb, const char *s, mrbc_context *c) { - return mrb_parse_nstring(mrb, s, strlen(s)); + return mrb_parse_nstring(mrb, s, strlen(s), c); } static mrb_value @@ -4817,22 +4840,40 @@ load_exec(mrb_state *mrb, parser_state *p) return mrb_run(mrb, mrb_proc_new(mrb, mrb->irep[n]), mrb_top_self(mrb)); } +mrb_value +mrb_load_file_cxt(mrb_state *mrb, FILE *f, mrbc_context *c) +{ + return load_exec(mrb, mrb_parse_file(mrb, f, c)); +} + mrb_value mrb_load_file(mrb_state *mrb, FILE *f) { - return load_exec(mrb, mrb_parse_file(mrb, f)); + return mrb_load_file_cxt(mrb, f, NULL); +} + +mrb_value +mrb_load_nstring_cxt(mrb_state *mrb, const char *s, int len, mrbc_context *c) +{ + return load_exec(mrb, mrb_parse_nstring(mrb, s, len, c)); } mrb_value mrb_load_nstring(mrb_state *mrb, const char *s, int len) { - return load_exec(mrb, mrb_parse_nstring(mrb, s, len)); + return mrb_load_nstring_cxt(mrb, s, len, NULL); +} + +mrb_value +mrb_load_string_cxt(mrb_state *mrb, const char *s, mrbc_context *c) +{ + return load_exec(mrb, mrb_parse_nstring(mrb, s, strlen(s), c)); } mrb_value mrb_load_string(mrb_state *mrb, const char *s) { - return load_exec(mrb, mrb_parse_nstring(mrb, s, strlen(s))); + return mrb_load_string_cxt(mrb, s, NULL); } void parser_dump(mrb_state *mrb, node *tree, int offset); diff --git a/test/driver.c b/test/driver.c index 6b42d025b..6b1697f14 100644 --- a/test/driver.c +++ b/test/driver.c @@ -42,16 +42,8 @@ main(void) } mrb_init_mrbtest(mrb); - parser = mrb_parse_nstring(mrb, prog, strlen(prog)); - - /* generate bytecode */ - byte_code = mrb_generate_code(mrb, parser->tree); - - /* evaluate the bytecode */ - return_value = mrb_run(mrb, - /* pass a proc for evaulation */ - mrb_proc_new(mrb, mrb->irep[byte_code]), - mrb_top_self(mrb)); + /* evaluate the test */ + return_value = mrb_load_string(mrb, prog); /* did an exception occur? */ if (mrb->exc) { mrb_p(mrb, return_value); diff --git a/tools/mrbc/mrbc.c b/tools/mrbc/mrbc.c index 99fea76d8..9b69244e5 100644 --- a/tools/mrbc/mrbc.c +++ b/tools/mrbc/mrbc.c @@ -172,7 +172,7 @@ main(int argc, char **argv) return n; } - p = mrb_parse_file(mrb, args.rfp); + p = mrb_parse_file(mrb, args.rfp, NULL); if (!p || !p->tree || p->nerr) { cleanup(&args); mrb_close(mrb); diff --git a/tools/mruby/mruby.c b/tools/mruby/mruby.c index 5cf3d8a37..b4b37516b 100644 --- a/tools/mruby/mruby.c +++ b/tools/mruby/mruby.c @@ -165,17 +165,16 @@ main(int argc, char **argv) n = mrb_load_irep(mrb, args.rfp); } else { + mrbc_context *c = mrbc_context_new(mrb); if (args.cmdline) { - p = mrb_parse_string(mrb, (char*)args.cmdline); - } + mrbc_filename(mrb, c, "-e"); + p = mrb_parse_string(mrb, (char*)args.cmdline, c); + } else { - p = mrb_parser_new(mrb); - if (p) { - mrb_parser_filename(p, argv[1]); - p->f = args.rfp; - mrb_parser_parse(p); - } + mrbc_filename(mrb, c, argv[1]); + p = mrb_parse_file(mrb, args.rfp, c); } + mrbc_context_free(mrb, c); if (!p || !p->tree || p->nerr) { cleanup(mrb, &args); return -1; -- cgit v1.2.3 From e81449557646b184e6367706273e8c0b4c53668d Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Tue, 3 Jul 2012 21:04:25 +0900 Subject: test/driver to use EXIT_SUCCESS --- test/driver.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/driver.c b/test/driver.c index 6b1697f14..03479bcf4 100644 --- a/test/driver.c +++ b/test/driver.c @@ -54,5 +54,5 @@ main(void) } mrb_close(mrb); - return 0; + return EXIT_SUCCESS; } -- cgit v1.2.3 From cd1e1a008987d61d06bbef99e9341738b36f3313 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Tue, 3 Jul 2012 21:33:20 +0900 Subject: remove unused variables --- test/driver.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'test') diff --git a/test/driver.c b/test/driver.c index 03479bcf4..4fe58432d 100644 --- a/test/driver.c +++ b/test/driver.c @@ -26,10 +26,8 @@ void print_hint(void) int main(void) { - struct mrb_parser_state *parser; mrb_state *mrb; mrb_value return_value; - int byte_code; const char *prog = "report()"; print_hint(); -- cgit v1.2.3 From becb7e98779914cdb1e5703ffe01ce408910523f Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Sun, 8 Jul 2012 00:19:40 +0900 Subject: .. is weaker than == --- test/t/bs_block.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/t/bs_block.rb b/test/t/bs_block.rb index 084d3b30f..654a9ba5c 100644 --- a/test/t/bs_block.rb +++ b/test/t/bs_block.rb @@ -66,7 +66,7 @@ assert('BS Block 7') do a = [m, n] ans << a end - end == 1..3 + end == (1..3) end assert('BS Block 8') do -- cgit v1.2.3 From 0d99856b57f172948c4e579c8f96cc19aa3d8568 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Sun, 8 Jul 2012 00:20:56 +0900 Subject: proper type check when creating a range; #345 --- src/range.c | 58 ++++++++++++++++++++++++------------------------------ test/t/bs_block.rb | 2 +- 2 files changed, 27 insertions(+), 33 deletions(-) (limited to 'test') diff --git a/src/range.c b/src/range.c index 34ca79a0d..a26d38e22 100644 --- a/src/range.c +++ b/src/range.c @@ -21,6 +21,30 @@ #define RANGE_CLASS (mrb_class_obj_get(mrb, "Range")) +static void +range_check(mrb_state *mrb, mrb_value a, mrb_value b) +{ + mrb_value ans; + + switch (mrb_type(a)) { + case MRB_TT_FIXNUM: + case MRB_TT_FLOAT: + switch (mrb_type(b)) { + case MRB_TT_FIXNUM: + case MRB_TT_FLOAT: + return; + } + } + + mrb_p(mrb, a); + mrb_p(mrb, b); + ans = mrb_funcall(mrb, a, "<=>", 1, b); + if (mrb_nil_p(ans)) { + /* can not be compared */ + mrb_raise(mrb, E_ARGUMENT_ERROR, "bad value for range"); + } +} + mrb_value mrb_range_new(mrb_state *mrb, mrb_value beg, mrb_value end, int excl) { @@ -28,6 +52,7 @@ mrb_range_new(mrb_state *mrb, mrb_value beg, mrb_value end, int excl) r = (struct RRange*)mrb_obj_alloc(mrb, MRB_TT_RANGE, RANGE_CLASS); r->edges = mrb_malloc(mrb, sizeof(struct mrb_range_edges)); + range_check(mrb, beg, end); r->edges->beg = beg; r->edges->end = end; r->excl = excl; @@ -82,39 +107,12 @@ mrb_range_excl(mrb_state *mrb, mrb_value range) return r->excl ? mrb_true_value() : mrb_false_value(); } -/* - * call-seq: - * beg end - * args[0] <= args[1] => true - * args[0] > args[1] => false - */ -static int -range_check(mrb_state *mrb, mrb_value *args) -{ - mrb_value ans = mrb_funcall(mrb, args[0], "<=>", 1, args[1]); - /* beg end - ans :args[0] < args[1] => -1 - args[0] = args[1] => 0 - args[0] > args[1] => +1 */ - if (mrb_nil_p(ans)) return FALSE; - //if (mrb_obj_equal(mrb, ans, mrb_fixnum_value(1))) return FALSE; - if (mrb_fixnum(ans) == 1) return FALSE; - return TRUE; -} - static void range_init(mrb_state *mrb, mrb_value range, mrb_value beg, mrb_value end, mrb_int exclude_end) { - mrb_value args[2]; struct RRange *r = mrb_range_ptr(range); - if ((mrb_type(beg) != MRB_TT_FIXNUM) || (mrb_type(end) != MRB_TT_FIXNUM)) { - args[0] = beg; - args[1] = end; - if (!range_check(mrb, args)) { - printf("range_failed()\n"); - } - } + range_check(mrb, beg, end); r->excl = exclude_end; r->edges->beg = beg; r->edges->end = end; @@ -166,7 +164,6 @@ mrb_range_eq(mrb_state *mrb, mrb_value range) if (mrb_obj_equal(mrb, range, obj)) return mrb_true_value(); /* same class? */ - // if (!rb_obj_is_instance_of(obj, rb_obj_class(range))) if (!mrb_obj_is_instance_of(mrb, obj, mrb_obj_class(mrb, range))) return mrb_false_value(); @@ -199,12 +196,10 @@ r_le(mrb_state *mrb, mrb_value a, mrb_value b) static int r_gt(mrb_state *mrb, mrb_value a, mrb_value b) { - //int c; mrb_value r = mrb_funcall(mrb, a, "<=>", 1, b); /* output :a < b => -1, a = b => 0, a > b => +1 */ if (mrb_nil_p(r)) return FALSE; - if (mrb_obj_equal(mrb, r, mrb_fixnum_value(1))) return TRUE; return FALSE; } @@ -212,7 +207,6 @@ r_gt(mrb_state *mrb, mrb_value a, mrb_value b) static int r_ge(mrb_state *mrb, mrb_value a, mrb_value b) { - //int c; mrb_value r = mrb_funcall(mrb, a, "<=>", 1, b); /* compare result */ /* output :a < b => -1, a = b => 0, a > b => +1 */ diff --git a/test/t/bs_block.rb b/test/t/bs_block.rb index 654a9ba5c..bef9a8564 100644 --- a/test/t/bs_block.rb +++ b/test/t/bs_block.rb @@ -62,7 +62,7 @@ end assert('BS Block 7') do ans = [] for m in 1..3 - for n in 1..3 + for n in 2..4 a = [m, n] ans << a end -- cgit v1.2.3 From 0c10becf91cdd584a8072501a514695aaa049ec2 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Sun, 8 Jul 2012 04:44:55 +0800 Subject: Add tests for Modules #append_features, #include, #included and #included_modules --- test/t/module.rb | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 54 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/t/module.rb b/test/t/module.rb index 95fbb7a86..63c2e7dc8 100644 --- a/test/t/module.rb +++ b/test/t/module.rb @@ -9,6 +9,23 @@ assert('Module superclass', '15.2.2.2') do Module.superclass == Object end +# TODO not implemented ATM assert('Module.constants', '15.2.2.3.1') do + +# TODO not implemented ATM assert('Module.nesting', '15.2.2.3.2') do + +assert('Module#append_features', '15.2.2.4.10') do + module Test4AppendFeatures + def self.append_features(mod) + Test4AppendFeatures2.const_set(:Const4AppendFeatures2, mod) + end + end + module Test4AppendFeatures2 + include Test4AppendFeatures + end + + Test4AppendFeatures2.const_get(:Const4AppendFeatures2) == Test4AppendFeatures2 +end + assert('Module#const_defined?', '15.2.2.4.20') do module Test4ConstDefined Const4Test4ConstDefined = true @@ -56,6 +73,41 @@ assert('Module#const_get', '15.2.2.4.23') do Test4ConstSet.const_get(:Const4Test4ConstSet) == 23 end -# TODO not implemented ATM assert('Module.constants', '15.2.2') do +assert('Module#include', '15.2.2.4.27') do + module Test4Include + Const4Include = 42 + end + module Test4Include2 + include Test4Include + end + + Test4Include2.const_get(:Const4Include) == 42 +end + +assert('Module#included', '15.2.2.4.29') do + module Test4Included + Const4Included = 42 + def Test4Included.included mod + Test4Included.const_set(:Const4Included2, mod) + end + end + module Test4Included2 + include Test4Included + end + + Test4Included2.const_get(:Const4Included) == 42 and + Test4Included2.const_get(:Const4Included2) == Test4Included2 +end + +assert('Module#included_modules', '15.2.2.4.30') do + r1 = true + module Test4includedModules + Const4Included = 42 + end + module Test4includedModules2 + r1 = included Test4includedModules + end + + Test4includedModules2.included_modules.class == Array +end -# TODO not implemented ATM assert('Module.nesting', '15.2.2') do -- cgit v1.2.3 From e8b53090803caef8b20ff6f7cc17e3eb472a521e Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Tue, 10 Jul 2012 15:11:31 +0800 Subject: Add a Test Case for #359 Array Corruption --- test/t/array.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'test') diff --git a/test/t/array.rb b/test/t/array.rb index 3f441c1cc..a1ef830a2 100644 --- a/test/t/array.rb +++ b/test/t/array.rb @@ -243,3 +243,11 @@ assert('Array#to_s', '15.2.12.5.31') do end # Not ISO specified + +assert("Array (Shared Array Corruption)") do + a = [ "a", "b", "c", "d", "e", "f" ] + b = a.slice(1, 3) + a.clear + b.clear +end + -- cgit v1.2.3 From 8020c280aa88354d797bdaf754c7beeb42dabab4 Mon Sep 17 00:00:00 2001 From: Masamitsu MURASE Date: Tue, 17 Jul 2012 00:56:18 +0900 Subject: Add test for Kernel#extend. --- test/t/kernel.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'test') diff --git a/test/t/kernel.rb b/test/t/kernel.rb index 5aa7672d7..4f1d2b42f 100644 --- a/test/t/kernel.rb +++ b/test/t/kernel.rb @@ -187,6 +187,21 @@ assert('Kernel#dup', '15.3.1.3.9') do c.respond_to?(:test) == false end +assert('Kernel#extend', '15.3.1.3.13') do + class Test4ExtendClass + end + + module Test4ExtendModule + def test_method; end + end + + a = Test4ExtendClass.new + a.extend(Test4ExtendModule) + b = Test4ExtendClass.new + + a.respond_to?(:test_method) == true && b.respond_to?(:test_method) == false +end + assert('Kernel#global_variables', '15.3.1.3.14') do global_variables.class == Array end -- cgit v1.2.3 From 526dd09b7a7bbaaddfe4d73b5d407409d518742d Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Tue, 17 Jul 2012 01:33:40 +0900 Subject: add Module#ancestors 15.2.2.4.9 --- src/class.c | 21 +++++++++++++++++++++ test/t/module.rb | 14 +++++++++----- 2 files changed, 30 insertions(+), 5 deletions(-) (limited to 'test') diff --git a/src/class.c b/src/class.c index 1409c0b33..976642224 100644 --- a/src/class.c +++ b/src/class.c @@ -720,6 +720,26 @@ mrb_mod_include(mrb_state *mrb, mrb_value klass) return klass; } +static mrb_value +mrb_mod_ancestors(mrb_state *mrb, mrb_value self) +{ + mrb_value result; + struct RClass *c = mrb_class_ptr(self); + + result = mrb_ary_new(mrb); + while (c) { + if (c->tt == MRB_TT_ICLASS) { + mrb_ary_push(mrb, result, mrb_obj_value(c->c)); + } + else { + mrb_ary_push(mrb, result, mrb_obj_value(c)); + } + c = c->super; + } + + return result; +} + static mrb_value mrb_mod_included_modules(mrb_state *mrb, mrb_value self) { @@ -1400,6 +1420,7 @@ mrb_init_class(mrb_state *mrb) mrb_define_method(mrb, mod, "to_s", mrb_mod_to_s, ARGS_NONE()); mrb_define_method(mrb, mod, "alias_method", mrb_mod_alias, ARGS_ANY()); /* 15.2.2.4.8 */ + mrb_define_method(mrb, mod, "ancestors", mrb_mod_ancestors, ARGS_NONE()); /* 15.2.2.4.9 */ mrb_define_method(mrb, mod, "undef_method", mrb_mod_undef, ARGS_ANY()); /* 15.2.2.4.41 */ mrb_define_method(mrb, mod, "const_defined?", mrb_mod_const_defined, ARGS_REQ(1)); /* 15.2.2.4.20 */ mrb_define_method(mrb, mod, "const_get", mrb_mod_const_get, ARGS_REQ(1)); /* 15.2.2.4.21 */ diff --git a/test/t/module.rb b/test/t/module.rb index 63c2e7dc8..0e5abff81 100644 --- a/test/t/module.rb +++ b/test/t/module.rb @@ -13,6 +13,12 @@ end # TODO not implemented ATM assert('Module.nesting', '15.2.2.3.2') do +assert('Module#ancestors', '15.2.2.4.9') do + + r = String.ancestors + r.class == Array and r.include?(String) and r.include?(Object) +end + assert('Module#append_features', '15.2.2.4.10') do module Test4AppendFeatures def self.append_features(mod) @@ -100,14 +106,12 @@ assert('Module#included', '15.2.2.4.29') do end assert('Module#included_modules', '15.2.2.4.30') do - r1 = true module Test4includedModules - Const4Included = 42 end module Test4includedModules2 - r1 = included Test4includedModules + include Test4includedModules end - Test4includedModules2.included_modules.class == Array + r = Test4includedModules2.included_modules + r.class == Array and r.include?(Test4includedModules) end - -- cgit v1.2.3 From 6696876e729a99a0a54e0989ef38361687fb0b5d Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Tue, 17 Jul 2012 02:01:52 +0900 Subject: refactoring on module tests --- test/t/module.rb | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) (limited to 'test') diff --git a/test/t/module.rb b/test/t/module.rb index 0e5abff81..5b847e8b7 100644 --- a/test/t/module.rb +++ b/test/t/module.rb @@ -14,7 +14,6 @@ end # TODO not implemented ATM assert('Module.nesting', '15.2.2.3.2') do assert('Module#ancestors', '15.2.2.4.9') do - r = String.ancestors r.class == Array and r.include?(String) and r.include?(Object) end @@ -53,21 +52,12 @@ assert('Module.const_missing', '15.2.2.4.22') do e1 = nil module Test4ConstMissing - def const_missing(sym) - # ATM this redirect doesn't work - puts "PLEASE GO TO TEST CASE Module.const_missing!" - puts "IT IS WORKING NOW!! PLEASE FINALIZE." - puts "Thanks :)" + def self.const_missing(sym) + 42 # the answer to everything end end - begin - Test4ConstMissing.const_get(:ConstDoesntExist) - rescue => e2 - e1 = e2 - end - - e1.class == NameError + Test4ConstMissing.const_get(:ConstDoesntExist) == 42 end assert('Module#const_get', '15.2.2.4.23') do @@ -93,7 +83,7 @@ end assert('Module#included', '15.2.2.4.29') do module Test4Included Const4Included = 42 - def Test4Included.included mod + def self.included mod Test4Included.const_set(:Const4Included2, mod) end end -- cgit v1.2.3 From 6f2aefae1f6032be5c7a7ba82734543b90be5ccc Mon Sep 17 00:00:00 2001 From: Masamitsu MURASE Date: Wed, 18 Jul 2012 02:23:16 +0900 Subject: Add test for 'respond_to?'. --- test/t/kernel.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/t/kernel.rb b/test/t/kernel.rb index 4f1d2b42f..6e68b1b22 100644 --- a/test/t/kernel.rb +++ b/test/t/kernel.rb @@ -300,7 +300,12 @@ assert('Kernel#raise', '15.3.1.3.40') do end assert('Kernel#respond_to?', '15.3.1.3.43') do - respond_to? :nil? + class Test4RespondTo + def test_method; end + undef test_method + end + + respond_to?(:nil?) and Test4RespondTo.new.respond_to?(:test_method) == false end assert('Kernel#send', '15.3.1.3.44') do -- cgit v1.2.3 From e6f1e7b899e25c523a43fab59d7f536877bd05ce Mon Sep 17 00:00:00 2001 From: Masamitsu MURASE Date: Wed, 18 Jul 2012 02:25:34 +0900 Subject: Add tests for Kernel#lambda and Kernel.lambda. --- test/t/kernel.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/t/kernel.rb b/test/t/kernel.rb index 4f1d2b42f..da818778a 100644 --- a/test/t/kernel.rb +++ b/test/t/kernel.rb @@ -36,7 +36,9 @@ assert('Kernel.lambda', '15.3.1.2.6') do true end - l.call and l.class == Proc + m = Kernel.lambda(&l) + + l.call and l.class == Proc and m.call and m.class == Proc end # Not implemented at the moment @@ -235,7 +237,9 @@ assert('Kernel#lambda', '15.3.1.3.27') do true end - l.call and l.class == Proc + m = lambda(&l) + + l.call and l.class == Proc and m.call and m.class == Proc end # Not implemented yet -- cgit v1.2.3 From 9dd3ac36d1ae16fffb1902e9d459c1bf9aec86a4 Mon Sep 17 00:00:00 2001 From: Akira Kuroda Date: Sun, 22 Jul 2012 21:06:38 +0900 Subject: add test cases for floor, inifinite?, truncate, ceil, and round --- test/t/float.rb | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) (limited to 'test') diff --git a/test/t/float.rb b/test/t/float.rb index 5c5245c73..30b470272 100644 --- a/test/t/float.rb +++ b/test/t/float.rb @@ -65,7 +65,11 @@ assert('Float#==', '15.2.9.3.7') do end assert('Float#ceil', '15.2.9.3.8') do - 3.123456789.ceil == 4 + a = 3.123456789.ceil + b = 3.0.ceil + c = -3.123456789.ceil + d = -3.0.ceil + a == 4 and b == 3 and c == -3 and d == -3 end assert('Float#finite?', '15.2.9.3.9') do @@ -74,20 +78,34 @@ assert('Float#finite?', '15.2.9.3.9') do end assert('Float#floor', '15.2.9.3.10') do - 3.123456789.floor == 3 + a = 3.123456789.floor + b = 3.0.floor + c = -3.123456789.floor + d = -3.0.floor + a == 3 and b == 3 and c == -4 and d == -3 end assert('Float#infinite?', '15.2.9.3.11') do - not 3.123456789.infinite? and - (1.0 / 0.0).infinite? + a = 3.123456789.infinite? + b = (1.0 / 0.0).infinite? + c = (-1.0 / 0.0).infinite? + + a == nil and b == 1 and c == -1 end assert('Float#round', '15.2.9.3.12') do a = 3.123456789.round b = 3.5.round c = 3.499999999.round + d = (-3.123456789).round + e = (-3.5).round + f = 12345.67.round(-1) + g = 3.123456789.round(0) + h = 3.123456789.round(1) + i = 3.123456789.round(4) - a == 3 and b == 4 and c == 3 + a == 3 and b == 4 and c == 3 and d == -3 and e == -4 and + f == 12350 and g == 3 and h == 3.1 and i == 3.1235 end assert('Float#to_f', '15.2.9.3.13') do @@ -101,5 +119,5 @@ assert('Float#to_i', '15.2.9.3.14') do end assert('Float#truncate', '15.2.9.3.15') do - 3.123456789.truncate == 3 + 3.123456789.truncate == 3 and -3.1.truncate == -3 end -- cgit v1.2.3 From f114e3e25236cd43d2f71419e4929caaa755020e Mon Sep 17 00:00:00 2001 From: Akira Kuroda Date: Wed, 25 Jul 2012 00:05:51 +0900 Subject: fix segmentation fault in Array#last --- src/array.c | 3 +++ test/t/array.rb | 10 +++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/src/array.c b/src/array.c index ed1c3f475..0f52c38ef 100644 --- a/src/array.c +++ b/src/array.c @@ -789,6 +789,9 @@ mrb_ary_last(mrb_state *mrb, mrb_value self) /* len == 1 */ size = mrb_fixnum(*vals); + if (size < 0) { + mrb_raise(mrb, E_ARGUMENT_ERROR, "negative array size"); + } if (size > a->len) size = a->len; if ((a->flags & MRB_ARY_SHARED) || size > ARY_DEFAULT_LEN) { return ary_subseq(mrb, a, a->len - size, size); diff --git a/test/t/array.rb b/test/t/array.rb index a1ef830a2..4ed12a58f 100644 --- a/test/t/array.rb +++ b/test/t/array.rb @@ -152,7 +152,15 @@ end assert('Array#last', '15.2.12.5.18') do a = [1,2,3] - a.last == 3 and [].last == nil + e2 = nil + begin + # this will cause an exception due to the wrong argument + [1,2,3].last(-1) + rescue => e1 + e2 = e1 + end + + a.last == 3 and [].last == nil and e2.class == ArgumentError end assert('Array#length', '15.2.12.5.19') do -- cgit v1.2.3 From 1cda5e0768e6d57db30a82f343d6aff2c6bc6b24 Mon Sep 17 00:00:00 2001 From: Masaki Muranaka Date: Wed, 25 Jul 2012 16:13:44 +0900 Subject: Add tests for coverage. --- test/t/array.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'test') diff --git a/test/t/array.rb b/test/t/array.rb index a1ef830a2..a113df1f4 100644 --- a/test/t/array.rb +++ b/test/t/array.rb @@ -65,6 +65,7 @@ assert('Array#[]=', '15.2.12.5.5') do end [1,2,3].[]=(1,4) == [1, 4, 3] and + [1,2,3].[]=(1,2,3) == [1, 3] and e2.class == ArgumentError and e3.class == ArgumentError end @@ -242,6 +243,21 @@ assert('Array#to_s', '15.2.12.5.31') do r1 == r2 and r1 == "[2, 3, 4, 5]" end +assert('Array#==', '15.2.12.5.33') do + r1 = [ "a", "c" ] == [ "a", "c", 7 ] #=> false + r2 = [ "a", "c", 7 ] == [ "a", "c", 7 ] #=> true + r3 = [ "a", "c", 7 ] == [ "a", "d", "f" ] #=> false + + r1 == false and r2 == true and r3 == false +end + +assert('Array#<=>', '15.2.12.5.36') do + r1 = [ "a", "a", "c" ] <=> [ "a", "b", "c" ] #=> -1 + r2 = [ 1, 2, 3, 4, 5, 6 ] <=> [ 1, 2 ] #=> +1 + + r1 == -1 and r2 == +1 +end + # Not ISO specified assert("Array (Shared Array Corruption)") do -- cgit v1.2.3 From 344946233c7070d22f0b654a191ad20b0f92a1a0 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Thu, 26 Jul 2012 23:00:34 +0900 Subject: do not use TrueClass/FalseClass.new --- test/t/false.rb | 8 ++++---- test/t/true.rb | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'test') diff --git a/test/t/false.rb b/test/t/false.rb index ae605205d..50ba5623a 100644 --- a/test/t/false.rb +++ b/test/t/false.rb @@ -14,17 +14,17 @@ assert('FalseClass false', '15.2.6.1') do end assert('FalseClass#&', '15.2.6.3.1') do - not FalseClass.new.&(true) and not FalseClass.new.&(false) + not false.&(true) and not false.&(false) end assert('FalseClass#^', '15.2.6.3.2') do - FalseClass.new.^(true) and not FalseClass.new.^(false) + false.^(true) and not false.^(false) end assert('FalseClass#to_s', '15.2.6.3.3') do - FalseClass.new.to_s == 'false' + false.to_s == 'false' end assert('FalseClass#|', '15.2.6.3.4') do - FalseClass.new.|(true) and not FalseClass.new.|(false) + false.|(true) and not false.|(false) end diff --git a/test/t/true.rb b/test/t/true.rb index 2662f7cd8..ae83e0baa 100644 --- a/test/t/true.rb +++ b/test/t/true.rb @@ -14,17 +14,17 @@ assert('TrueClass true', '15.2.5.1') do end assert('TrueClass#&', '15.2.5.3.1') do - TrueClass.new.&(true) and not TrueClass.new.&(false) + true.&(true) and not true.&(false) end assert('TrueClass#^', '15.2.5.3.2') do - not TrueClass.new.^(true) and TrueClass.new.^(false) + not true.^(true) and true.^(false) end assert('TrueClass#to_s', '15.2.5.3.3') do - TrueClass.new.to_s == 'true' + true.to_s == 'true' end assert('TrueClass#|', '15.2.5.3.4') do - TrueClass.new.|(true) and TrueClass.new.|(false) + true.|(true) and true.|(false) end -- cgit v1.2.3 From a2aa7e7f520b42a2de393039bd8d468dbd299026 Mon Sep 17 00:00:00 2001 From: Akira Kuroda Date: Sun, 29 Jul 2012 00:21:40 +0900 Subject: fix segmentation fault in Array#first --- src/array.c | 3 +++ test/t/array.rb | 19 ++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/src/array.c b/src/array.c index 0f52c38ef..ccd22674e 100644 --- a/src/array.c +++ b/src/array.c @@ -764,6 +764,9 @@ mrb_ary_first(mrb_state *mrb, mrb_value self) if (mrb_get_args(mrb, "|i", &size) == 0) { return (a->len > 0)? a->ptr[0]: mrb_nil_value(); } + if (size < 0) { + mrb_raise(mrb, E_ARGUMENT_ERROR, "negative array size"); + } if (size > a->len) size = a->len; if (a->flags & MRB_ARY_SHARED) { diff --git a/test/t/array.rb b/test/t/array.rb index 7029cd3c6..cb99cea6a 100644 --- a/test/t/array.rb +++ b/test/t/array.rb @@ -118,7 +118,24 @@ assert('Array#first', '15.2.12.5.13') do a = [] b = [1,2,3] - a.first == nil and b.first == 1 + e2 = nil + e3 = nil + begin + # this will cause an exception due to the wrong argument + [1,2,3].first(-1) + rescue => e1 + e2 = e1 + end + begin + # this will cause an exception due to the wrong argument + [1,2,3].first(1,2) + rescue => e1 + e3 = e1 + end + + a.first == nil and b.first == 1 and b.first(0) == [] and + b.first(1) == [1] and b.first(4) == [1,2,3] and + e2.class == ArgumentError and e3.class == ArgumentError end assert('Array#index', '15.2.12.5.14') do -- cgit v1.2.3 From b71063b239cbbdbdd6779d7b590c0cad59e0c3ae Mon Sep 17 00:00:00 2001 From: Masamitsu MURASE Date: Sun, 29 Jul 2012 14:02:07 +0900 Subject: Modify test for Class. * Rename some classes in test/t/class.rb to avoid name conflict. * Add tests for mismatch fo superclass. --- test/t/class.rb | 76 +++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 61 insertions(+), 15 deletions(-) (limited to 'test') diff --git a/test/t/class.rb b/test/t/class.rb index 1b809a832..d6c4715dd 100644 --- a/test/t/class.rb +++ b/test/t/class.rb @@ -47,36 +47,82 @@ end # Not ISO specified assert('Class 1') do - class C; end - C.class == Class + class C1; end + C1.class == Class end assert('Class 2') do - class C; end - C.new.class == C + class C2; end + C2.new.class == C2 end assert('Class 3') do - class C; end - C.new.class.class == Class + class C3; end + C3.new.class.class == Class end assert('Class 4') do - class A; end - class C < A; end - C.class == Class + class C4_A; end + class C4 < C4_A; end + C4.class == Class end assert('Class 5') do - class A; end - class C < A; end - C.new.class == C + class C5_A; end + class C5 < C5_A; end + C5.new.class == C5 end assert('Class 6') do - class A; end - class C < A; end - C.new.class.class == Class + class C6_A; end + class C6 < C6_A; end + C6.new.class.class == Class +end + +assert('Class 7') do + class C7_A; end + class C7_B; end + + class C7 < C7_A; end + + error = false + begin + # Different superclass. + class C7 < C7_B; end + rescue TypeError + error = true + end + + error +end + +assert('Class 8') do + class C8_A; end + + class C8; end # superclass is Object + + error = false + begin + # Different superclass. + class C8 < C8_A; end + rescue TypeError + error = true + end + + error +end + +assert('Class 9') do + Class9Const = "a" + + error = false + begin + class Class9Const; end + rescue TypeError + error = true + end + + error end assert('Class Module 1') do -- cgit v1.2.3 From d5bcaafd9167be0942f46ffa6a67c7ea673bdf8b Mon Sep 17 00:00:00 2001 From: Masamitsu MURASE Date: Sun, 29 Jul 2012 18:45:47 +0900 Subject: Modify return value of mrbtest. This is an improvement for CI, such as Travis. --- test/driver.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/driver.c b/test/driver.c index 4fe58432d..d2ad31b26 100644 --- a/test/driver.c +++ b/test/driver.c @@ -11,6 +11,7 @@ #include #include #include +#include void mrb_init_mrbtest(mrb_state *); @@ -23,12 +24,24 @@ void print_hint(void) printf("Thanks :)\n\n"); } +static int +check_error(mrb_state *mrb) +{ + /* Error check */ + /* $ko_test and $kill_test should be 0 */ + mrb_value ko_test = mrb_gv_get(mrb, mrb_intern(mrb, "$ko_test")); + mrb_value kill_test = mrb_gv_get(mrb, mrb_intern(mrb, "$kill_test")); + + return FIXNUM_P(ko_test) && mrb_fixnum(ko_test) == 0 && FIXNUM_P(kill_test) && mrb_fixnum(kill_test) == 0; +} + int main(void) { mrb_state *mrb; mrb_value return_value; const char *prog = "report()"; + int ret = EXIT_SUCCESS; print_hint(); @@ -46,11 +59,12 @@ main(void) if (mrb->exc) { mrb_p(mrb, return_value); mrb->exc = 0; + ret = EXIT_FAILURE; } - else { - /* no */ + else if (!check_error(mrb)) { + ret = EXIT_FAILURE; } mrb_close(mrb); - return EXIT_SUCCESS; + return ret; } -- cgit v1.2.3 From 0270d11c81c28a5616eebd64d10be5133de4d7a0 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Wed, 1 Aug 2012 00:45:12 +0900 Subject: float do not have enough precision to round if MRB_USE_FLOAT is set --- src/numeric.c | 27 ++++++++++++++------------- test/t/float.rb | 34 +++++++++++++++++----------------- 2 files changed, 31 insertions(+), 30 deletions(-) (limited to 'test') diff --git a/src/numeric.c b/src/numeric.c index d294597ee..012e69741 100644 --- a/src/numeric.c +++ b/src/numeric.c @@ -195,7 +195,11 @@ flo_to_s(mrb_state *mrb, mrb_value flt) } else if(isnan(value)) return mrb_str_new(mrb, "NaN", 3); +#ifdef MRB_USE_FLOAT + n = sprintf(buf, "%.7g", value); +#else n = sprintf(buf, "%.14g", value); +#endif assert(n >= 0); return mrb_str_new(mrb, buf, n); } @@ -511,21 +515,13 @@ flo_ceil(mrb_state *mrb, mrb_value num) */ static mrb_value -flo_round(mrb_state *mrb, /*int argc, mrb_value *argv,*/ mrb_value num) +flo_round(mrb_state *mrb, mrb_value num) { - mrb_value nd; - mrb_float number, f; + double number, f; int ndigits = 0, i; - mrb_value *argv; - int argc; - - mrb_get_args(mrb, "*", &argv, &argc); - if (argc == 1) { - nd = argv[0]; - ndigits = mrb_fixnum(nd); - } - number = mrb_float(num); + mrb_get_args(mrb, "|i", &ndigits); + number = mrb_float(num); f = 1.0; i = abs(ndigits); while (--i >= 0) @@ -535,7 +531,7 @@ flo_round(mrb_state *mrb, /*int argc, mrb_value *argv,*/ mrb_value num) if (ndigits < 0) number = 0; } else { - mrb_float d; + double d; if (ndigits < 0) number /= f; else number *= f; @@ -554,6 +550,11 @@ flo_round(mrb_state *mrb, /*int argc, mrb_value *argv,*/ mrb_value num) else number /= f; } + { + mrb_value ff = mrb_float_value(number); + + printf("%f.round(%d) = %f\n", mrb_float(num), ndigits, mrb_float(ff)); + } if (ndigits > 0) return mrb_float_value(number); return mrb_fixnum_value((mrb_int)number); } diff --git a/test/t/float.rb b/test/t/float.rb index 30b470272..e2c139c03 100644 --- a/test/t/float.rb +++ b/test/t/float.rb @@ -26,11 +26,11 @@ assert('Float#-', '15.2.9.3.2') do end assert('Float#*', '15.2.9.3.3') do - a = 3.123456789 * 3.123456789 - b = 3.123456789 * 1 + a = 3.125 * 3.125 + b = 3.125 * 1 - check_float(a, 9.75598231275019) and - check_float(b, 3.123456789) + check_float(a, 9.765625) and + check_float(b, 3.125) end assert('Float#/', '15.2.9.3.4') do @@ -42,19 +42,19 @@ assert('Float#/', '15.2.9.3.4') do end assert('Float#%', '15.2.9.3.5') do - a = 3.123456789 % 3.123456789 - b = 3.123456789 % 1 + a = 3.125 % 3.125 + b = 3.125 % 1 check_float(a, 0.0) and - check_float(b, 0.123456789) + check_float(b, 0.125) end assert('Float#<=>', '15.2.9.3.6') do - a = 3.123456789 <=> 3.123456788 - b = 3.123456789 <=> 3.123456789 - c = 3.123456789 <=> 3.123456790 - a2 = 3.123456789 <=> 3 - c2 = 3.123456789 <=> 4 + a = 3.125 <=> 3.123 + b = 3.125 <=> 3.125 + c = 3.125 <=> 3.126 + a2 = 3.125 <=> 3 + c2 = 3.125 <=> 4 a == 1 and b == 0 and c == -1 and a2 == 1 and c2 == -1 @@ -96,16 +96,16 @@ end assert('Float#round', '15.2.9.3.12') do a = 3.123456789.round b = 3.5.round - c = 3.499999999.round + c = 3.4999.round d = (-3.123456789).round e = (-3.5).round f = 12345.67.round(-1) - g = 3.123456789.round(0) - h = 3.123456789.round(1) - i = 3.123456789.round(4) + g = 3.423456789.round(0) + h = 3.423456789.round(1) + i = 3.423456789.round(3) a == 3 and b == 4 and c == 3 and d == -3 and e == -4 and - f == 12350 and g == 3 and h == 3.1 and i == 3.1235 + f == 12350 and g == 3 and h == 3.4 and i == 3.423 end assert('Float#to_f', '15.2.9.3.13') do -- cgit v1.2.3 From 34cf05679c5ce9ee40be6bd4ccace0ec94fcebdf Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Wed, 1 Aug 2012 01:12:09 +0900 Subject: add Math::TOLERANCE --- src/math.c | 28 +++++++++++++++++----------- test/assert.rb | 3 +-- 2 files changed, 18 insertions(+), 13 deletions(-) (limited to 'test') diff --git a/src/math.c b/src/math.c index 519d4f37b..fe10848c3 100644 --- a/src/math.c +++ b/src/math.c @@ -634,18 +634,24 @@ mrb_init_math(mrb_state *mrb) struct RClass *mrb_math; mrb_math = mrb_define_module(mrb, "Math"); - #ifdef M_PI - mrb_define_const(mrb, mrb_math, "PI", mrb_float_value(M_PI)); - #else - mrb_define_const(mrb, mrb_math, "PI", mrb_float_value(atan(1.0)*4.0)); - #endif - - #ifdef M_E - mrb_define_const(mrb, mrb_math, "E", mrb_float_value(M_E)); - #else - mrb_define_const(mrb, mrb_math, "E", mrb_float_value(exp(1.0))); - #endif +#ifdef M_PI + mrb_define_const(mrb, mrb_math, "PI", mrb_float_value(M_PI)); +#else + mrb_define_const(mrb, mrb_math, "PI", mrb_float_value(atan(1.0)*4.0)); +#endif +#ifdef M_E + mrb_define_const(mrb, mrb_math, "E", mrb_float_value(M_E)); +#else + mrb_define_const(mrb, mrb_math, "E", mrb_float_value(exp(1.0))); +#endif + +#ifdef MRB_USE_FLOAT + mrb_define_const(mrb, mrb_math, "TOLERANCE", mrb_float_value(1e-6)); +#else + mrb_define_const(mrb, mrb_math, "TOLERANCE", mrb_float_value(1e-12)); +#endif + mrb_define_module_function(mrb, mrb_math, "sin", math_sin, ARGS_REQ(1)); mrb_define_module_function(mrb, mrb_math, "cos", math_cos, ARGS_REQ(1)); mrb_define_module_function(mrb, mrb_math, "tan", math_tan, ARGS_REQ(1)); diff --git a/test/assert.rb b/test/assert.rb index 9329638c9..89e820a00 100644 --- a/test/assert.rb +++ b/test/assert.rb @@ -81,7 +81,7 @@ end # Performs fuzzy check for equality on methods returning floats # on the basis of the Math::TOLERANCE constant. def check_float(a, b) - tolerance = 1e-12 + tolerance = Math::TOLERANCE a = a.to_f b = b.to_f if a.finite? and b.finite? @@ -90,4 +90,3 @@ def check_float(a, b) true end end - -- cgit v1.2.3 From 883b97ab05ac8e509ff575c0c8533066f7e900c7 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Wed, 1 Aug 2012 01:23:34 +0900 Subject: some test requires double precision --- src/math.c | 2 +- test/t/math.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/src/math.c b/src/math.c index fe10848c3..9aae87acd 100644 --- a/src/math.c +++ b/src/math.c @@ -647,7 +647,7 @@ mrb_init_math(mrb_state *mrb) #endif #ifdef MRB_USE_FLOAT - mrb_define_const(mrb, mrb_math, "TOLERANCE", mrb_float_value(1e-6)); + mrb_define_const(mrb, mrb_math, "TOLERANCE", mrb_float_value(1e-5)); #else mrb_define_const(mrb, mrb_math, "TOLERANCE", mrb_float_value(1e-12)); #endif diff --git a/test/t/math.rb b/test/t/math.rb index 025551b82..d71e44fc9 100644 --- a/test/t/math.rb +++ b/test/t/math.rb @@ -12,7 +12,7 @@ if Object.const_defined?(:Math) assert('Fundamental trig identities') do result = true - N = 15 + N = 13 N.times do |i| a = Math::PI / N * i ca = Math::PI / 2 - a -- cgit v1.2.3