| // Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file | |
| // for details. All rights reserved. Use of this source code is governed by a | |
| // BSD-style license that can be found in the LICENSE file. | |
| // Test simple tuple return | |
| public class TupleTest { | |
| public func getNothing() -> () { | |
| return () | |
| } | |
| public func getSingleValue() -> (Int) { | |
| return (42) | |
| } | |
| public func getCoordinates() -> (Int, Int) { | |
| return (10, 20) | |
| } | |
| public func getLabeledTuple() -> (id: Int, name: String) { | |
| return (id: 42, name: "Alice") | |
| } | |
| public func getMixedTuple() -> (Int, value: String, Bool) { | |
| return (1, value: "test", true) | |
| } | |
| // Tuple with optional elements | |
| // TODO(https://github.com/dart-lang/native/issues/1743): Enable this when optional primitives are supported. | |
| // public func getTupleWithOptionals() -> (Int?, String?) { | |
| // return (nil, "test") | |
| // } | |
| // Deeply nested tuple (3 levels) | |
| public func getDeeplyNestedTuple() -> (Int, (String, (Bool, Double))) { | |
| return (1, ("test", (true, 3.14))) | |
| } | |
| // Large tuple with many elements | |
| public func getLargeTuple() -> (Int, Int, Int, Int, Int) { | |
| return (1, 2, 3, 4, 5) | |
| } | |
| // All labeled elements | |
| public func getAllLabeledTuple() -> (x: Int, y: Int, z: String) { | |
| return (x: 10, y: 20, z: "point") | |
| } | |
| public class NestedTupleTest { | |
| public func getNestedTuple() -> (Int, (String, Bool)) { | |
| return (42, ("test", true)) | |
| } | |
| } | |
| // Test repeated nested tuples (both elements have the same tuple type) | |
| public func getRepeatedNestedTuple() -> ((Int, String), (Int, String)) { | |
| return ((1, "a"), (2, "b")) | |
| } | |
| // Test tuple with cycle | |
| // TODO(https://github.com/dart-lang/native/issues/1358): Enable this when the bug is fixed. | |
| /* | |
| public func getCircularTuple() -> (Foo, Bar)? { | |
| return nil | |
| } | |
| public class Foo { | |
| public func getCycle() -> (Foo, Bar) { | |
| return (self, Bar()) | |
| } | |
| } | |
| public class Bar { | |
| public func getCycle() -> (Foo, Bar) { | |
| return (Foo(), self) | |
| } | |
| } | |
| */ | |
| // TODO(https://github.com/dart-lang/native/issues/1743): Enable this when optional return types are fully supported. | |
| // public class OptionalTupleTest { | |
| // public func getOptionalTuple() -> (Int, String)? { | |
| // return (1, "test") | |
| // } | |
| // // Optional nested tuple | |
| // public func getOptionalNestedTuple() -> (Int, (String, Bool)?) { | |
| // return (42, nil) | |
| // } | |
| // } | |
| } |