v2 / vlib / v / tests / options / option_index_amp_test.v
28 lines · 24 sloc · 346 bytes · 29f372ff5b94f0542684fe3941a4cd8a36f307c7
Raw
1module main
2
3struct Bar {
4 name string
5}
6
7struct Foo {
8 bars []Bar
9}
10
11fn (f Foo) find() ?&Bar {
12 return &f.bars[1] or { return none }
13}
14
15fn test_main() {
16 foo := Foo{
17 bars: [Bar{
18 name: '123'
19 }, Bar{
20 name: 'aaa'
21 }, Bar{
22 name: 's34'
23 }]
24 }
25 bar := foo.find() or { panic('not found') }
26 println(bar.name)
27 assert bar.name == 'aaa'
28}
29