v2 / vlib / v / tests / casts / conversions_test.v
16 lines · 15 sloc · 281 bytes · 6488041a749df9762348d019c4223908c476f2e2
Raw
1fn test_conv_to_bool() {
2 v := 0
3 mut b := v != 0
4 assert !b
5 b = u64(&v) != 0
6 assert b
7 // check true -> 1
8 assert int(b) == 1
9
10 // branchless tests (can be important for manual optimization)
11 arr := [7, 8]!
12 e := arr[int(b)]
13 assert e == 8
14 b = e < 0
15 assert arr[int(b)] == 7
16}
17