commit a73765fe2e9b3497637af42b5fcfa73083557d2f parent 9aa447a7047b249c7649abfc339841e28525c765 Author: Eyal Sawady <ecs@d2evs.net> Date: Fri, 5 Feb 2021 12:17:00 -0500 Add if tests Diffstat:
A | tests/20-if.ha | | | 74 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
M | tests/configure | | | 3 | ++- |
2 files changed, 76 insertions(+), 1 deletion(-)
diff --git a/tests/20-if.ha b/tests/20-if.ha @@ -0,0 +1,74 @@ +fn equality() void = { + assert((if (2 == 2) true else false)); +}; + +fn inequality() void = { + assert((if (2 == 1) false else true)); +}; + +fn else_() void = { + assert((if (2 == 1) false else true)); +}; + +fn elseif() void = { + assert((if (2 == 1) false + else if (2 == 2) true + else false)); +}; + +fn justif() void = { + let x: int = 1; + if (true) { + // asserts that the side-effects work + x = 0; + }; + assert(x == 0); +}; + +fn gt() void = { + assert((if (1 > 2) false else true)); +}; + +fn gte() void = { + assert((if (2 >= 2) true else false)); +}; + +fn lt() void = { + assert((if (1 < 2) true else false)); +}; + +fn lte() void = { + assert((if (2 <= 2) true else false)); +}; + +fn and2(left: bool) bool = { + return if (left && 1 / 0 == 0) false else true; +}; + +fn and() void = { + assert((if (true && and2(1 == 1 && false)) true else false)); +}; + +fn or() void = { + assert((if (true || 1 / 0 == 0) true else false)); +}; + +fn tagged() void = { + assert((if (true) 1u8 else 0i8) as u8 == 1u8); + assert((if (false) 1u8 else 0i8) as i8 == 0i8); +}; + +export fn main() void = { + equality(); + inequality(); + else_(); + elseif(); + justif(); + gt(); + gte(); + lt(); + lte(); + and(); + or(); + tagged(); +}; diff --git a/tests/configure b/tests/configure @@ -22,7 +22,8 @@ tests() { 16-defer \ 17-alloc \ 18-match \ - 19-append + 19-append \ + 20-if do cat <<EOF tests/$t: libhart.a tests/$t.ha