v2 / vlib / v / tests / aliases / alias_fixed_array_of_struct_test.v
53 lines · 41 sloc · 942 bytes · eba20d868cf88bfea81546e5da3d3c9da6a1b457
Raw
1struct Foo {}
2
3type Bar = [4]Foo
4
5struct Baz {
6 data int
7}
8
9type BazFixed = [2]Baz
10type NestedBazFixed = [2]BazFixed
11
12struct Empty {}
13
14type EmptyFixed = [2]Empty
15
16type Dot = [3]f64
17type Box = [2]Dot
18
19struct Tst {
20 box Box
21 val int
22}
23
24fn test_alias_fixed_array_of_struct() {
25 bar := Bar([Foo{}, Foo{}, Foo{}, Foo{}]!)
26 println(bar)
27 assert '${bar}' == 'Bar([Foo{}, Foo{}, Foo{}, Foo{}])'
28}
29
30fn test_nested_fixed_array_alias_of_named_struct() {
31 nested := [2]NestedBazFixed{}
32 assert nested.len == 2
33 assert nested[0].len == 2
34 assert nested[0][0][0].data == 0
35}
36
37fn test_fixed_array_alias_of_empty_struct() {
38 nested := [2]EmptyFixed{}
39 assert nested.len == 2
40 assert nested[0].len == 2
41}
42
43fn test_nested_fixed_array_alias_in_struct_init() {
44 v_box := Box{}
45 assert v_box.len == 2
46 assert v_box[0].len == 3
47
48 v_tst := Tst{Box([2]Dot{}), 1}
49 println(v_tst)
50 assert v_tst.val == 1
51 assert v_tst.box[0][0] == 0.0
52 assert v_tst.box[1][2] == 0.0
53}
54