summaryrefslogtreecommitdiff
path: root/tests/memory/test_copy_trait.zc
diff options
context:
space:
mode:
authorZuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian>2026-01-25 11:53:53 +0000
committerZuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian>2026-01-25 11:53:53 +0000
commit2dc5214fd8bb6a1168e2f2b643a36043c36c908a (patch)
tree55780a330598d3606205b662584a839ea60d0315 /tests/memory/test_copy_trait.zc
parent6a45f6a640dc8f7b5f9819d22d68cd79fbe3c260 (diff)
Fix for #121
Diffstat (limited to 'tests/memory/test_copy_trait.zc')
-rw-r--r--tests/memory/test_copy_trait.zc37
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/memory/test_copy_trait.zc b/tests/memory/test_copy_trait.zc
new file mode 100644
index 0000000..994ccee
--- /dev/null
+++ b/tests/memory/test_copy_trait.zc
@@ -0,0 +1,37 @@
+
+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;
+}