diff options
| author | Zuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian> | 2026-01-17 18:09:31 +0000 |
|---|---|---|
| committer | Zuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian> | 2026-01-17 18:09:31 +0000 |
| commit | 7ac5be7ba8f700f69009c5e980ee7b12b0653586 (patch) | |
| tree | 85c44ed59d768d0bae8849b4590655b82a2a8c57 /tests | |
| parent | 661a71defc66cfeea1681dddd944ba017087f78a (diff) | |
Fix for #60
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/features/test_alias.zc | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/tests/features/test_alias.zc b/tests/features/test_alias.zc index f7bc42a..ec84947 100644 --- a/tests/features/test_alias.zc +++ b/tests/features/test_alias.zc @@ -17,6 +17,15 @@ fn add(a: int, b: int) -> int { return a + b; } +// Generic struct for alias testing +struct Vec2<T> { + x: T; + y: T; +} + +alias Vec2f = Vec2<f32>; +alias Vec2i = Vec2<int>; + test "alias basic" { var x: MyInt = 10; var ptr: MyIntPtr = &x; @@ -28,14 +37,33 @@ test "alias basic" { assert(res == 11, "Function with alias arg failed"); } +test "alias struct" { + var p: Point = Point{x: 0, y: 0}; p.x = 100; p.y = 200; assert(p.x == 100, "Struct alias access failed"); } +test "alias generic struct" { + var v = Vec2f{x: 1.5, y: 2.5}; + assert(v.x > 1.0, "Generic alias field access failed"); + assert(v.y > 2.0, "Generic alias field access failed"); + + var vi = Vec2i{x: 10, y: 20}; + assert(vi.x == 10, "Generic int alias failed"); + assert(vi.y == 20, "Generic int alias failed"); +} + +test "alias fstring" { + var v = Vec2f{x: 3.14, y: 6.28}; + // This tests that f-string interpolation correctly resolves the alias + println "v.x = {v.x}, v.y = {v.y}"; +} + test "alias function pointer" { // var op: BinOp; - // Assignment currently not supported for function types without casting op = add; + // Assignment currently not supported for function types without casting + // op = add; // assert(op(1, 2) == 3, "Function alias"); } |
