Skip to content
Closed
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 @@ -91,3 +91,11 @@ public func multipleOptionals(
) -> Int64? {
1
}

public func optionalTuple() -> (Int64, String)? {
(42, "hello")
}

public func optionalTuple2() -> (Int64?, Alignment?)? {
(42, .horizontal)
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,7 @@ public func makeBigTuple() -> (
public func namedByteArrayTuple() -> (name: [UInt8], another: [UInt8]) {
(name: [1, 2, 3], another: [4, 5])
}

public func genericTypeTuple() -> (MyID<Double>, Alignment) {
(MyID(1.23), .horizontal)
}
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,30 @@ void optionalThrows() {
assertEquals("swiftError", exception.getMessage());
}
}
}

@Test
void optionalTuple() {
var result = MySwiftLibrary.optionalTuple();
assertDoesNotThrow(() -> {
var resultUnwrapped = result.orElseThrow();
assertEquals(42, resultUnwrapped.$0);
assertEquals("hello", resultUnwrapped.$1);
});
}

@Test
void optionalTuple2() {
try (var arena = SwiftArena.ofConfined()) {
var result = MySwiftLibrary.optionalTuple2(arena);
assertDoesNotThrow(() -> {
var resultUnwrapped = result.orElseThrow();
assertDoesNotThrow(() -> {
assertEquals(42, resultUnwrapped.$0.orElseThrow());
});
assertDoesNotThrow(() -> {
assertEquals(Alignment.Discriminator.HORIZONTAL, resultUnwrapped.$1.orElseThrow().getDiscriminator());
});
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package com.example.swift;

import org.junit.jupiter.api.Test;
import org.swift.swiftkit.core.SwiftArena;
import org.swift.swiftkit.core.tuple.Tuple2;
import org.swift.swiftkit.core.tuple.Tuple3;
import org.swift.swiftkit.core.tuple.Tuple16;
Expand Down Expand Up @@ -95,4 +96,13 @@ void namedByteArrayTuple() {
assertArrayEquals(new byte[] { 1, 2, 3 }, (byte[]) result.$0);
assertArrayEquals(new byte[] { 4, 5 }, (byte[]) result.$1);
}

@Test
void genericTypeTuple() {
try (var arena = SwiftArena.ofConfined()) {
var result = MySwiftLibrary.genericTypeTuple(arena);
assertEquals("1.23", result.$0.getDescription());
assertEquals(Alignment.Discriminator.HORIZONTAL, result.$1.getDiscriminator());
}
}
}
Loading
Loading