summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2020-03-12 19:31:28 -0400
committerLeo Tenenbaum <pommicket@gmail.com>2020-03-12 19:32:00 -0400
commit65c9211b961c0c5d2c48b37533825852013687b5 (patch)
treef00d0eaa5f844e35f05712e33e738679e992c5a4 /tests
parent1338c083d649ab15d4dee63a6f6d49e891f9cdfa (diff)
added varargs test, showed that somethings wrong
Diffstat (limited to 'tests')
-rwxr-xr-xtests/test.sh1
-rw-r--r--tests/varargs.toc37
-rw-r--r--tests/varargs_expected9
3 files changed, 47 insertions, 0 deletions
diff --git a/tests/test.sh b/tests/test.sh
index b0b27e1..ac195bc 100755
--- a/tests/test.sh
+++ b/tests/test.sh
@@ -1,6 +1,7 @@
#!/bin/bash
tests='bf
+varargs
arr
arr2
arr3
diff --git a/tests/varargs.toc b/tests/varargs.toc
new file mode 100644
index 0000000..7ffb758
--- /dev/null
+++ b/tests/varargs.toc
@@ -0,0 +1,37 @@
+printf ::= #foreign("printf","libc.so.6") fn(#C &"const char", #C ..) #C int;
+
+tprintf ::= fn(fmt: []char, args: ..) {
+ printf(&fmt[0], args);
+};
+
+sum ::= fn(x: ..) int {
+ total := 0;
+ n := 0;
+ for a, i := x {
+ total += a + i / i;
+ n += 1;
+ }
+ total - n
+};
+
+sumc ::= fn(x:: ..) int {
+ total := 0;
+ n := 0;
+ for a, i := x {
+ total += a + i / i;
+ n += 1;
+ }
+ total - n
+};
+
+do_printing ::= fn(x::..) {
+ tprintf("%ld\n",sum(x));
+ tprintf("%ld\n",sumc(x));
+};
+
+main ::= fn() {
+ do_printing();
+ do_printing(1,2,3);
+ do_printing(4);
+ do_printing(1,10,100,1000,10000);
+};
diff --git a/tests/varargs_expected b/tests/varargs_expected
new file mode 100644
index 0000000..5436134
--- /dev/null
+++ b/tests/varargs_expected
@@ -0,0 +1,9 @@
+0
+0
+6
+6
+4
+4
+11111
+11111
+