diff --git a/translator/test/org/jetbrains/k2js/test/FunctionTest.java b/translator/test/org/jetbrains/k2js/test/FunctionTest.java index 75632d5a5ad..3b41d6d0a41 100644 --- a/translator/test/org/jetbrains/k2js/test/FunctionTest.java +++ b/translator/test/org/jetbrains/k2js/test/FunctionTest.java @@ -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"); + } + } diff --git a/translator/test/org/jetbrains/k2js/test/TraitTest.java b/translator/test/org/jetbrains/k2js/test/TraitTest.java index 6546702c631..d8346238200 100644 --- a/translator/test/org/jetbrains/k2js/test/TraitTest.java +++ b/translator/test/org/jetbrains/k2js/test/TraitTest.java @@ -44,4 +44,10 @@ public final class TraitTest extends IncludeLibraryTest { testFooBoxIsTrue("traitExtendsTwoTraits.kt"); } + @Test + public void funDelegation() throws Exception { + testFooBoxIsOk("funDelegation.jet"); + } + + } diff --git a/translator/test/org/jetbrains/k2js/test/TranslationTest.java b/translator/test/org/jetbrains/k2js/test/TranslationTest.java index 80b4e3eef0c..ae1ddbd0b58 100644 --- a/translator/test/org/jetbrains/k2js/test/TranslationTest.java +++ b/translator/test/org/jetbrains/k2js/test/TranslationTest.java @@ -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"); + } + } diff --git a/translator/testFiles/expression/function/cases/closureWithParameter.jet b/translator/testFiles/expression/function/cases/closureWithParameter.jet new file mode 100644 index 00000000000..8674e078051 --- /dev/null +++ b/translator/testFiles/expression/function/cases/closureWithParameter.jet @@ -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) +} diff --git a/translator/testFiles/expression/function/cases/closureWithParameterAndBoxing.jet b/translator/testFiles/expression/function/cases/closureWithParameterAndBoxing.jet new file mode 100644 index 00000000000..3b05060982d --- /dev/null +++ b/translator/testFiles/expression/function/cases/closureWithParameterAndBoxing.jet @@ -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) +} diff --git a/translator/testFiles/expression/function/cases/functionLiteralAsParameter.kt b/translator/testFiles/expression/function/cases/functionLiteralAsParameter.kt new file mode 100644 index 00000000000..3ec397a9127 --- /dev/null +++ b/translator/testFiles/expression/function/cases/functionLiteralAsParameter.kt @@ -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 +} \ No newline at end of file diff --git a/translator/testFiles/trait/cases/funDelegation.jet b/translator/testFiles/trait/cases/funDelegation.jet new file mode 100644 index 00000000000..8a5258d2cee --- /dev/null +++ b/translator/testFiles/trait/cases/funDelegation.jet @@ -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" +} \ No newline at end of file