v2 / vlib / v / tests / options / option_multi_ret_test.v
41 lines · 35 sloc · 604 bytes · 6488041a749df9762348d019c4223908c476f2e2
Raw
1struct Test {
2mut:
3 a ?int
4 b ?string
5 c ?[]int
6}
7
8fn mr_1() (?int, string, []int) {
9 return 456, 'foo', [1]
10}
11
12fn mr_2() (?int, string, []int) {
13 return none, 'zoo', [99]
14}
15
16fn mr_3() ([]?int, ?int) {
17 return [?int(456)], none
18}
19
20fn test_mr_first_option() {
21 mut t := Test{}
22 t.a, t.b, t.c = mr_1()
23 assert t.a? == 456
24 assert t.b? == 'foo'
25 assert t.c? == [1]
26}
27
28fn test_mr_first_option_none() {
29 mut t := Test{}
30 t.a, t.b, t.c = mr_2()
31 assert t.a == none
32 assert t.b? == 'zoo'
33 assert t.c? == [99]
34}
35
36fn test_mr_first_option_array() {
37 a, b := mr_3()
38 t := a[0]
39 assert t? == 456
40 assert b == none
41}
42