commit 7ecfa4acc36b37a549b5ff44d19cc754137af45c
parent 880dea36a4dcda574262dc70349b4baa08c9f4b8
Author: Drew DeVault <sir@cmpwn.com>
Date: Sun, 10 Jan 2021 12:06:47 -0500
Add basic struct test
Diffstat:
2 files changed, 20 insertions(+), 1 deletion(-)
diff --git a/tests/06-structs.ha b/tests/06-structs.ha
@@ -0,0 +1,18 @@
+fn padding() void = {
+ assert(size(struct { x: i32, y: i32 }) == 8z);
+ assert(size(struct { x: i32, y: i64 }) == 16z);
+ assert(size(union { x: i8, y: i16, z: i32 }) == 4z);
+};
+
+fn storage() void = {
+ let coords = struct { x: i32 = 10i32, y: i32 = 20i32 };
+ let ptr = &coords: *[*]i32;
+ assert(ptr[0] == 10i32);
+ assert(ptr[1] == 20i32);
+};
+
+export fn main() void = {
+ padding();
+ storage();
+ // TODO: These tests need to be expanded when field selection works
+};
diff --git a/tests/configure b/tests/configure
@@ -8,7 +8,8 @@ tests() {
02-integers \
03-pointers \
04-strings \
- 05-implicit-casts
+ 05-implicit-casts \
+ 06-structs
do
cat <<EOF
tests/$t: libhart.a tests/$t.ha