v2 / vlib / v / fmt / tests / or_keep.vv
40 lines · 35 sloc · 737 bytes · 90941b3b1f5513cef7f913bc54f1b5a2af0c8c7a
Raw
1fn main() {
2 empty_or_block() or {}
3 empty_or_block() or {
4 }
5}
6
7fn fn_with_or() int {
8 fn_with_option() or { return 10 }
9 return 20
10}
11
12fn (f Foo) method_with_or() int {
13 f.fn_with_option() or { return 10 }
14 return 20
15}
16
17fn unwrapped_single_line_if() {
18 namefound := publisher.name_fix_check(name_to_find, state.site.id, ispage) or {
19 if err.contains('Could not find') {
20 state.error('cannot find link: ${name_to_find}')
21 } else {
22 state.error('cannot find link: ${name_to_find}\n${err}')
23 }
24 println('Another stmt')
25 }
26}
27
28fn or_with_one_multi_line_stmt() {
29 b := or_func() or {
30 MyStruct{
31 val: 'xyz'
32 }
33 }
34}
35
36fn channel_pop() {
37 var_init := <-ch or { -1.25 }
38 var_assign = <-ch or { -2.5 }
39 arr_push << <-ch or { -3.75 }
40}
41