summaryrefslogtreecommitdiff
path: root/tests/features/test_alias.zc
diff options
context:
space:
mode:
Diffstat (limited to 'tests/features/test_alias.zc')
-rw-r--r--tests/features/test_alias.zc30
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");
}