diff options
| author | Zuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian> | 2026-01-14 23:59:54 +0000 |
|---|---|---|
| committer | Zuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian> | 2026-01-14 23:59:54 +0000 |
| commit | dcfdc053cb5f9fb4d5eac0a2233c75126b7a8188 (patch) | |
| tree | f34f30b382fa22d6fd0af46875a5b4b26d00feff /tests/features/test_destructuring.zc | |
| parent | a918df69269a39ef7350a645b5db025d66ecb18a (diff) | |
Added some of the tests.
Diffstat (limited to 'tests/features/test_destructuring.zc')
| -rw-r--r-- | tests/features/test_destructuring.zc | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/features/test_destructuring.zc b/tests/features/test_destructuring.zc new file mode 100644 index 0000000..b898582 --- /dev/null +++ b/tests/features/test_destructuring.zc @@ -0,0 +1,38 @@ +struct Point { + x: int; + y: int; +} + +struct Rect { + w: int; + h: int; +} + +fn tuple_ret() -> (int, int) { + return (10, 20); +} + +test "test_destructuring" { + var p = Point{x: 1, y: 2}; + + // Explicit Struct Destructuring (Shorthand) + var Point{x, y} = p; + assert(x == 1, "x is 1"); + assert(y == 2, "y is 2"); + + // Explicit Struct Destructuring (Renamed) + var Point{x: a, y: b} = p; + assert(a == 1, "a is 1"); + assert(b == 2, "b is 2"); + + // Anonymous Struct Destructuring (Inferred) + // Note: Anonymous block only supports shorthand {x, y} currently. + // var {x: x2} = p; // Not supported yet in anonymous block parser + + // Tuple Destructuring + var (t1, t2) = tuple_ret(); + assert(t1 == 10, "t1 is 10"); + assert(t2 == 20, "t2 is 20"); + + println "Destructuring OK"; +} |
