1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

builtin: add operator precedence test

This commit is contained in:
Alexey 2020-04-02 20:02:49 +03:00 committed by GitHub
parent 16acc5f312
commit 6309e699e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -70,13 +70,31 @@ fn test_str_methods() {
assert u64(-1).str() == '18446744073709551615' assert u64(-1).str() == '18446744073709551615'
} }
fn test_and() { fn test_and_precendence() {
c:=[1,2,3,4,5] assert (2 & 0 == 0) == ((2 & 0) == 0)
assert c[0] & 1 != 0 assert (2 & 0 != 0) == ((2 & 0) != 0)
assert c[1] & 1 == 0 assert (0 & 0 >= 0) == ((0 & 0) >= 0)
assert c[2] & 1 != 0 assert (0 & 0 <= 0) == ((0 & 0) <= 0)
assert c[3] & 1 == 0 assert (0 & 0 < 1) == ((0 & 0) < 1)
assert c[4] & 1 != 0 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() { fn test_i8_print() {