diff options
| author | Zuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian> | 2026-01-23 15:55:02 +0000 |
|---|---|---|
| committer | Zuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian> | 2026-01-23 15:55:02 +0000 |
| commit | c735d4b45f2db336e2aff8d94da7a08bb1fad68f (patch) | |
| tree | 16f079ddb7e400ddce4a83be47bed5cc6d46c884 /tests | |
| parent | 8d0ea93a7220730ccce754429549fd63e4eeaa7c (diff) | |
Update for tuples.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/features/test_tuples.zc | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/features/test_tuples.zc b/tests/features/test_tuples.zc new file mode 100644 index 0000000..f8ccb1f --- /dev/null +++ b/tests/features/test_tuples.zc @@ -0,0 +1,29 @@ +fn get_pair() -> (int, int) { + return (10, 20); +} + +fn main() { + // Inferred type tuple literal + var p = (1, 2); + assert(p.0 == 1, "Tuple access 0"); + assert(p.1 == 2, "Tuple access 1"); + + // Function returning tuple + var p2 = get_pair(); + assert(p2.0 == 10, "Tuple return 0"); + assert(p2.1 == 20, "Tuple return 1"); + + // Explicit type tuple + var p3: (int, int) = (5, 6); + assert(p3.0 == 5, "Explicit tuple 0"); + assert(p3.1 == 6, "Explicit tuple 1"); + + // Different types + var mixed: (int, string) = (10, "Hello"); + assert(mixed.0 == 10, "Mixed 0"); + + // Tuple destructuring + var (a, b) = get_pair(); + assert(a == 10, "Destructured a"); + assert(b == 20, "Destructured b"); +} |
