From ecc350ca5c2eb50be8309c5f14f8bf0d87db9a02 Mon Sep 17 00:00:00 2001 From: Moon Flower Date: Mon, 12 Oct 2026 08:46:23 +0330 Subject: a --- tests/programs/arrays.zc | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 tests/programs/arrays.zc (limited to 'tests/programs/arrays.zc') diff --git a/tests/programs/arrays.zc b/tests/programs/arrays.zc new file mode 100644 index 0000000..a8a12bf --- /dev/null +++ b/tests/programs/arrays.zc @@ -0,0 +1,23 @@ +// growable arrays and fixed ones +struct point { int x, y; }; +fn main() { + let before = live_objects(); + { + []int a = new([]int); + for (int i = 0; i < 100; i++) push(a, i * i); + put_n(len(a)); put_c(' '); put_n(cap(a)); put_c(' '); put_n(a[99]); put_c(' '); + put_n(pop(a)); put_c(' '); put_n(len(a)); put_c(' '); + resize(a, 3); put_n(len(a)); put_c(' '); put_n(a[2]); put_c(' '); + fixed []int f = new(fixed []int, 5); + f[4] = 7; put_n(f[4] + len(f)); put_c(' '); + []point ps = new([]point, 2); + ps[1].y = 9; resize(ps, 10); put_n(ps[1].y + len(ps)); put_c(' '); + [8]int st; put_n(len(st)); put_c(' '); + []point* owned = new([]point*); + for (int i = 0; i < 20; i++) { point* p = new(point); p.x = i; push(owned, d*p); } + put_n(owned[19].x); put_c(' '); + put_n(live_objects() - before); put_c(10); + } + put_n(live_objects() - before); put_c(10); + return 0; +} -- cgit v1.2.3