diff options
| author | 2026-10-12 08:46:23 +0330 | |
|---|---|---|
| committer | 2026-10-12 08:46:23 +0330 | |
| commit | ecc350ca5c2eb50be8309c5f14f8bf0d87db9a02 (patch) | |
| tree | 70e0af76a1b13affff7c6cc8aac7b3e6ef960478 /tests/programs/arrays.zc | |
a
Diffstat (limited to 'tests/programs/arrays.zc')
| -rw-r--r-- | tests/programs/arrays.zc | 23 |
1 files changed, 23 insertions, 0 deletions
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; +} |
