v2 / vlib / v / fmt / tests / conditions_input.vv
33 lines · 29 sloc · 814 bytes · 592deda7fd378512345e74a19956f468ced8ef82
Raw
1fn fn_with_if_else() {
2 if true {
3 a = 10
4 a++
5 } else { println('false') }
6}
7
8fn fn_with_if_else_oneline() {
9_ := if true { 1 } else { 2 }
10}
11
12fn short_if_stmts(a int) {
13 if a <= 10 {println('vfmt_0')}
14 if a > 10 {println('vfmt_1')}
15 if this_is_a_very_long_condition_name && this_is_another_really_long_condition_name && this_pushes_past_the_limit {println('wrapped')}
16}
17
18fn dynamic_where_expr(name_filter string, min_age int, status_filter string) {
19 dynamic_where := {if name_filter != '' {name == name_filter}, if min_age > 0 {age >= min_age}, if status_filter != '' {status == status_filter}}
20 _ = dynamic_where
21}
22
23fn dynamic_where_expr_comments(mobile ?string) {
24 dynamic_where := {
25 // mobile update
26 if m := mobile {
27 phone == m,
28 // nested comment
29 },
30 //name == name_dyn
31 }
32 _ = dynamic_where
33}
34