Added tests for simple closure examples.

This commit is contained in:
Pavel Talanov
2011-11-18 16:56:23 +04:00
parent 7cdfccf2d8
commit 28763128be
3 changed files with 36 additions and 0 deletions
@@ -28,4 +28,14 @@ public class FunctionTest extends AbstractExpressionTest {
public void functionLiteral() throws Exception {
testFooBoxIsTrue("functionLiteral.kt");
}
@Test
public void adderClosure() throws Exception {
testFooBoxIsTrue("adderClosure.kt");
}
@Test
public void loopClosure() throws Exception {
testFooBoxIsTrue("loopClosure.kt");
}
}
@@ -0,0 +1,9 @@
namespace foo
fun box() : Boolean {
var sum = 0
val adder = {(a: Int) => sum += a }
adder(3)
adder(2)
return sum == 5
}
@@ -0,0 +1,17 @@
namespace foo
var b = 0
fun loop(var times : Int) {
while(times > 0) {
val u : fun(value : Int) : Unit = {
b++
}
u(times--)
}
}
fun box() : Boolean {
loop(5)
return b == 5
}