v2 / vlib / v / fmt / tests / match_keep.vv
81 lines · 73 sloc · 915 bytes · 8e35f4d9848f7ad35d857a187dddbfd2eca5e19d
Raw
1fn nested_match() {
2 match 100 {
3 0...1 {
4 println('0 to 1')
5 }
6 else {
7 match 200 {
8 0...1 { println('0 to 1') }
9 else { println('unknown value') }
10 }
11 }
12 }
13}
14
15fn branches_are_struct_inits() {
16 match 'a' {
17 'b' { SpamStruct{} }
18 }
19
20 match 'a' {
21 'b' {
22 SpamStruct{
23 x: 42
24 }
25 }
26 }
27
28 match 'a' {
29 'b' {
30 SpamStruct{
31 // comment inside init
32 }
33 }
34 }
35}
36
37fn branches_are_call_exprs_with_or_blocks() {
38 match 'a' {
39 'b' { foo() or { panic(err) } }
40 }
41
42 match 'a' {
43 'b' {
44 foo() or {
45 // do stuff
46 panic(err)
47 }
48 }
49 }
50
51 match 'a' {
52 'b' {
53 foo() or {
54 another_stmt()
55 panic(err)
56 }
57 }
58 }
59}
60
61fn keep_branch_linebreaks() {
62 a := 10
63 match a {
64 // first comment
65 10 {
66 println('10')
67 }
68 20 {
69 println('20')
70 }
71 else {}
72 }
73
74 match a {
75 // first comment
76 10 { println('10') }
77 // post_comment of the first branch
78 20 { println('20') }
79 else {}
80 }
81}
82