Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ public class MySwiftClass {
self.y = 5
}

convenience public init(throwing: Bool) throws {
if throwing {
throw MySwiftError.swiftError
} else {
self.init()
}
}

deinit {
p("deinit called!")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ public struct MySwiftStruct {
self.len = len
}

public init?(doInit: Bool) {
if doInit {
self.init(cap: 10, len: 10)
} else {
return nil
}
}

public func getCapacity() -> Int64 {
self.cap
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ void init_withParameters() {
}
}

@Test
void init_throwing() {
try (var arena = SwiftArena.ofConfined()) {
Exception exception = assertThrows(Exception.class, () -> MySwiftClass.init(true, arena));
assertEquals("swiftError", exception.getMessage());

MySwiftClass c = assertDoesNotThrow(() -> MySwiftClass.init(false, arena));
assertNotNull(c);
}
}

@Test
void sum() {
try (var arena = SwiftArena.ofConfined()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import org.swift.swiftkit.core.ConfinedSwiftMemorySession;
import org.swift.swiftkit.core.SwiftArena;

import java.util.Optional;

import static org.junit.jupiter.api.Assertions.*;

public class MySwiftStructTest {
Expand All @@ -30,6 +32,17 @@ void init() {
}
}

@Test
void init_optional() {
try (var arena = SwiftArena.ofConfined()) {
assertEquals(Optional.empty(), MySwiftStruct.init(false, arena));

Optional<MySwiftStruct> optionalStruct = MySwiftStruct.init(true, arena);
assertTrue(optionalStruct.isPresent());
assertEquals(10, optionalStruct.get().getLen());
}
}

@Test
void getAndSetLen() {
try (var arena = SwiftArena.ofConfined()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ SwiftJava's `swift-java jextract` tool automates generating Java bindings from S
| Swift Feature | FFM | JNI |
|--------------------------------------------------------------------------------------|----------|-----|
| Initializers: `class`, `struct` | ✅ | ✅ |
| Optional Initializers / Throwing Initializers | ❌ | |
| Optional Initializers / Throwing Initializers | ❌ | |
| Deinitializers: `class`, `struct` | ✅ | ✅ |
| `enum` | ❌ | ✅ |
| `actor` | ❌ | ❌ |
Expand Down
Loading