From 6309e699e52f22220f89d2fd77d60fed134997da Mon Sep 17 00:00:00 2001 From: Alexey Date: Thu, 2 Apr 2020 20:02:49 +0300 Subject: [PATCH] builtin: add operator precedence test --- vlib/builtin/int_test.v | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/vlib/builtin/int_test.v b/vlib/builtin/int_test.v index fc680c70db..f77bcc93b2 100644 --- a/vlib/builtin/int_test.v +++ b/vlib/builtin/int_test.v @@ -70,13 +70,31 @@ fn test_str_methods() { assert u64(-1).str() == '18446744073709551615' } -fn test_and() { - c:=[1,2,3,4,5] - assert c[0] & 1 != 0 - assert c[1] & 1 == 0 - assert c[2] & 1 != 0 - assert c[3] & 1 == 0 - assert c[4] & 1 != 0 +fn test_and_precendence() { + assert (2 & 0 == 0) == ((2 & 0) == 0) + assert (2 & 0 != 0) == ((2 & 0) != 0) + assert (0 & 0 >= 0) == ((0 & 0) >= 0) + assert (0 & 0 <= 0) == ((0 & 0) <= 0) + assert (0 & 0 < 1) == ((0 & 0) < 1) + assert (1 & 2 > 0) == ((1 & 2) > 0) +} + +fn test_or_precendence() { + assert (1 | 0 == 0) == ((1 | 0) == 0) + assert (1 | 0 != 1) == ((1 | 0) != 1) + assert (1 | 0 >= 2) == ((1 | 0) >= 2) + assert (1 | 0 <= 0) == ((1 | 0) <= 0) + assert (1 | 0 < 0) == ((1 | 0) < 0) + assert (1 | 0 > 1) == ((1 | 0) > 1) +} + +fn test_xor_precendence() { + assert (1 ^ 0 == 2) == ((1 ^ 0) == 2) + assert (1 ^ 0 != 2) == ((1 ^ 0) != 2) + assert (1 ^ 0 >= 0) == ((1 ^ 0) >= 0) + assert (1 ^ 0 <= 1) == ((1 ^ 0) <= 1) + assert (1 ^ 0 < 0) == ((1 ^ 0) < 0) + assert (1 ^ 0 > 1) == ((1 ^ 0) > 1) } fn test_i8_print() {