Support extensions on singleton objects
This commit is contained in:
1 parent
671583638b
commit
35628c8453
5 files changed
+56
-9
No files matched your search
@@ -384,6 +384,32 @@ class OOTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testObjectSingletonSupportsExtensions() = runTest {
|
||||
val scope = Script.newScope()
|
||||
scope.eval(
|
||||
"""
|
||||
object X {
|
||||
fun base() = "base"
|
||||
}
|
||||
|
||||
fun X.decorate(value): String {
|
||||
this.base() + ":" + value.toString()
|
||||
}
|
||||
val X.tag get() = this.base() + ":tag"
|
||||
|
||||
assertEquals("base", X.base())
|
||||
assertEquals("base:42", X.decorate(42))
|
||||
assertEquals("base:ok", X.decorate("ok"))
|
||||
assertEquals("base:tag", X.tag)
|
||||
|
||||
// Wrapper names should be generated for singleton-object receivers too.
|
||||
assertEquals("base:17", __ext__X__decorate(X, 17))
|
||||
assertEquals("base:tag", __ext_get__X__tag(X))
|
||||
""".trimIndent()
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testExtensionsAreScopeIsolated() = runTest {
|
||||
val scope1 = Script.newScope()
|
||||
|
||||
Reference in new issue
Block a user