commit e991ccc8e11c73f48ca3d97d214e51cc33e5a897
parent 1d768112aa06fc72a83e58745291e6cf0dd4d897
Author: Drew DeVault <sir@cmpwn.com>
Date: Tue, 12 Jan 2021 11:58:00 -0500
Add function test
Diffstat:
2 files changed, 29 insertions(+), 1 deletion(-)
diff --git a/tests/09-funcs.ha b/tests/09-funcs.ha
@@ -0,0 +1,27 @@
+fn addone(x: *int) void = {
+ *x += 1;
+};
+
+fn pointers() void = {
+ let x = 0;
+ addone(&x);
+ assert(x == 1);
+ let y = &addone;
+ y(&x);
+ assert(x == 2);
+ let z = &y;
+ z(&x);
+ assert(x == 3);
+};
+
+fn vaargs(expected: []int, values: int...) void = {
+ assert(len(expected) == len(values));
+ for (let i = 0z; i < len(values); i += 1z) {
+ assert(expected[i] == values[i]);
+ };
+};
+
+export fn main() void = {
+ pointers();
+ vaargs([1, 2, 3], 1, 2, 3);
+};
diff --git a/tests/configure b/tests/configure
@@ -11,7 +11,8 @@ tests() {
05-implicit-casts \
06-structs \
07-aliases \
- 08-slices
+ 08-slices \
+ 09-funcs
do
cat <<EOF
tests/$t: libhart.a tests/$t.ha