v2 / vlib / v / tests / builtin_arrays / array_map_cast_interface_test.v
34 lines · 30 sloc · 415 bytes · 537605a058f5041d751765123aad6d9404b87516
Raw
1interface Rect {
2 width u32
3 height u32
4}
5
6struct Square {
7 side u32
8 width u32
9 height u32
10}
11
12fn test_main() {
13 squares := [Square{
14 side: 5
15 width: 5
16 height: 5
17 }]
18 rects := squares.map(Rect(it))
19
20 assert rects.str() == '[Rect(Square{
21 side: 5
22 width: 5
23 height: 5
24})]'
25}
26
27fn test_fixed_array() {
28 squares := [Square{
29 side: 5
30 width: 5
31 height: 5
32 }]!
33 rects := squares.map(Rect(it))
34}
35