diff options
| author | Zuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian> | 2026-01-25 11:53:53 +0000 |
|---|---|---|
| committer | Zuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian> | 2026-01-25 11:53:53 +0000 |
| commit | 2dc5214fd8bb6a1168e2f2b643a36043c36c908a (patch) | |
| tree | 55780a330598d3606205b662584a839ea60d0315 /tests/features | |
| parent | 6a45f6a640dc8f7b5f9819d22d68cd79fbe3c260 (diff) | |
Fix for #121
Diffstat (limited to 'tests/features')
| -rw-r--r-- | tests/features/test_copy_trait.zc | 37 | ||||
| -rw-r--r-- | tests/features/test_drop.zc | 26 | ||||
| -rw-r--r-- | tests/features/test_move_semantics.zc | 55 | ||||
| -rw-r--r-- | tests/features/test_resources.zc | 59 |
4 files changed, 0 insertions, 177 deletions
diff --git a/tests/features/test_copy_trait.zc b/tests/features/test_copy_trait.zc deleted file mode 100644 index 994ccee..0000000 --- a/tests/features/test_copy_trait.zc +++ /dev/null @@ -1,37 +0,0 @@ - -trait Copy {} - -struct Point { - x: int; - y: int; -} - -impl Copy for Point {} - -struct Mover { - val: int; -} - -test "copy_trait" { - var p1 = Point { x: 10, y: 20 }; - var p2 = p1; // Copy, not move - - // Both should be valid - assert(p1.x == 10, "p1 invalid after copy"); - assert(p2.x == 10, "p2 invalid after copy"); - - // Modify p2, p1 should be unchanged - p2.x = 30; - assert(p1.x == 10, "p1 changed after p2 modification"); - assert(p2.x == 30, "p2 modification failed"); - - println "Copy Trait Works!"; -} - -test "move_default" { - var m1 = Mover { val: 1 }; - var m2 = m1; // Moved - - // Uncommenting this should cause compile error - // var m3 = m1; -} diff --git a/tests/features/test_drop.zc b/tests/features/test_drop.zc deleted file mode 100644 index 8b34efe..0000000 --- a/tests/features/test_drop.zc +++ /dev/null @@ -1,26 +0,0 @@ -import "../../std/mem.zc" - -var DROP_CALLED = 0; - -struct MyResource { - id: int; -} - -impl Drop for MyResource { - fn drop(self) { - println "Dropping MyResource {self.id}"; - DROP_CALLED = 1; - } -} - -test "drop_trait" { - { - var res = MyResource { id: 1 }; - // Scope ends here, drop should be called - } - - if (DROP_CALLED != 1) { - println "Error: Drop was not called!"; - exit(1); - } -} diff --git a/tests/features/test_move_semantics.zc b/tests/features/test_move_semantics.zc deleted file mode 100644 index bf0d717..0000000 --- a/tests/features/test_move_semantics.zc +++ /dev/null @@ -1,55 +0,0 @@ - -struct Point { - x: int; -} - -struct Mover { - val: int; -} - -test "basic_move" { - var p1 = Mover { val: 10 }; - var p2 = p1; // p1 moved to p2 - - // Valid usage of p2 - assert(p2.val == 10, "p2 should be valid"); - - // Invalid usage of p1 (Uncomment to test compiler error) - // var p3 = p1; -} - -test "primitive_copy" { - var i = 10; - var j = i; // Copy - var k = i; // Copy again - should be valid - assert(k == 10, "Primitive copy failed"); -} - -test "reassignment" { - var m1 = Mover { val: 1 }; - var m2 = m1; // m1 moved - - m1 = Mover { val: 2 }; // Resurrect m1 - var m3 = m1; // Valid now - assert(m3.val == 2, "Resurrection failed"); -} - -fn consume(m: Mover) { - assert(m.val == 10, "Func arg failed"); -} - -test "func_arg" { - var m = Mover { val: 10 }; - consume(m); // m moved - - // 2. Use after move (Call - Negative Test) - // consume(m); // Should fail: Use of moved value 'm' -} - -/* -// 3. Use after return (Negative Test) -fn fail_return(m: Mover) -> Mover { - var m2 = m; - return m; // Should fail: Use of moved value 'm' -} -*/ diff --git a/tests/features/test_resources.zc b/tests/features/test_resources.zc deleted file mode 100644 index dc7b9f9..0000000 --- a/tests/features/test_resources.zc +++ /dev/null @@ -1,59 +0,0 @@ - -// Copy Trait -@derive(Copy) -struct Point { x: int; y: int; } - -// Clone Pattern -trait Clone { - fn clone(self) -> Self; -} - -struct Box { val: int; } - -impl Clone for Box { - fn clone(self) -> Box { - return Box{val: self.val}; - } -} - -// Re-initialization -struct Resource { ptr: void*; } - -// Function Param Helper -fn take_point(p: Point) { - if p.x != 10 { - // Error - } -} - -test "Resource Semantics" { - "Testing Resource Semantics..."; - - var p1 = Point{x: 10, y: 20}; - var p2 = p1; // Copied - - var b1 = Box{val: 99}; - var b2 = b1.clone(); - // var b3 = b1; // This would move if uncommented. - - if b2.val != 99 { - !"Clone failed"; - exit(1); - } - - // Re-initialization - // struct Resource (Global) - - var r1 = Resource{ptr: NULL}; - var r2 = r1; // Moved - - r1 = Resource{ptr: NULL}; // Re-init - var r3 = r1; // Valid again - - // Function Param Move (Simulated) - take_point(p1); - take_point(p1); // Still valid because Copy - - "Resource Semantics Passed."; -} - |
