v2 / vlib / v / tests / comptime / comptime_if_test.v
54 lines · 51 sloc · 725 bytes · 6488041a749df9762348d019c4223908c476f2e2
Raw
1fn test_comptime_if_test() {
2 mut i := 0
3 $if test {
4 i++
5 }
6 $if !test {
7 i--
8 }
9 assert i == 1
10}
11
12fn test_comptime_if_parsing_in_combination_with_ordinary_if_1() {
13 if true {
14 $if debug {
15 println('debug')
16 }
17 } else {
18 assert false
19 }
20 assert true
21}
22
23fn test_comptime_if_parsing_in_combination_with_ordinary_if_2() {
24 if true {
25 if true {
26 $if debug {
27 println('debug')
28 }
29 } else {
30 assert false
31 }
32 } else {
33 assert false
34 }
35 assert true
36}
37
38fn test_comptime_if_parsing_in_combination_with_ordinary_if_3() {
39 println(@LINE)
40 $if true {
41 println(@LINE)
42 $if true {
43 println(@LINE)
44 $if debug {
45 println('debug')
46 }
47 } $else {
48 assert false
49 }
50 } $else {
51 assert false
52 }
53 assert true
54}
55