v2 / vlib / v / tests / options / option_fn_variadic_test.v
21 lines · 18 sloc · 317 bytes · 64343168c6f2d8380bd8bdb0960f90959af8cd33
Raw
1struct Empty {
2}
3
4type Elem = int | Empty
5
6fn new_elems(elems ...?int) []Elem {
7 mut out := []Elem{}
8 for elem in elems {
9 if elem == none {
10 out << Empty{}
11 } else {
12 out << elem
13 }
14 }
15 return out
16}
17
18fn test_main() {
19 elems := new_elems(0, none, 2)
20 assert '${elems}' == '[Elem(0), Elem(Empty{}), Elem(2)]'
21}
22