Added some tests from jet project.

This commit is contained in:
Pavel Talanov
2011-11-18 17:32:53 +04:00
parent 28763128be
commit ebf29263f1
7 changed files with 74 additions and 0 deletions
@@ -38,4 +38,20 @@ public class FunctionTest extends AbstractExpressionTest {
public void loopClosure() throws Exception {
testFooBoxIsTrue("loopClosure.kt");
}
@Test
public void functionLiteralAsParameter() throws Exception {
testFooBoxIsTrue("functionLiteralAsParameter.kt");
}
@Test
public void closureWithParameter() throws Exception {
testFooBoxIsOk("closureWithParameter.jet");
}
@Test
public void closureWithParameterAndBoxing() throws Exception {
testFooBoxIsOk("closureWithParameterAndBoxing.jet");
}
}
@@ -44,4 +44,10 @@ public final class TraitTest extends IncludeLibraryTest {
testFooBoxIsTrue("traitExtendsTwoTraits.kt");
}
@Test
public void funDelegation() throws Exception {
testFooBoxIsOk("funDelegation.jet");
}
}
@@ -100,4 +100,9 @@ public abstract class TranslationTest {
protected void testFooBoxIsTrue(String filename) throws Exception {
testFunctionOutput(filename, "foo", "box", true);
}
protected void testFooBoxIsOk(String filename) throws Exception {
testFunctionOutput(filename, "foo", "box", "OK");
}
}
@@ -0,0 +1,9 @@
namespace foo
fun box() : String {
return apply( "OK", {(arg: String) => arg } )
}
fun apply(arg : String, f : fun (p:String) : String) : String {
return f(arg)
}
@@ -0,0 +1,9 @@
namespace foo
fun box() : String {
return if (apply( 5, {(arg: Int) => arg + 13 } ) == 18) "OK" else "fail"
}
fun apply(arg : Int, f : fun (p:Int) : Int) : Int {
return f(arg)
}
@@ -0,0 +1,10 @@
namespace foo
fun apply(f : fun(Int) : Int, t : Int) : Int {
return f(t)
}
fun box() : Boolean {
return apply({(a: Int) => a + 5 }, 3) == 8
}
@@ -0,0 +1,19 @@
namespace foo
open class Base() {
fun n(n : Int) : Int = n + 1
}
trait Abstract {}
class Derived1() : Base(), Abstract {}
class Derived2() : Abstract, Base() {}
fun test(s : Base) : Boolean = s.n(238) == 239
fun box() : String {
if (!test(Base())) return "Fail #1"
if (!test(Derived1())) return "Fail #2"
if (!test(Derived2())) return "Fail #3"
return "OK"
}