harec

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit c9d110fd1ff4bd8c38e94c36622f5289347e25a1
parent 682e8d0662e4b1a155c8fbd1efe225f94d1e31d9
Author: Drew DeVault <sir@cmpwn.com>
Date:   Sun, 25 Jul 2021 08:59:18 +0200

gen: merge call & deref tests

Diffstat:
Dtests/903-call.ha | 27---------------------------
Atests/903-postfix.ha | 60++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Rtests/905-copy.ha -> tests/904-copy.ha | 0
Dtests/904-deref.ha | 31-------------------------------
Mtests/configure | 5++---
5 files changed, 62 insertions(+), 61 deletions(-)

diff --git a/tests/903-call.ha b/tests/903-call.ha @@ -1,27 +0,0 @@ -type coords = struct { x: int, y: int }; - -fn foo() size = 2; -fn equal(x: int, y: int) bool = x == y; -fn aggregate(c: coords) coords = c; - -export fn main() int = { - // Indirect - let x: size = foo(); - assert(x == 2); - - // Direct - let x = [1, 2, 3]; - assert(x[foo()] == 3); - - // Direct & indirect params - let x = 1234; - assert(equal(x, 1234)); - - // Aggregate params and return - let x = coords { x = 1234, y = 4321 }; - let x = aggregate(x); - // TODO: Use && - assert(x.x == 1234); - assert(x.y == 4321); - return 0; -}; diff --git a/tests/903-postfix.ha b/tests/903-postfix.ha @@ -0,0 +1,60 @@ +type coords = struct { x: size, y: size }; + +fn foo() size = 2; +fn equal(x: int, y: int) bool = x == y; +fn aggregate(c: coords) coords = c; +fn not(x: bool) bool = x == false; + +fn deref() void = { + let a = coords { x = 10, y = 20 }; + let b = &a; + let c = &b; + assert(a.x == 10); + assert(b.x == 10); + assert(c.x == 10); + + let x = [1, 3, 3, 7]; + let y = &x; + let z = &y; + assert(x[2] == 3); + assert(y[2] == 3); + assert(z[2] == 3); + + let q = coords { x = 2, y = 2 }; + let o = &q; + assert(x[q.x] == 3); + assert(x[o.x] == 3); + + let f = &not; + let g = &f; + assert(not(true) == false); + assert(f(true) == false); + assert(g(true) == false); +}; + +fn calls() void = { + // Indirect + let x: size = foo(); + assert(x == 2); + + // Direct + let x = [1, 2, 3]; + assert(x[foo()] == 3); + + // Direct & indirect params + let x = 1234; + assert(equal(x, 1234)); + + // Aggregate params and return + let x = coords { x = 1234, y = 4321 }; + let x = aggregate(x); + // TODO: Use && + assert(x.x == 1234); + assert(x.y == 4321); +}; + +export fn main() int = { + deref(); + calls(); + return 0; +}; diff --git a/tests/905-copy.ha b/tests/904-copy.ha diff --git a/tests/904-deref.ha b/tests/904-deref.ha @@ -1,31 +0,0 @@ -type coords = struct { x: size, y: size }; - -fn not(x: bool) bool = x == false; - -export fn main() int = { - let a = coords { x = 10, y = 20 }; - let b = &a; - let c = &b; - assert(a.x == 10); - assert(b.x == 10); - assert(c.x == 10); - - let x = [1, 3, 3, 7]; - let y = &x; - let z = &y; - assert(x[2] == 3); - assert(y[2] == 3); - assert(z[2] == 3); - - let q = coords { x = 2, y = 2 }; - let o = &q; - assert(x[q.x] == 3); - assert(x[o.x] == 3); - - let f = &not; - let g = &f; - assert(not(true) == false); - assert(f(true) == false); - assert(g(true) == false); - return 0; -}; diff --git a/tests/configure b/tests/configure @@ -7,9 +7,8 @@ tests() { 900-basics \ 901-primitives \ 902-arithm \ - 903-call \ - 904-deref \ - 905-copy + 903-postfix \ + 904-copy do cat <<EOF tests/$t: harec tests/$t.ha tests/rt.o