v2 / vlib / v / tests / options / option_fixed_arr_const_test.v
20 lines · 17 sloc · 548 bytes · 7b20c9c6fb1ffa45ddd0945fd34a9f9e3fd422e5
Raw
1// Test for or-block returning a fixed array constant.
2// Regression test for issue where cgen generated invalid C cast to array type.
3const default_arr = [f32(1.0), 2.0, 3.0, 4.0]!
4
5fn get_arr(key string) ?[4]f32 {
6 if key == 'valid' {
7 return [f32(0.1), 0.2, 0.3, 0.4]!
8 }
9 return none
10}
11
12fn test_or_block_with_fixed_array_const() {
13 result := get_arr('invalid') or { default_arr }
14 assert result == default_arr
15}
16
17fn test_or_block_with_valid_key() {
18 result := get_arr('valid') or { default_arr }
19 assert result == [f32(0.1), 0.2, 0.3, 0.4]!
20}
21