vxx2 / vlib / v / tests / fixed_array_expr_field_assign_test.v
38 lines · 29 sloc · 1.01 KB · ab695faf0cc6c36b8cc4785211ff567a985b3dd6
Raw
1const fixed_array_expr_hi = [u8(1), 2, 3, 4]!
2const fixed_array_expr_lo = [u8(5), 6, 7, 8]!
3
4struct FixedArrayExprMesh {
5mut:
6 highlight [4]u8
7}
8
9fn fixed_array_expr_set_if(mut mesh FixedArrayExprMesh, highlighted bool) {
10 mesh.highlight = if highlighted { fixed_array_expr_hi } else { fixed_array_expr_lo }
11}
12
13fn fixed_array_expr_set_match(mut mesh FixedArrayExprMesh, highlighted bool) {
14 mesh.highlight = match highlighted {
15 true { fixed_array_expr_hi }
16 false { fixed_array_expr_lo }
17 }
18}
19
20fn test_fixed_array_field_assign_from_if_expr() {
21 mut mesh := FixedArrayExprMesh{}
22
23 fixed_array_expr_set_if(mut mesh, true)
24 assert mesh.highlight == fixed_array_expr_hi
25
26 fixed_array_expr_set_if(mut mesh, false)
27 assert mesh.highlight == fixed_array_expr_lo
28}
29
30fn test_fixed_array_field_assign_from_match_expr() {
31 mut mesh := FixedArrayExprMesh{}
32
33 fixed_array_expr_set_match(mut mesh, true)
34 assert mesh.highlight == fixed_array_expr_hi
35
36 fixed_array_expr_set_match(mut mesh, false)
37 assert mesh.highlight == fixed_array_expr_lo
38}
39