diff options
| author | Zuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian> | 2026-01-20 10:49:40 +0000 |
|---|---|---|
| committer | Zuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian> | 2026-01-20 10:49:40 +0000 |
| commit | f027a812707d68ca0690b7544175b9f302dd57ad (patch) | |
| tree | 8ca82006fa3213215ff7b70bec5e49e8421413ff /tests | |
| parent | 856198b2ea473a4fd2cd020e58db821265b21ca5 (diff) | |
Copy trait...
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/features/test_copy_trait.zc | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/features/test_copy_trait.zc b/tests/features/test_copy_trait.zc new file mode 100644 index 0000000..120dc5d --- /dev/null +++ b/tests/features/test_copy_trait.zc @@ -0,0 +1,41 @@ + +trait Copy {} + +struct Point { + x: int; + y: int; +} + +impl Copy for Point {} + +struct Mover { + val: int; +} + +fn 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"); +} + +fn test_move_default() { + var m1 = Mover { val: 1 }; + var m2 = m1; // Moved + + // Uncommenting this should cause compile error + // var m3 = m1; +} + +fn main() { + test_copy_trait(); + test_move_default(); + "Copy Trait Works!"; +} |
