commit 8bc8965c5eb6f58af551b073ec022a3a54b3df4d
parent 46d79bea85c927a3aeb6f8ff4ed04f551a72827c
Author: Eyal Sawady <ecs@d2evs.net>
Date: Sun, 21 Feb 2021 18:06:21 -0500
Add delete tests
Diffstat:
2 files changed, 44 insertions(+), 1 deletion(-)
diff --git a/tests/22-delete.ha b/tests/22-delete.ha
@@ -0,0 +1,42 @@
+use rt;
+
+type my_slice = []int;
+
+fn index() void = {
+ let x = alloc([]int, [1, 2, 3, 4, 5]);
+ let y = &x: *my_slice;
+
+ delete(x[1]);
+ assert(len(x) == 4);
+ assert(x[0] == 1 && x[1] == 3 && x[2] == 4 && x[3] == 5);
+
+ delete(y[3]);
+ assert(len(x) == 3);
+ assert(x[0] == 1 && x[1] == 3 && x[2] == 4);
+ free(x);
+};
+
+fn slice() void = {
+ let x = alloc([]int, [1, 2, 3, 4, 5]): my_slice;
+ let y = &x;
+ const s = y: *rt::slice;
+
+ delete(x[..3]);
+ assert(len(x) == 2);
+ assert(x[0] == 4 && x[1] == 5);
+
+ delete(y[..]);
+ assert(len(x) == 0);
+ assert(s.capacity < 5);
+
+ append(x, 6, 7, 8, 9);
+ delete(x[1..3]);
+ assert(len(x) == 2);
+ assert(x[0] == 6 && x[1] == 9);
+ free(x);
+};
+
+export fn main() void = {
+ index();
+ slice();
+};
diff --git a/tests/configure b/tests/configure
@@ -24,7 +24,8 @@ tests() {
18-match \
19-append \
20-if \
- 21-tuples
+ 21-tuples \
+ 22-delete
do
cat <<EOF
tests/$t: libhart.a tests/$t.ha