v2 / vlib / v / tests / goto_test.v
54 lines · 50 sloc · 619 bytes · c44115c67d4994009835905b1ee8a60090e50cb6
Raw
1fn test_goto() {
2 mut i := 0
3 a:
4 b := 1
5 _ = b
6 i++
7 if i < 3 {
8 unsafe {
9 goto a
10 }
11 }
12 assert i == 3
13}
14
15pub fn test_goto_after_return() {
16 a, b, c, d := 4, 5, 6, 7
17 for {
18 for {
19 for {
20 if a == 4 {
21 if b == 5 {
22 if c == 6 {
23 if d == 7 {
24 unsafe {
25 goto finally_ok
26 }
27 }
28 }
29 }
30 }
31 }
32 }
33 }
34 assert false
35 return
36 finally_ok:
37 assert true
38}
39
40fn test_goto_with_comptime_tmpl() {
41 a := 22
42 _ := $tmpl('./tmpl/a.txt')
43 println('before goto')
44
45 unsafe {
46 goto label
47 }
48 println('failed goto')
49 assert false
50
51 label:
52 println('goto label')
53 assert true
54}
55