harec

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

commit 9852393e73225ebb7ca9483cea0345c2c8dc92e8
parent fe5d4a17319e099c61f0d729f2983fc03feab314
Author: Drew DeVault <sir@cmpwn.com>
Date:   Sun, 17 Jan 2021 10:07:14 -0500

tests: add 14-switch

Diffstat:
Msrc/check.c | 2+-
Atests/14-switch.ha | 31+++++++++++++++++++++++++++++++
Mtests/configure | 3++-
3 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/src/check.c b/src/check.c @@ -967,7 +967,7 @@ check_expr_switch(struct context *ctx, _case->value = xcalloc(1, sizeof(struct expression)); check_expression(ctx, acase->value, _case->value); - if (expr->terminates) { + if (_case->value->terminates) { continue; } diff --git a/tests/14-switch.ha b/tests/14-switch.ha @@ -0,0 +1,31 @@ +fn basics() void = { + let cases = [[0, 1], [1, 3], [10, 20], [11, 21], [12, 22], [13, 13]]; + for (let i = 0z; i < len(cases); i += 1z) { + let x = cases[i][0]; + let y: int = switch (x) { + 0 => x + 1, + 1 => x + 2, + 10, 11, 12 => x + 10, + * => { + x; + }, + }; + assert(y == cases[i][1]); + }; +}; + +fn termination() void = { + let x = 42; + let y: int = switch (x) { + 42 => 1337, + 24 => abort(), + * => abort(), + }; + assert(y == 1337); +}; + +export fn main() void = { + basics(); + termination(); + // TODO: Test exhaustiveness and dupe detection +}; diff --git a/tests/configure b/tests/configure @@ -16,7 +16,8 @@ tests() { 10-binarithms \ 11-globals \ 12-loops \ - 13-tagged + 13-tagged \ + 14-switch do cat <<EOF tests/$t: libhart.a tests/$t.ha