Skip to content

Commit

Permalink
Add test for SAM-converted lambdas passed to Obj-C
Browse files Browse the repository at this point in the history
  • Loading branch information
SvyatoslavScherbina authored and homuroll committed Feb 12, 2021
1 parent dbd835a commit f01e284
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
13 changes: 13 additions & 0 deletions backend.native/tests/objcexport/expectedLazy.h
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,19 @@ __attribute__((swift_name("EmptyEnum")))
+ (KtKotlinArray<KtEmptyEnum *> *)values __attribute__((swift_name("values()")));
@end;

__attribute__((swift_name("FunInterface")))
@protocol KtFunInterface
@required
- (int32_t)run __attribute__((swift_name("run()")));
@end;

__attribute__((objc_subclassing_restricted))
__attribute__((swift_name("FunInterfacesKt")))
@interface KtFunInterfacesKt : KtBase
+ (id<KtFunInterface>)getObject __attribute__((swift_name("getObject()")));
+ (id<KtFunInterface>)getLambda __attribute__((swift_name("getLambda()")));
@end;

__attribute__((swift_name("FHolder")))
@interface KtFHolder : KtBase
- (instancetype)init __attribute__((swift_name("init()"))) __attribute__((objc_designated_initializer));
Expand Down
15 changes: 15 additions & 0 deletions backend.native/tests/objcexport/funInterfaces.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package funinterfaces

fun interface FunInterface {
fun run(): Int
}

fun getObject(): FunInterface {
return object : FunInterface {
override fun run() = 1
}
}

fun getLambda(): FunInterface {
return FunInterface { 2 }
}
15 changes: 15 additions & 0 deletions backend.native/tests/objcexport/funInterfaces.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import Kt

// Based on https://youtrack.jetbrains.com/issue/KT-44799.
private func testSAMConversion() throws {
try assertEquals(actual: FunInterfacesKt.getObject().run(), expected: 1)
try assertEquals(actual: FunInterfacesKt.getLambda().run(), expected: 2)
}

class FunInterfacesTests : SimpleTestProvider {
override init() {
super.init()

test("TestSAMConversion", testSAMConversion)
}
}

0 comments on commit f01e284

Please sign in to comment.