summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/arrs_slices.toc47
-rw-r--r--tests/arrs_slices_expected2
-rwxr-xr-xtests/test.sh1
3 files changed, 50 insertions, 0 deletions
diff --git a/tests/arrs_slices.toc b/tests/arrs_slices.toc
new file mode 100644
index 0000000..dc7526d
--- /dev/null
+++ b/tests/arrs_slices.toc
@@ -0,0 +1,47 @@
+#include "std/mem.toc", mem;
+#include "std/io.toc", io;
+use mem;
+
+fill_array ::= fn(n ::=, a : &[n]int) {
+ for i := 0..n-1 {
+ a[i] = i*i;
+ }
+ a[0] = 17;
+}
+
+sum_array ::= fn(n ::=, a : &[n]int) total := 0 {
+ for i := 0..n-1 {
+ total += a[i];
+ }
+}
+
+fill_slice ::= fn(a: &[]int) {
+ *a = mem.news(int, 3);
+ a[0] = 1;
+ a[1] = 48;
+ a[2] = 136;
+}
+
+sum_slice ::= fn(a : &[]int) total := 0 {
+ for i := 0..a.len-1 {
+ total += a[i];
+ }
+}
+
+thing ::= fn() int {
+ foo : [5]int;
+ fill_array(&foo);
+ a := sum_array(&foo);
+ bar : []int;
+ defer dels(bar);
+ fill_slice(&bar);
+ b := sum_slice(&bar);
+ a+b
+}
+
+main ::= fn() {
+ a := thing();
+ b ::= thing();
+ io.puti(a);
+ io.puti(b);
+}
diff --git a/tests/arrs_slices_expected b/tests/arrs_slices_expected
new file mode 100644
index 0000000..d41c8a7
--- /dev/null
+++ b/tests/arrs_slices_expected
@@ -0,0 +1,2 @@
+232
+232
diff --git a/tests/test.sh b/tests/test.sh
index 1168e5b..75697ef 100755
--- a/tests/test.sh
+++ b/tests/test.sh
@@ -3,6 +3,7 @@
tests='bf
control_flow
types
+arrs_slices
defer
sizeof
new