diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/features/test_alias.zc | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/features/test_alias.zc b/tests/features/test_alias.zc index ec84947..7b0eaa4 100644 --- a/tests/features/test_alias.zc +++ b/tests/features/test_alias.zc @@ -23,6 +23,15 @@ struct Vec2<T> { y: T; } +impl Vec2<T> { + fn neg(self) -> Vec2<T> { + return Vec2<T>{x: -self.x, y: -self.y}; + } + fn add(self, rhs: Vec2<T>) -> Vec2<T> { + return Vec2<T>{x: self.x + rhs.x, y: self.y + rhs.y}; + } +} + alias Vec2f = Vec2<f32>; alias Vec2i = Vec2<int>; @@ -67,3 +76,19 @@ test "alias function pointer" { // op = add; // assert(op(1, 2) == 3, "Function alias"); } + +test "alias operator overloading" { + var v = Vec2f{x: 1.0, y: 1.0}; + v = -v; // Should call __neg + assert(v.x == -1.0, "Unary operator generic alias failed"); + + v += v; // Should call __add (-1 + -1 = -2) + assert(v.x == -2.0, "Compound assignment generic alias failed"); + + // Control + var v2 = Vec2<f32>{x: 1.0, y: 1.0}; + v2 = -v2; + v2 += v2; + assert(v2.x == -2.0, "Control generic operator overloading failed"); +} + |
