diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/driver.c | 43 | ||||
| -rw-r--r-- | test/init_mrbtest.c | 1 | ||||
| -rw-r--r-- | test/t/literals.rb | 133 |
3 files changed, 159 insertions, 18 deletions
diff --git a/test/driver.c b/test/driver.c index 5183145b4..acf79df05 100644 --- a/test/driver.c +++ b/test/driver.c @@ -5,6 +5,8 @@ ** against the current mruby implementation. */ + +#include <stdlib.h> #include <string.h> #include <mruby.h> @@ -17,7 +19,8 @@ void mrb_init_mrbtest(mrb_state *); /* Print a short remark for the user */ -void print_hint(void) +static void +print_hint(void) { printf("mrbtest - Embeddable Ruby Test\n"); printf("\nThis is a very early version, please test and report errors.\n"); @@ -35,13 +38,31 @@ check_error(mrb_state *mrb) return mrb_fixnum_p(ko_test) && mrb_fixnum(ko_test) == 0 && mrb_fixnum_p(kill_test) && mrb_fixnum(kill_test) == 0; } +static int +eval_test(mrb_state *mrb) +{ + mrb_value return_value; + const char *prog = "report()"; + + /* evaluate the test */ + return_value = mrb_load_string(mrb, prog); + /* did an exception occur? */ + if (mrb->exc) { + mrb_p(mrb, return_value); + mrb->exc = 0; + return EXIT_FAILURE; + } + else if (!check_error(mrb)) { + return EXIT_FAILURE; + } + return EXIT_SUCCESS; +} + int main(int argc, char **argv) { mrb_state *mrb; - mrb_value return_value; - const char *prog = "report()"; - int ret = EXIT_SUCCESS; + int ret; print_hint(); @@ -52,23 +73,13 @@ main(int argc, char **argv) return EXIT_FAILURE; } - if (argc == 2 && strncmp(argv[1], "-v", 2) == 0) { + if (argc == 2 && argv[1][0] == '-' && argv[1][1] == 'v') { printf("verbose mode: enable\n\n"); mrb_gv_set(mrb, mrb_intern(mrb, "$mrbtest_verbose"), mrb_true_value()); } mrb_init_mrbtest(mrb); - /* evaluate the test */ - return_value = mrb_load_string(mrb, prog); - /* did an exception occur? */ - if (mrb->exc) { - mrb_p(mrb, return_value); - mrb->exc = 0; - ret = EXIT_FAILURE; - } - else if (!check_error(mrb)) { - ret = EXIT_FAILURE; - } + ret = eval_test(mrb); mrb_close(mrb); return ret; diff --git a/test/init_mrbtest.c b/test/init_mrbtest.c index 6b2219b6f..973029c8f 100644 --- a/test/init_mrbtest.c +++ b/test/init_mrbtest.c @@ -1,3 +1,4 @@ +#include <stdlib.h> #include "mruby.h" #include "mruby/irep.h" #include "mruby/dump.h" diff --git a/test/t/literals.rb b/test/t/literals.rb index 9a6d341d4..f40852ff9 100644 --- a/test/t/literals.rb +++ b/test/t/literals.rb @@ -128,8 +128,137 @@ ZZZ z == "" end -# Not Implemented ATM assert('Literals Array', '8.7.6.4') do +assert('Literals Array', '8.7.6.4') do + a = %W{abc#{1+2}def \}g} + b = %W(abc #{2+3} def \(g) + c = %W[#{3+4}] + d = %W< #{4+5} > + e = %W// + f = %W[[ab cd][ef]] + g = %W{ + ab + #{-1}1 + 2#{2} + } + h = %W(a\nb + test\ abc + c\ +d + x\y x\\y x\\\y) + + test1 = (a == ['abc3def', '}g'] and + b == ['abc', '5', 'def', '(g'] and + c == ['7'] and + d == ['9'] and + e == [] and + f == ['[ab', 'cd][ef]'] and + g == ['ab', '-11', '22'] and + h == ["a\nb", 'test abc', "c\nd", "xy", "x\\y", "x\\y"] + ) + + a = %w{abc#{1+2}def \}g} + b = %w(abc #{2+3} def \(g) + c = %w[#{3+4}] + d = %w< #{4+5} > + e = %w// + f = %w[[ab cd][ef]] + g = %w{ + ab + #{-1}1 + 2#{2} + } + h = %w(a\nb + test\ abc + c\ +d + x\y x\\y x\\\y) + + test2 = (a == ['abc#{1+2}def', '}g'] and + b == ['abc', '#{2+3}', 'def', '(g'] and + c == ['#{3+4}'] and + d == ['#{4+5}'] and + e == [] and + f == ['[ab', 'cd][ef]'] and + g == ['ab', '#{-1}1', '2#{2}'] and + h == ["a\\nb", "test abc", "c\nd", "x\\y", "x\\y", "x\\\\y"] + ) + + test1 and test2 +end + +assert('Literals Array of symbols') do + a = %I{abc#{1+2}def \}g} + b = %I(abc #{2+3} def \(g) + c = %I[#{3+4}] + d = %I< #{4+5} > + e = %I// + f = %I[[ab cd][ef]] + g = %I{ + ab + #{-1}1 + 2#{2} + } + + test1 = (a == [:'abc3def', :'}g'] and + b == [:'abc', :'5', :'def', :'(g'] and + c == [:'7'] and + d == [:'9'] and + e == [] and + f == [:'[ab', :'cd][ef]'] and + g == [:'ab', :'-11', :'22'] + ) + + a = %i{abc#{1+2}def \}g} + b = %i(abc #{2+3} def \(g) + c = %i[#{3+4}] + d = %i< #{4+5} > + e = %i// + f = %i[[ab cd][ef]] + g = %i{ + ab + #{-1}1 + 2#{2} + } + + test2 = (a == [:'abc#{1+2}def', :'}g'] and + b == [:'abc', :'#{2+3}', :'def', :'(g'] and + c == [:'#{3+4}'] and + d == [:'#{4+5}'] and + e == [] and + f == [:'[ab', :'cd][ef]'] and + g == [:'ab', :'#{-1}1', :'2#{2}'] + ) + + test1 and test2 +end + +assert('Literals Symbol', '8.7.6.6') do + # do not compile error + :$asd + :@asd + :@@asd + :asd= + :asd! + :asd? + :+ + :+@ + :if + :BEGIN + + a = :"asd qwe" + b = :'foo bar' + c = :"a#{1+2}b" + d = %s(asd) + e = %s( foo \)) + f = %s[asd \[ +qwe] + g = %s/foo#{1+2}bar/ + h = %s{{foo bar}} + + a == :'asd qwe' and b == :"foo bar" and c == :a3b and d == :asd and + e == :' foo )' and f == :"asd [\nqwe" and g == :'foo#{1+2}bar' and + h == :'{foo bar}' +end # Not Implemented ATM assert('Literals Regular expression', '8.7.6.5') do -# Not Implemented ATM assert('Literals Symbol', '8.7.6.6') do |
