Methods and Initializers 28
This commit is contained in:
parent
d9dc02b92f
commit
28b0c71be1
12 changed files with 233 additions and 28 deletions
32
test/all.d
32
test/all.d
|
|
@ -7,7 +7,9 @@ import std.conv;
|
|||
import std.string, std.format;
|
||||
import std.algorithm, std.range;
|
||||
|
||||
void main(){
|
||||
int failures;
|
||||
|
||||
int main(){
|
||||
|
||||
"./test/func.lox".match("-1\n6\n1\n");
|
||||
"./test/bigsum.lox".match("125250\n");
|
||||
|
|
@ -26,7 +28,8 @@ void main(){
|
|||
"./test/fib_recursive.lox".match(fib(34));
|
||||
"./test/fib_closure.lox".match(fib(34));
|
||||
"./test/perverseclosure.lox".match("return from outer create inner closure value ".replace(" ", "\n"));
|
||||
/* "./test/class.lox".match("The German chocolate cake is delicious!\n"); */
|
||||
"./test/class.lox".match("The German chocolate cake is delicious!\n");
|
||||
"./test/methods.lox".match("Enjoy your cup of coffee and chicory\nnot a method\n");
|
||||
/* "./test/super.lox".match("Fry until golden brown.\nPipe full of custard and coat with chocolate.\nA method\n"); */
|
||||
|
||||
"./test/err/invalid_syntax.lox".shouldFail(RetVal.other);
|
||||
|
|
@ -36,6 +39,8 @@ void main(){
|
|||
"./test/err/global_scope_return.lox".shouldFail(RetVal.other, "Can't return from top-level code");
|
||||
/* "./test/err/super_outside_class.lox".shouldFail(RetVal.other, "Can't use 'super' outside of a class"); */
|
||||
/* "./test/err/super_without_superclass.lox".shouldFail(RetVal.other, "Can't use 'super' in a class with no superclass"); */
|
||||
|
||||
return failures;
|
||||
}
|
||||
|
||||
enum RetVal{
|
||||
|
|
@ -56,12 +61,27 @@ string fib(uint n){
|
|||
auto run(string file, Config.Flags f = Config.Flags.stderrPassThrough) => [ "./lox", file ].execute(null, Config(f));
|
||||
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));
|
||||
if(res != correct){
|
||||
stderr.writeln("Match %s failed\n-- Got --\n%s\n-- Expected --\n%s".format(file, res, correct));
|
||||
failures++;
|
||||
}
|
||||
}
|
||||
void shouldFail(string file, int code = 1, string msg = null){
|
||||
auto c = file.run(Config.Flags.none);
|
||||
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));
|
||||
if(!(c.status == code)){
|
||||
stderr.writeln("Expected %s to fail with code %d but got %d".format(file, code, c.status));
|
||||
failures++;
|
||||
return;
|
||||
}
|
||||
if(!(!msg || c.output.toLower.indexOf(msg.toLower) >= 0)){
|
||||
stderr.writeln("ShouldFail %s failed\n-- Got --\n%s\n-- Expected --\n%s".format(file, c.output, msg));
|
||||
failures++;
|
||||
return;
|
||||
}
|
||||
if(!(c.output.indexOf("_Dmain") == -1)){
|
||||
stderr.writeln("ShouldFail %s got D exception\n%s".format(file, c.output));
|
||||
failures++;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue