From cc681c76a09047cc07dd3b3f3684d98ee47236da Mon Sep 17 00:00:00 2001 From: sergeych Date: Sun, 15 Feb 2026 01:26:31 +0300 Subject: [PATCH] Test extension callable handles --- .../commonTest/kotlin/BridgeResolverTest.kt | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/lynglib/src/commonTest/kotlin/BridgeResolverTest.kt b/lynglib/src/commonTest/kotlin/BridgeResolverTest.kt index dde5d7f..a90e4c8 100644 --- a/lynglib/src/commonTest/kotlin/BridgeResolverTest.kt +++ b/lynglib/src/commonTest/kotlin/BridgeResolverTest.kt @@ -51,4 +51,33 @@ class BridgeResolverTest { val addByName = callByName.callByName(facade, "add", Arguments(ObjInt.of(4), ObjInt.of(6))) assertEquals(10, (addByName as ObjInt).value) } + + @Test + fun testExtensionCallableHandle() = runTest { + val im = Script.defaultImportManager.copy() + val scope = im.newStdScope() + scope.eval( + """ + class Foo { + var count: Int = 1 + } + + fun Foo.bumped() = count + 2 + + val f = Foo() + """.trimIndent() + ) + + val facade = scope.asFacade() + val resolver = facade.resolver() + + val fooRec = scope["Foo"] ?: error("Foo not found") + val fooClass = scope.resolve(fooRec, "Foo") as net.sergeych.lyng.obj.ObjClass + val fRec = scope["f"] ?: error("f not found") + val fObj = scope.resolve(fRec, "f") as ObjInstance + + val extHandle = resolver.resolveExtensionCallable(fooClass, "bumped") + val result = extHandle.call(facade, newThisObj = fObj) as ObjInt + assertEquals(3, result.value) + } }