v2 / vlib / v / tests / comptime / comptime_selector_postfix_unwrap_test.v
21 lines · 19 sloc · 347 bytes · 82798096a3f5eb84a2aa2b22bb63ffca88f79da7
Raw
1fn generic_unwrap[T](value T) []int {
2 mut out := []int{}
3 $if T is $struct {
4 $for field in T.fields {
5 $if field.typ is ?int {
6 out << value.$(field.name) ?
7 }
8 }
9 }
10 return out
11}
12
13struct PostfixOptionField {
14 a ?int
15}
16
17fn test_generic_comptime_selector_postfix_unwrap() {
18 assert generic_unwrap(PostfixOptionField{
19 a: 7
20 }) == [7]
21}
22