IR Scripting: update capturing logic for the REPL, imported scripts,
as well as all other implicit receivers.
This commit is contained in:
+24
@@ -67,6 +67,30 @@ class ReplTest : TestCase() {
|
||||
Assert.assertEquals("x = 3", out)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testCaptureFromPreviousSnippets() {
|
||||
val out = captureOut {
|
||||
checkEvaluateInRepl(
|
||||
sequenceOf(
|
||||
"val x = 3",
|
||||
"fun b() = x",
|
||||
"b()",
|
||||
"println(\"b() = \${b()}\")",
|
||||
"val y = x + 2",
|
||||
"y",
|
||||
"class Nested { fun c() = x + 4 }",
|
||||
"Nested().c()",
|
||||
"inner class Inner { fun d() = x + 6 }",
|
||||
"Inner().d()",
|
||||
"class TwoLevel { inner class Inner { fun e() = x + 8 } }",
|
||||
"TwoLevel().Inner().e()",
|
||||
),
|
||||
sequenceOf(null, null, 3, null, null, 5, null, 7, null, 9, null, 11)
|
||||
)
|
||||
}
|
||||
Assert.assertEquals("b() = 3", out)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testEvalWithResult() {
|
||||
checkEvaluateInRepl(
|
||||
|
||||
+11
@@ -122,6 +122,17 @@ class MainKtsTest {
|
||||
Assert.assertEquals(OUT_FROM_IMPORT_TEST, out)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testImportWithCapture() {
|
||||
|
||||
val out = captureOut {
|
||||
val res = evalFile(File("$TEST_DATA_ROOT/import-with-capture-test.main.kts"))
|
||||
assertSucceeded(res)
|
||||
}.lines()
|
||||
|
||||
Assert.assertEquals(OUT_FROM_IMPORT_TEST, out)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testDuplicateImportError() {
|
||||
val res = evalFile(File("$TEST_DATA_ROOT/import-duplicate-test.main.kts"))
|
||||
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
|
||||
@file:Import("import-common.main.kts")
|
||||
@file:Import("import-middle.main.kts")
|
||||
|
||||
sharedVar = sharedVar + 1
|
||||
|
||||
class CapturingClass1 {
|
||||
val value = sharedVar
|
||||
}
|
||||
|
||||
class CapturingClass2 {
|
||||
fun f() = CapturingClass1().value
|
||||
}
|
||||
|
||||
println("${SharedObject.greeting} ${from.msg} main")
|
||||
println("sharedVar == ${CapturingClass2().f()}")
|
||||
Reference in New Issue
Block a user