Skip to content

Commit

Permalink
Merge pull request #14 from skiptools/statics
Browse files Browse the repository at this point in the history
Test bridging of static vars and funcs
  • Loading branch information
aabewhite authored Oct 29, 2024
2 parents ddeb107 + b274058 commit de9e66d
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 42 deletions.
8 changes: 7 additions & 1 deletion Sources/SkipBridgeSamples/BridgeToSwiftSamples.swift
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,20 @@ public var kotlinSwiftClassComputedVar: SwiftHelperClass {

// SKIP @BridgeToSwift
public class KotlinClass {
public static let staticIntConstant = 1
public static var staticIntVar = 1
public static func staticFunc(string: String) -> String {
return "kotlin" + string
}

public let intConstant = 1
public let kotlinClassConstant = KotlinHelperClass()

public var intVar = 1
public var optionalIntVar: Int? = nil

public var kotlinClassVar = KotlinHelperClass()
public var optionalSwiftClassVar = SwiftHelperClass()
public var optionalSwiftClassVar: SwiftHelperClass?

public init() {
}
Expand Down
6 changes: 6 additions & 0 deletions Sources/SkipBridgeSamples/Swift/BridgeToKotlinSamples.swift
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ public var swiftKotlinClassComputedVar: KotlinHelperClass {

// SKIP @BridgeToKotlin
public class SwiftClass {
public static let staticIntConstant = 1
public static var staticIntVar = 1
public static func staticFunc(string: String) -> String {
return "swift" + string
}

public let intConstant = 1
public let swiftClassConstant = SwiftHelperClass()

Expand Down
51 changes: 51 additions & 0 deletions Sources/SkipBridgeSamples/Swift/BridgeToSwiftTestsSupport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,57 @@ public func testSupport_kotlinSwiftClassComputedVar_stringVar(value: String) ->
return kotlinSwiftClassComputedVar.stringVar
}

// SKIP @BridgeToKotlin
public func testSupport_kotlinClassMemberConstant() -> Int {
let obj = KotlinClass()
return obj.intConstant
}

// SKIP @BridgeToKotlin
public func testSupport_kotlinClassMemberVar(value: Int) -> Int {
let obj = KotlinClass()
obj.intVar = value
return obj.intVar
}

// SKIP @BridgeToKotlin
public func testSupport_kotlinClassMemberOptionalVar(value: Int?) -> Int? {
let obj = KotlinClass()
obj.optionalIntVar = value
return obj.optionalIntVar
}

// SKIP @BridgeToKotlin
public func testSupport_kotlinClassMemberKotlinClassConstant_stringVar() -> String {
let obj = KotlinClass()
return obj.kotlinClassConstant.stringVar
}

// SKIP @BridgeToKotlin
public func testSupport_kotlinClassMemberKotlinClassVar_stringVar(value: String) -> String {
let helper = KotlinHelperClass()
helper.stringVar = value
let obj = KotlinClass()
obj.kotlinClassVar = helper
return obj.kotlinClassVar.stringVar
}

// SKIP @BridgeToKotlin
public func testSupport_kotlinClassMemberStaticConstant() -> Int {
return KotlinClass.staticIntConstant
}

// SKIP @BridgeToKotlin
public func testSupport_kotlinClassMemberStaticVar(value: Int) -> Int {
KotlinClass.staticIntVar = 99
return KotlinClass.staticIntVar
}

// SKIP @BridgeToKotlin
public func testSupport_kotlinClassMemberStaticFunc(value: String) -> String {
return KotlinClass.staticFunc(string: value)
}

// SKIP @BridgeToKotlin
public func testSupport_kotlinClosure0Var() {
kotlinClosure0Var()
Expand Down
13 changes: 13 additions & 0 deletions Tests/SkipBridgeSamplesTests/BridgeToKotlinTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,19 @@ final class BridgeToKotlinTests: XCTestCase {
XCTAssertEqual(testSupport_swiftKotlinClassMemberVar_stringVar(value: "member"), "member")
}

func testSwiftClassMemberStaticConstant() {
XCTAssertEqual(SwiftClass.staticIntConstant, 1)
}

func testSwiftClassMemberStaticVar() {
SwiftClass.staticIntVar = 99
XCTAssertEqual(SwiftClass.staticIntVar, 99)
}

func testSwiftClassMemberStaticFunc() {
XCTAssertEqual(SwiftClass.staticFunc(string: "Hello"), "swiftHello")
}

public func testClosure0Var() {
swiftClosure0Var()
swiftClosure0Var = { print("reassigned") }
Expand Down
74 changes: 33 additions & 41 deletions Tests/SkipBridgeSamplesTests/BridgeToSwiftTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,39 @@ final class BridgeToSwiftTests: XCTestCase {
XCTAssertEqual(testSupport_kotlinClassComputedVar_stringVar(value: "computed"), "computed")
}

func testKotlinClassMemberConstant() {
XCTAssertEqual(testSupport_kotlinClassMemberConstant(), 1)
}

func testKotlinClassMemberVar() {
XCTAssertEqual(testSupport_kotlinClassMemberVar(value: 99), 99)
}

func testKotlinClassMemberOptionalVar() {
XCTAssertEqual(testSupport_kotlinClassMemberOptionalVar(value: 99), 99)
XCTAssertNil(testSupport_kotlinClassMemberOptionalVar(value: nil))
}

func testKotlinClassMemberKotlinClassConstant() {
XCTAssertEqual(testSupport_kotlinClassMemberKotlinClassConstant_stringVar(), "s")
}

func testKotlinClassMemberKotlinClassVar() {
XCTAssertEqual(testSupport_kotlinClassMemberKotlinClassVar_stringVar(value: "member"), "member")
}

func testKotlinClassMemberStaticConstant() {
XCTAssertEqual(testSupport_kotlinClassMemberStaticConstant(), 1)
}

func testKotlinClassMemberStaticVar() {
XCTAssertEqual(testSupport_kotlinClassMemberStaticVar(value: 99), 99)
}

func testKotlinClassMemberStaticFunc() {
XCTAssertEqual(testSupport_kotlinClassMemberStaticFunc(value: "Hello"), "kotlinHello")
}

func testClosure0Var() {
testSupport_kotlinClosure0Var()
}
Expand Down Expand Up @@ -173,45 +206,4 @@ final class BridgeToSwiftTests: XCTestCase {
let result = try await testSupport_callKotlinAsyncThrowingFunction(shouldThrow: false)
XCTAssertEqual(result, 1)
}

/*
func testSwiftClassMemberConstant() {
let value = SwiftClass()
XCTAssertEqual(value.intConstant, 1)
}

func testSwiftClassMemberVar() {
let value = SwiftClass()
value.intVar = 99
XCTAssertEqual(value.intVar, 99)
}

func testSwiftClassMemberOptionalVar() {
let value = SwiftClass()
value.optionalIntVar = 100
XCTAssertEqual(value.optionalIntVar, 100)
value.optionalIntVar = nil
XCTAssertNil(value.optionalIntVar)
}

func testSwiftClassMemberSwiftClassConstant() {
let value = SwiftClass()
XCTAssertEqual(value.swiftClassConstant.stringVar, "s")
}

func testSwiftClassMemberSwiftClassVar() {
let helper = SwiftHelperClass()
helper.stringVar = "member"
let value = SwiftClass()
value.swiftClassVar = helper
XCTAssertEqual(value.swiftClassVar.stringVar, "member")
}

// TODO:
// #if SKIP
// func testSwiftClassMemberKotlinClassVar() {
// XCTAssertEqual(testSupport_swiftKotlinClassMemberVar_stringVar("member"), "member")
// }
// #endif
*/
}

0 comments on commit de9e66d

Please sign in to comment.