From b52b92cd3125cabeeddd2d067c5d4337582a87ff Mon Sep 17 00:00:00 2001 From: Alex Tkachman Date: Thu, 2 Aug 2012 09:31:32 +0300 Subject: [PATCH] one more test for scripts --- .../codegen/script/methodWithClosure.lang.kt | 2 ++ .../org/jetbrains/jet/codegen/ScriptGenTest.java | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 compiler/testData/codegen/script/methodWithClosure.lang.kt diff --git a/compiler/testData/codegen/script/methodWithClosure.lang.kt b/compiler/testData/codegen/script/methodWithClosure.lang.kt new file mode 100644 index 00000000000..ad9da1753f2 --- /dev/null +++ b/compiler/testData/codegen/script/methodWithClosure.lang.kt @@ -0,0 +1,2 @@ +val v = 239 +fun method() = num + v \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/jet/codegen/ScriptGenTest.java b/compiler/tests/org/jetbrains/jet/codegen/ScriptGenTest.java index dac4fdf52b2..576f9b52932 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/ScriptGenTest.java +++ b/compiler/tests/org/jetbrains/jet/codegen/ScriptGenTest.java @@ -164,4 +164,20 @@ public class ScriptGenTest extends CodegenTestCase { throw new RuntimeException(e); } } + + public void testScriptWhereMethodHasClosure() { + JetScriptDefinitionProvider.getInstance(myEnvironment.getProject()).addScriptDefinition(FIB_SCRIPT_DEFINITION); + loadFile("script/methodWithClosure.lang.kt"); + final Class aClass = loadClass("MethodWithClosure", generateClassesInFile()); + try { + Constructor constructor = aClass.getConstructor(int.class); + Object script = constructor.newInstance(239); + Method fib = aClass.getMethod("method"); + Object invoke = fib.invoke(script); + assertEquals(239, ((Integer)invoke)/2); + } + catch (Exception e) { + throw new RuntimeException(e); + } + } }