Classes 12
This commit is contained in:
parent
52a7b73a9e
commit
d8ac625429
18 changed files with 417 additions and 186 deletions
30
test/all.d
30
test/all.d
|
|
@ -1,5 +1,6 @@
|
|||
#!/bin/env rdmd
|
||||
|
||||
import std.stdio;
|
||||
import std.process;
|
||||
import std.concurrency;
|
||||
import std.conv;
|
||||
|
|
@ -7,18 +8,20 @@ import std.string, std.format;
|
|||
import std.algorithm, std.range;
|
||||
|
||||
void main(){
|
||||
auto scheduler = new ThreadScheduler();
|
||||
scheduler.spawn((){ "./test/closure.lox".run.output.match("1\n2\n"); });
|
||||
scheduler.spawn((){ "./test/scope.lox".run.output.match("global first first second first ".replace(' ', '\n').repeat(2).join("\n")); });
|
||||
scheduler.spawn((){ "./test/fib_for.lox".run.output.match(fib(6765)); });
|
||||
scheduler.spawn((){ "./test/fib_recursive.lox".run.output.match(fib(34)); });
|
||||
scheduler.spawn((){ "./test/fib_closure.lox".run.output.match(fib(34)); });
|
||||
"./test/ops.lox".match("1\n2\n3\n4\n5\n6\n7\ntrue\nfalse\ntrue\ntrue\nhello, world\n");
|
||||
"./test/shortcircuit.lox".match("true\nAAAA!\nAAAA!\nAAAA?\n");
|
||||
"./test/closure.lox".match("1\n2\n");
|
||||
"./test/scope.lox".match("global first first second first ".replace(' ', '\n').repeat(2).join("\n"));
|
||||
"./test/fib_for.lox".match(fib(6765));
|
||||
"./test/fib_recursive.lox".match(fib(34));
|
||||
"./test/fib_closure.lox".match(fib(34));
|
||||
"./test/class.lox".match("The German chocolate cake is delicious!\n");
|
||||
|
||||
scheduler.spawn((){ "./test/err/already_defined.lox".shouldFail(RetVal.other, "Already a variable with this name"); });
|
||||
scheduler.spawn((){ "./test/err/undefined_var.lox".shouldFail(RetVal.runtime, "Undefined variable"); });
|
||||
scheduler.spawn((){ "./test/err/self_ref_vardecl.lox".shouldFail(RetVal.runtime, "Undefined variable"); });
|
||||
scheduler.spawn((){ "./test/err/invalid_syntax.lox".shouldFail(RetVal.other); });
|
||||
scheduler.spawn((){ "./test/err/global_scope_return.lox".shouldFail(RetVal.other, "Can't return from top-level code"); });
|
||||
"./test/err/already_defined.lox".shouldFail(RetVal.other, "Already a variable with this name");
|
||||
"./test/err/undefined_var.lox".shouldFail(RetVal.runtime, "Undefined variable");
|
||||
"./test/err/self_ref_vardecl.lox".shouldFail(RetVal.runtime, "Undefined variable");
|
||||
"./test/err/invalid_syntax.lox".shouldFail(RetVal.other);
|
||||
"./test/err/global_scope_return.lox".shouldFail(RetVal.other, "Can't return from top-level code");
|
||||
}
|
||||
|
||||
enum RetVal{
|
||||
|
|
@ -37,8 +40,9 @@ string fib(uint n){
|
|||
return r;
|
||||
}
|
||||
auto run(string file) => [ "./lox", file ].execute;
|
||||
void match(string res, string correct){
|
||||
assert(res == correct, "Match failed\n-- Got --\n%s\n-- Expected --\n%s".format(res, correct));
|
||||
void match(string file, string correct){
|
||||
auto res = file.run.output;
|
||||
assert(res == correct, "Match %s failed\n-- Got --\n%s\n-- Expected --\n%s".format(file, res, correct));
|
||||
}
|
||||
void shouldFail(string file, int code = 1, string msg = null){
|
||||
auto c = file.run;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue