Resolving and Binding 11
This commit is contained in:
parent
a1acefab0e
commit
52a7b73a9e
14 changed files with 263 additions and 22 deletions
56
test/all.d
56
test/all.d
|
|
@ -1,23 +1,49 @@
|
|||
#!/bin/env rdmd
|
||||
|
||||
import std.process;
|
||||
import std.concurrency;
|
||||
import std.conv;
|
||||
import std.string, std.format;
|
||||
import std.algorithm, std.range;
|
||||
|
||||
void main(){
|
||||
string fib(uint n){
|
||||
string r = "";
|
||||
double a = 0;
|
||||
double temp;
|
||||
for(double b = 1; a <= n; b = temp + b){
|
||||
r ~= a.to!string ~ "\n";
|
||||
temp = a;
|
||||
a = b;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
assert([ "./lox", "test/closure.lox" ].execute.output == "1\n2\n");
|
||||
assert([ "./lox", "test/fib_for.lox" ].execute.output == fib(6765));
|
||||
assert([ "./lox", "test/fib_recursive.lox" ].execute.output == fib(34));
|
||||
assert([ "./lox", "test/fib_closure.lox" ].execute.output == fib(34));
|
||||
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)); });
|
||||
|
||||
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"); });
|
||||
}
|
||||
|
||||
enum RetVal{
|
||||
success = 0, other = 1, runtime = 2
|
||||
}
|
||||
|
||||
string fib(uint n){
|
||||
string r = "";
|
||||
double a = 0;
|
||||
double temp;
|
||||
for(double b = 1; a <= n; b = temp + b){
|
||||
r ~= a.to!string ~ "\n";
|
||||
temp = a;
|
||||
a = b;
|
||||
}
|
||||
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 shouldFail(string file, int code = 1, string msg = null){
|
||||
auto c = file.run;
|
||||
assert(c.status == code, "Expected %s to fail with code %d but got %d".format(file, code, c.status));
|
||||
assert(!msg || c.output.toLower.indexOf(msg.toLower) >= 0, "ShouldFail %s failed\n-- Got --\n%s\n-- Expected --\n%s".format(file, c.output, msg));
|
||||
assert(c.output.indexOf("_Dmain") == -1, "ShouldFail %s got D exception\n%s".format(file, c.output));
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue