harec

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 92289addea6bb2766b7ee652aae93bbe26a1783b
parent d9aad3dd2d11df5d92362037751636db1960e0f0
Author: Bor Grošelj Simić <bgs@turminal.net>
Date:   Thu, 10 Mar 2022 15:22:31 +0100

add more struct autofill tests

Signed-off-by: Bor Grošelj Simić <bgs@turminal.net>

Diffstat:
Mtests/06-structs.ha | 32++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+), 0 deletions(-)

diff --git a/tests/06-structs.ha b/tests/06-structs.ha @@ -112,6 +112,17 @@ fn nested() void = { type coords = struct { x: int, y: int }; +type coords3 = struct { coords, z: int }; +type embed = struct { a: uint, b: u8 }; +// complex embedded hierarchy +type me = struct { embed, coords3, f: int }; +let g1: me = me { b = 4, x = -1, y = -2, z = -3, f = 20, ... }; +let g2: me = me { x = -1, y = -2, z = -3, f = 20, ... }; +let g3: me = me { y = -2, z = -3, f = 20, ... }; +let g4: me = me { z = -3, f = 20, ... }; +let g5: me = me { f = 20, ... }; +let g6: me = me { ... }; + fn named() void = { let x = coords { y = 10, x = 20 }; assert(x.x == 20 && x.y == 10); @@ -120,6 +131,27 @@ fn named() void = { fn autofill() void = { let x = coords { x = 10, ... }; assert(x.x == 10 && x.y == 0); + + assert(g1.a==0 && g1.b == 4 && g1.x == -1 && g1.y == -2 && g1.z == -3 && g1.f == 20); + assert(g2.a==0 && g2.b==0 && g2.x == -1 && g2.y == -2 && g2.z == -3 && g2.f == 20); + assert(g3.a==0 && g3.b==0 && g3.x==0 && g3.y == -2 && g3.z == -3 && g3.f == 20); + assert(g4.a==0 && g4.b==0 && g4.x==0 && g4.y==0 && g4.z == -3 && g4.f == 20); + assert(g5.a==0 && g5.b==0 && g5.x==0 && g5.y==0 && g5.z==0 && g5.f == 20); + assert(g6.a==0 && g6.b==0 && g6.x==0 && g6.y==0 && g6.z==0 && g6.f==0 ); + + let l1: me = me { b = 4, x = -1, y = -2, z = -3, f = 20, ... }; + let l2: me = me { x = -1, y = -2, z = -3, f = 20, ... }; + let l3: me = me { y = -2, z = -3, f = 20, ... }; + let l4: me = me { z = -3, f = 20, ... }; + let l5: me = me { f = 20, ... }; + let l6: me = me { ... }; + + assert(l1.a==0 && l1.b == 4 && l1.x == -1 && l1.y == -2 && l1.z == -3 && l1.f == 20); + assert(l2.a==0 && l2.b==0 && l2.x == -1 && l2.y == -2 && l2.z == -3 && l2.f == 20); + assert(l3.a==0 && l3.b==0 && l3.x==0 && l3.y == -2 && l3.z == -3 && l3.f == 20); + assert(l4.a==0 && l4.b==0 && l4.x==0 && l4.y==0 && l4.z == -3 && l4.f == 20); + assert(l5.a==0 && l5.b==0 && l5.x==0 && l5.y==0 && l5.z==0 && l5.f == 20); + assert(l6.a==0 && l6.b==0 && l6.x==0 && l6.y==0 && l6.z==0 && l6.f==0 ); }; fn invariants() void = {