K2 Scripting: add support for script implicit receivers
This commit is contained in:
committed by
Space Team
parent
480ea80fc4
commit
6c7751b0af
+1
-1
@@ -110,7 +110,7 @@ class CachingTest : TestCase() {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testImplicitReceiversWithJarCache() = expectTestToFailOnK2 {
|
||||
fun testImplicitReceiversWithJarCache() {
|
||||
withTempDir("scriptingTestJarCache") { cacheDir ->
|
||||
val cache = TestCompiledScriptJarsCache(cacheDir)
|
||||
Assert.assertTrue(cache.baseDir.listFiles()!!.isEmpty())
|
||||
|
||||
+1
-1
@@ -24,7 +24,7 @@ class ConstructorArgumentsOrderTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testScriptWithImplicitReceiver() = expectTestToFailOnK2 {
|
||||
fun testScriptWithImplicitReceiver() {
|
||||
val res = evalString<ScriptWithImplicitReceiver>("""println(receiverString)""") {
|
||||
implicitReceivers(ImplicitReceiverClass("Hello Receiver!"))
|
||||
}
|
||||
|
||||
+21
@@ -223,6 +223,27 @@ class ScriptingHostTest : TestCase() {
|
||||
Assert.assertEquals(greeting, output)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testSimpleScriptWithImplicitReceiver() {
|
||||
val greeting = listOf("3")
|
||||
val script = "println(length)"
|
||||
val definition = createJvmScriptDefinitionFromTemplate<SimpleScriptTemplate>(
|
||||
compilation = {
|
||||
implicitReceivers(String::class)
|
||||
},
|
||||
evaluation = {
|
||||
implicitReceivers("abc")
|
||||
}
|
||||
)
|
||||
val output = captureOut {
|
||||
val retVal = BasicJvmScriptingHost().eval(
|
||||
script.toScriptSource(), definition.compilationConfiguration, definition.evaluationConfiguration
|
||||
).valueOrThrow().returnValue
|
||||
if (retVal is ResultValue.Error) throw retVal.error
|
||||
}.lines()
|
||||
Assert.assertEquals(greeting, output)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testProvidedPropertiesNullability() = expectTestToFailOnK2 {
|
||||
val stringType = KotlinType(String::class)
|
||||
|
||||
Reference in New Issue
Block a user