From 8d9f5628eda4f1353c2578900b6396a7e06f281b Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Thu, 1 Nov 2012 16:24:52 +0800 Subject: Add Test for String#bytes --- test/t/string.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'test') diff --git a/test/t/string.rb b/test/t/string.rb index 27af38a4c..1a917b1c4 100644 --- a/test/t/string.rb +++ b/test/t/string.rb @@ -339,3 +339,10 @@ assert('Check the usage of a NUL character') do "qqq\0ppp" end +assert('String#bytes') do + str1 = "hello" + bytes1 = [104, 101, 108, 108, 111] + + str1.bytes == bytes1 +end + -- cgit v1.2.3 From b9cf5045b7e10ad722475a432db4fe1b38987cbd Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Thu, 1 Nov 2012 16:40:31 +0800 Subject: Add Test for String#each_byte --- test/t/string.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'test') diff --git a/test/t/string.rb b/test/t/string.rb index 1a917b1c4..26b7df584 100644 --- a/test/t/string.rb +++ b/test/t/string.rb @@ -346,3 +346,13 @@ assert('String#bytes') do str1.bytes == bytes1 end +assert('String#each_byte') do + str1 = "hello" + bytes1 = [104, 101, 108, 108, 111] + bytes2 = [] + + str1.each_byte {|b| bytes2 << b } + + bytes1 == bytes2 +end + -- cgit v1.2.3 From 308b41c12b3095a5dec85ca89d32a5b196434141 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Fri, 2 Nov 2012 08:02:21 +0900 Subject: add test for 8cf42709 --- test/t/syntax.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'test') diff --git a/test/t/syntax.rb b/test/t/syntax.rb index 7898a0b7d..47221d425 100644 --- a/test/t/syntax.rb +++ b/test/t/syntax.rb @@ -45,3 +45,16 @@ assert('Abbreviated variable assignment', '11.4.2.3.2') do c += 2 a == 1 and b == nil and c == 3 end + +assert('Nested const reference') do + module Syntax4Const + CONST1 = "hello world" + class Const2 + def const1 + CONST1 + end + end + end + Syntax4Const::CONST1 == "hello world" and + Syntax4Const::Const2.new.const1 == "hello world" +end -- cgit v1.2.3 From 3ba521ae9e238c91198404845e4f213ce541b13d Mon Sep 17 00:00:00 2001 From: Yukihiro Matz Matsumoto Date: Sun, 4 Nov 2012 04:49:43 +0900 Subject: replace FIXNUM_P() by mrb_fixnum_p() --- include/mruby/value.h | 2 +- src/array.c | 2 +- src/numeric.c | 16 ++++++++-------- src/object.c | 2 +- src/sprintf.c | 2 +- test/driver.c | 2 +- 6 files changed, 13 insertions(+), 13 deletions(-) (limited to 'test') diff --git a/include/mruby/value.h b/include/mruby/value.h index 70e0e9b3f..819ce6b7b 100644 --- a/include/mruby/value.h +++ b/include/mruby/value.h @@ -149,7 +149,7 @@ mrb_float_value(mrb_float f) #define mrb_fixnum(o) (o).value.i #define mrb_symbol(o) (o).value.sym #define mrb_object(o) ((struct RBasic *) (o).value.p) -#define FIXNUM_P(o) (mrb_type(o) == MRB_TT_FIXNUM) +#define mrb_fixnum_p(o) (mrb_type(o) == MRB_TT_FIXNUM) #define mrb_undef_p(o) (mrb_type(o) == MRB_TT_UNDEF) #define mrb_nil_p(o) (mrb_type(o) == MRB_TT_FALSE && !(o).value.i) #define mrb_test(o) (mrb_type(o) != MRB_TT_FALSE) diff --git a/src/array.c b/src/array.c index 2e2536368..6b901b4ee 100644 --- a/src/array.c +++ b/src/array.c @@ -719,7 +719,7 @@ mrb_ary_aset(mrb_state *mrb, mrb_value self) mrb_get_args(mrb, "*", &argv, &argc); switch(argc) { case 2: - if (FIXNUM_P(argv[0])) { + if (mrb_fixnum_p(argv[0])) { mrb_ary_set(mrb, self, mrb_fixnum(argv[0]), argv[1]); } else { diff --git a/src/numeric.c b/src/numeric.c index c1491ac51..e4d9c9ff9 100644 --- a/src/numeric.c +++ b/src/numeric.c @@ -97,7 +97,7 @@ num_pow(mrb_state *mrb, mrb_value x) mrb_float d; mrb_get_args(mrb, "o", &y); - if (FIXNUM_P(x) && FIXNUM_P(y)) both_int = TRUE; + if (mrb_fixnum_p(x) && mrb_fixnum_p(y)) both_int = TRUE; d = pow(mrb_to_flo(mrb, x), mrb_to_flo(mrb, y)); if (both_int && FIXABLE(d)) return mrb_fixnum_value((mrb_int)d); @@ -682,7 +682,7 @@ fix_succ(mrb_state *mrb, mrb_value num) static mrb_value int_succ(mrb_state *mrb, mrb_value num) { - if (FIXNUM_P(num)) return fix_succ(mrb, num); + if (mrb_fixnum_p(num)) return fix_succ(mrb, num); return mrb_funcall(mrb, num, "+", 1, mrb_fixnum_value(1)); } @@ -697,7 +697,7 @@ mrb_fixnum_mul(mrb_state *mrb, mrb_value x, mrb_value y) a = mrb_fixnum(x); if (a == 0) return x; - if (FIXNUM_P(y)) { + if (mrb_fixnum_p(y)) { mrb_int b, c; b = mrb_fixnum(y); @@ -774,7 +774,7 @@ fix_mod(mrb_state *mrb, mrb_value x) mrb_get_args(mrb, "o", &y); a = mrb_fixnum(x); - if (FIXNUM_P(y) && (b=mrb_fixnum(y)) != 0) { + if (mrb_fixnum_p(y) && (b=mrb_fixnum(y)) != 0) { mrb_int mod; if (mrb_fixnum(y) == 0) { @@ -803,7 +803,7 @@ fix_divmod(mrb_state *mrb, mrb_value x) mrb_value y; mrb_get_args(mrb, "o", &y); - if (FIXNUM_P(y)) { + if (mrb_fixnum_p(y)) { mrb_int div, mod; if (mrb_fixnum(y) == 0) { @@ -877,7 +877,7 @@ fix_rev(mrb_state *mrb, mrb_value num) static mrb_value bit_coerce(mrb_state *mrb, mrb_value x) { - while (!FIXNUM_P(x)) { + while (!mrb_fixnum_p(x)) { if (mrb_type(x) == MRB_TT_FLOAT) { mrb_raise(mrb, E_TYPE_ERROR, "can't convert Float into Integer"); } @@ -1076,7 +1076,7 @@ mrb_fixnum_plus(mrb_state *mrb, mrb_value x, mrb_value y) a = mrb_fixnum(x); if (a == 0) return y; - if (FIXNUM_P(y)) { + if (mrb_fixnum_p(y)) { mrb_int b, c; b = mrb_fixnum(y); @@ -1114,7 +1114,7 @@ mrb_fixnum_minus(mrb_state *mrb, mrb_value x, mrb_value y) mrb_int a; a = mrb_fixnum(x); - if (FIXNUM_P(y)) { + if (mrb_fixnum_p(y)) { mrb_int b, c; b = mrb_fixnum(y); diff --git a/src/object.c b/src/object.c index a23e397f6..ae3af692d 100644 --- a/src/object.c +++ b/src/object.c @@ -509,7 +509,7 @@ mrb_to_integer(mrb_state *mrb, mrb_value val, const char *method) { mrb_value v; - if (FIXNUM_P(val)) return val; + if (mrb_fixnum_p(val)) return val; v = convert_type(mrb, val, "Integer", method, TRUE); if (!mrb_obj_is_kind_of(mrb, v, mrb->fixnum_class)) { const char *cname = mrb_obj_classname(mrb, val); diff --git a/src/sprintf.c b/src/sprintf.c index 2bd72ffc6..91fa3edca 100644 --- a/src/sprintf.c +++ b/src/sprintf.c @@ -800,7 +800,7 @@ retry: goto bin_retry; } val = mrb_flt2big(mrb, mrb_float(val)); - if (FIXNUM_P(val)) goto bin_retry; + if (mrb_fixnum_p(val)) goto bin_retry; break; case MRB_TT_STRING: val = mrb_str_to_inum(mrb, val, 0, TRUE); diff --git a/test/driver.c b/test/driver.c index d2ad31b26..788a77b2d 100644 --- a/test/driver.c +++ b/test/driver.c @@ -32,7 +32,7 @@ check_error(mrb_state *mrb) 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; + return mrb_fixnum_p(ko_test) && mrb_fixnum(ko_test) == 0 && mrb_fixnum_p(kill_test) && mrb_fixnum(kill_test) == 0; } int -- cgit v1.2.3 From cd2c7c7532b91818b57e7f54ce5ed4553ae3964c Mon Sep 17 00:00:00 2001 From: Akira Yumiyama Date: Mon, 5 Nov 2012 13:28:20 +0900 Subject: add mruby/mrbc tests. --- .gitignore | 1 + test/Makefile | 25 +++++++++++++++++++++++++ test/report.rb | 4 ++++ 3 files changed, 30 insertions(+) create mode 100644 test/report.rb (limited to 'test') diff --git a/.gitignore b/.gitignore index 797f98917..8a76394ee 100644 --- a/.gitignore +++ b/.gitignore @@ -22,5 +22,6 @@ cscope.out /test/mrbtest /test/mrbtest.c /test/*.*tmp +/test/mrubytest.* CMakeFiles CMakeCache.txt diff --git a/test/Makefile b/test/Makefile index 18bc79b5a..7457a6266 100644 --- a/test/Makefile +++ b/test/Makefile @@ -16,6 +16,13 @@ ASSLIB := $(BASEDIR)/assert.rb MRBS := $(BASEDIR)/t/*.rb OBJS := driver.o $(MLIB) +# for mruby/mrbc test +REPLIB := $(BASEDIR)/report.rb +TESTRB := mrubytest.rb +TESTMRB := mrubytest.mrb +TESTRB_REP := mrubytest.rb.report +TESTMRB_REP := mrubytest.mrb.report + # libraries, includes LIBS = -lm INCLUDES = -I$(BASEDIR)/../src -I$(BASEDIR)/../include @@ -43,9 +50,11 @@ endif # mruby compiler and test driver ifeq ($(OS),Windows_NT) MRBC = ../bin/mrbc.exe +MRUBY= ../bin/mruby.exe EXE := $(TARGET).exe else MRBC = ../bin/mrbc +MRUBY= ../bin/mruby EXE := $(TARGET) endif @@ -55,7 +64,15 @@ endif .PHONY : test all : $(EXE) + @echo "# exec mrbtest" ./$(EXE) + @echo + @echo "# exec mruby test with ruby script" + @($(MRUBY) $(TESTRB) > $(TESTRB_REP) && echo "mrubytest.rb success.") || $(CAT) $(TESTRB_REP) + @echo + @echo "# exec mruby test with mrb file" + @($(MRUBY) -b $(TESTMRB) > $(TESTMRB_REP) && echo "mrubytest.mrb success.") || $(CAT) $(TESTMRB_REP) + @echo # executable constructed using linker from object files $(EXE) : $(OBJS) $(LIBR) @@ -75,8 +92,16 @@ $(CLIB) : $(RLIB) $(MRBC) $(INIT) $(RLIB) : $(ASSLIB) $(MRBS) $(CAT) $(ASSLIB) $(MRBS) > $@ +# Compile mrb file from mruby source +$(TESTMRB) : $(MRBC) $(TESTRB) + $(MRBC) $(TESTRB) + +$(TESTRB) : $(ASSLIB) $(MRBS) $(REPLIB) + $(CAT) $(ASSLIB) $(MRBS) $(REPLIB) > $@ + # clean up .PHONY : clean clean : @echo "make: removing targets, objects and depend files of `pwd`" -$(RM_F) $(MLIB) $(CLIB) $(RLIB) $(DLIB) $(DEPLIB) $(OBJS) $(EXE) + -$(RM_F) $(TESTRB) $(TESTMRB) $(TESTRB_REP) $(TESTMRB_REP) diff --git a/test/report.rb b/test/report.rb new file mode 100644 index 000000000..5e85715b7 --- /dev/null +++ b/test/report.rb @@ -0,0 +1,4 @@ +report +if $ko_test > 0 or $kill_test > 0 + raise "mrbtest failed (KO=#{$ko_test}, Crash:#{kill_test})" +end -- cgit v1.2.3 From 8d3baf62294ce9bd15b4c24d67d69d289776f5c9 Mon Sep 17 00:00:00 2001 From: Akira Yumiyama Date: Mon, 5 Nov 2012 15:36:12 +0900 Subject: fix mrubytest dependencies --- test/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/Makefile b/test/Makefile index 7457a6266..3df07b280 100644 --- a/test/Makefile +++ b/test/Makefile @@ -63,7 +63,7 @@ endif # generic build targets, rules .PHONY : test -all : $(EXE) +all : $(EXE) $(MRUBY) $(TESTRB) $(TESTMRB) @echo "# exec mrbtest" ./$(EXE) @echo -- cgit v1.2.3 From fdefaf9f7d02a2b43d25bccaecca7ec530f77384 Mon Sep 17 00:00:00 2001 From: Akira Yumiyama Date: Mon, 5 Nov 2012 15:50:46 +0900 Subject: typo fix on test/report.rb --- test/report.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/report.rb b/test/report.rb index 5e85715b7..fb77fd0aa 100644 --- a/test/report.rb +++ b/test/report.rb @@ -1,4 +1,4 @@ report if $ko_test > 0 or $kill_test > 0 - raise "mrbtest failed (KO=#{$ko_test}, Crash:#{kill_test})" + raise "mrbtest failed (KO:#{$ko_test}, Crash:#{$kill_test})" end -- cgit v1.2.3