diff --git a/test/all.d b/test/all.d index 5b79f0e..71de62f 100755 --- a/test/all.d +++ b/test/all.d @@ -15,8 +15,9 @@ void main(){ } return r; } - assert([ "./lox", "test/fib21.lox" ].execute.output == fib(6765)); - assert([ "./lox", "test/fib10.lox" ].execute.output == fib(34)); 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)); } diff --git a/test/fib_closure.lox b/test/fib_closure.lox new file mode 100644 index 0000000..42c8fe8 --- /dev/null +++ b/test/fib_closure.lox @@ -0,0 +1,18 @@ + +fun fibonacci(){ + var a = 0; + var b = 1; + fun f(){ + var next = a; + a = b; + b = next + b; + return next; + } + return f; +} + +var nextFibonacci = fibonacci(); + +for(var i = 0; i < 10; i = i + 1) + print nextFibonacci(); + diff --git a/test/fib21.lox b/test/fib_for.lox similarity index 100% rename from test/fib21.lox rename to test/fib_for.lox diff --git a/test/fib10.lox b/test/fib_recursive.lox similarity index 100% rename from test/fib10.lox rename to test/fib_recursive.lox