v2 / vlib / v / tests / options / option_with_error_test.v
17 lines · 15 sloc · 278 bytes · 6df25afe0615c430e0e1ffc99fe11c8a27252d57
Raw
1struct Struct {
2 error ?string
3}
4
5fn result_function() !Struct {
6 return error('This is an error')
7}
8
9fn test_main() {
10 some_struct := result_function() or {
11 Struct{
12 error: err
13 }
14 }
15 // some_struct.error?
16 assert some_struct.error or { '${err}' } == 'This is an error'
17}
18