vq / vlib / v / tests / comptime / comptime_selector_map_move_test.v
27 lines · 24 sloc · 466 bytes · 777460dfd3f7cf551cb57ac9a6f29831aa85f164
Raw
1struct MapHolder {
2 values map[string]string
3}
4
5fn make_map_holder() MapHolder {
6 return MapHolder{
7 values: {
8 'a': 'b'
9 }
10 }
11}
12
13fn first_map_from_temporary[T]() map[string]string {
14 $for field in T.fields {
15 $if field.unaliased_typ is map[string]string {
16 values := make_map_holder().$(field.name)
17 return values
18 }
19 }
20 return {}
21}
22
23fn test_comptime_selector_map_move_from_temporary() {
24 assert first_map_from_temporary[MapHolder]() == {
25 'a': 'b'
26 }
27}
28