Scripting: add test for implicit receivers with the same short name

This commit is contained in:
Ilya Chernikov
2023-07-20 19:20:02 +02:00
committed by Space Team
parent 3dc94f3d31
commit 3ee07eb015
3 changed files with 43 additions and 0 deletions
@@ -266,6 +266,33 @@ class ScriptingHostTest : TestCase() {
Assert.assertEquals(greeting, output)
}
fun testScriptWithImplicitReceiversWithSameShortName() {
val result = listOf("42")
val script = "println(v1 + v2)"
val definition = createJvmScriptDefinitionFromTemplate<SimpleScriptTemplate>(
compilation = {
updateClasspath(classpathFromClass<kotlin.script.experimental.jvmhost.test.forScript.p1.TestClass>())
implicitReceivers(
kotlin.script.experimental.jvmhost.test.forScript.p1.TestClass::class,
kotlin.script.experimental.jvmhost.test.forScript.p2.TestClass::class
)
},
evaluation = {
implicitReceivers(
kotlin.script.experimental.jvmhost.test.forScript.p1.TestClass("4"),
kotlin.script.experimental.jvmhost.test.forScript.p2.TestClass("2")
)
}
)
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(result, output)
}
@Test
fun testProvidedPropertiesNullability() {
val stringType = KotlinType(String::class)
@@ -0,0 +1,8 @@
/*
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package kotlin.script.experimental.jvmhost.test.forScript.p1
class TestClass(val v1: String)
@@ -0,0 +1,8 @@
/*
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package kotlin.script.experimental.jvmhost.test.forScript.p2
class TestClass(val v2: String)