v2 / vlib / v / tests / loops / for_loop_with_option2_test.v
44 lines · 39 sloc · 645 bytes · 6488041a749df9762348d019c4223908c476f2e2
Raw
1struct Test {
2 a ?[]int
3 b ?[]string
4 c ?[]f64
5 d ?[][]string
6}
7
8fn test_for_in_option_fields() {
9 mut out := []string{}
10 test := Test{
11 a: [1, 2, 3]
12 b: ['foo', 'bar']
13 c: [1.2, 2.3]
14 d: [['foo'], ['bar']]
15 }
16
17 for element in test.a {
18 out << '${element}'
19 }
20 dump(out)
21 assert out == ['1', '2', '3']
22 out.clear()
23
24 for element in test.b {
25 out << '${element}'
26 }
27 dump(out)
28 assert out == ['foo', 'bar']
29 out.clear()
30
31 for element in test.c {
32 out << '${element}'
33 }
34 dump(out)
35 assert out == ['1.2', '2.3']
36 out.clear()
37
38 for element in test.d {
39 out << '${element}'
40 }
41 dump(out)
42 assert out == ["['foo']", "['bar']"]
43 out.clear()
44}
45