| 1 | const fixed_array_expr_hi = [u8(1), 2, 3, 4]! |
| 2 | const fixed_array_expr_lo = [u8(5), 6, 7, 8]! |
| 3 | |
| 4 | struct FixedArrayExprMesh { |
| 5 | mut: |
| 6 | highlight [4]u8 |
| 7 | } |
| 8 | |
| 9 | fn 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 | |
| 13 | fn 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 | |
| 20 | fn 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 | |
| 30 | fn 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 | |