summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2020-05-01 17:48:09 -0400
committerLeo Tenenbaum <pommicket@gmail.com>2020-05-01 17:48:09 -0400
commitf9d970a0535ec3ae4aaff6842788a89b139cfdaa (patch)
tree2d07c1f9e0844e5b1ce12a7d69605a7fad17f8e9 /tests
parentc21fa1738ea08455f906deba2762cdbd591b29ad (diff)
made output for void pointer arithmetic standard-compliant
Diffstat (limited to 'tests')
-rw-r--r--tests/ptr_arithmetic.toc33
-rw-r--r--tests/ptr_arithmetic_expected2
-rwxr-xr-xtests/test.sh1
3 files changed, 36 insertions, 0 deletions
diff --git a/tests/ptr_arithmetic.toc b/tests/ptr_arithmetic.toc
new file mode 100644
index 0000000..05975e8
--- /dev/null
+++ b/tests/ptr_arithmetic.toc
@@ -0,0 +1,33 @@
+#include "std/io.toc";
+#include "std/mem.toc";
+
+ptr_arithmetic_test ::= fn() total := 0 {
+ foo := news(int, 10);
+ for p, i := &foo {
+ *p = i;
+ }
+ p := &foo[0];
+
+ p += 2;
+ total += *p;
+ total += *(p + 3);
+ total += *(p - 1);
+
+ voidp : &void = &foo[7];
+ total += *(voidp as &int);
+ voidp = voidp + 8;
+ total += *(voidp as &int);
+ voidp += 8;
+ total += *(voidp as &int);
+ voidp = voidp - 8;
+ total += *(voidp as &int);
+ voidp -= 8;
+ total += *(voidp as &int);
+}
+
+main ::= fn() {
+ x ::= ptr_arithmetic_test();
+ y := ptr_arithmetic_test();
+ puti(x);
+ puti(y);
+}
diff --git a/tests/ptr_arithmetic_expected b/tests/ptr_arithmetic_expected
new file mode 100644
index 0000000..930ba1a
--- /dev/null
+++ b/tests/ptr_arithmetic_expected
@@ -0,0 +1,2 @@
+47
+47
diff --git a/tests/test.sh b/tests/test.sh
index 75697ef..bf58042 100755
--- a/tests/test.sh
+++ b/tests/test.sh
@@ -4,6 +4,7 @@ tests='bf
control_flow
types
arrs_slices
+ptr_arithmetic
defer
sizeof
new