summaryrefslogtreecommitdiff
path: root/tests/memory/test_drop.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_drop.zc
parent6a45f6a640dc8f7b5f9819d22d68cd79fbe3c260 (diff)
Fix for #121
Diffstat (limited to 'tests/memory/test_drop.zc')
-rw-r--r--tests/memory/test_drop.zc26
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/memory/test_drop.zc b/tests/memory/test_drop.zc
new file mode 100644
index 0000000..8b34efe
--- /dev/null
+++ b/tests/memory/test_drop.zc
@@ -0,0 +1,26 @@
+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);
+ }
+}