v2 / vlib / v / fmt / tests / if_ternary_expected.vv
67 lines · 63 sloc · 1.35 KB · 3d60410b605d001e54f280070d5f952da9de1112
Raw
1const spacing_error = if true { true } else { false }
2// Multiline result should not align with the next multiline result.
3const too_long_line = if b.no_cstep {
4 'TMP1/${b.nexpected_steps:1d}'
5} else {
6 '${b.cstep:1d}/${b.nexpected_steps:1d}'
7}
8const too_many_branches = if true {
9 true
10} else if true {
11 true
12} else {
13 false
14}
15
16const align = if true { 'a' } else { 'b' }
17const some_longer_variable = 'foo'
18const another_var = 'bar'
19
20fn main() {
21 // This line is too long
22 sprogress := if b.no_cstep {
23 'TMP1/${b.nexpected_steps:1d}'
24 } else {
25 '${b.cstep:1d}/${b.nexpected_steps:1d}'
26 }
27 // Normal struct inits
28 _ := if true {
29 Foo{}
30 } else {
31 Foo{
32 x: 5
33 }
34 }
35 _ := if some_cond {
36 Bar{
37 a: 'bar'
38 b: 'also bar'
39 }
40 } else {
41 Bar{}
42 }
43}
44
45fn condition_is_very_long_infix() {
46 val := if the_first_condition && this_is_required_too
47 && (another_cond || foobar_to_exceed_the_max_len) {
48 'true'
49 } else {
50 'false'
51 }
52}
53
54fn branches_are_long_fn_calls() {
55 _ := if nr_dims == 1 {
56 t.find_or_register_array(elem_type)
57 } else {
58 t.find_or_register_arra(t.find_or_register_array_with_dims(elem_type, nr_dims - 1))
59 }
60 // With another arg to make fn call exceed the max_len after if unwrapping
61 _ := if nr_dims == 1 {
62 t.find_or_register_array(elem_type)
63 } else {
64 t.find_or_register_arra(t.find_or_register_array_with_dims(elem_type, nr_dims - 1,
65 'some string'))
66 }
67}
68