v2 / vlib / v / tests / comptime / comptime_if_top_3_test.v
94 lines · 85 sloc · 1.46 KB · 19d31f221fb72987c8e25b6889d746da2da57630
Raw
1// vtest vflags: -d new_3 -d new_a_3 -d new_b_3 -d new_c_3 -d new_d_3 -d new_e_3
2module main
3
4// this is comment, should skip
5
6$if new_1 ? {
7 // this is comment, should skip
8 import os
9 // this is comment, should skip
10} $else $if new_2 ? {
11 // this is comment, should skip
12 import math
13 // this is comment, should skip
14} $else {
15 // this is comment, should skip
16 import time
17 // this is comment, should skip
18}
19// this is comment, should skip
20
21const t = $if amd64 { 1 } $else { 2 }
22
23$if new_a_1 ? {
24 pub type Digits = u64
25} $else $if new_a_2 ? {
26 pub type Digits = u32
27} $else {
28 pub type Digits = u8
29}
30
31$if new_b_1 ? {
32 pub const const1 = '123'
33} $else $if new_b_2 ? {
34 pub const const1 = 123
35} $else {
36 pub const const1 = 1.1
37}
38
39$if new_c_1 ? {
40 pub enum Enum1 {
41 enum1_a
42 enum1_b
43 }
44} $else $if new_c_2 ? {
45 pub enum Enum1 {
46 enum1_c
47 enum1_d
48 }
49} $else {
50 pub enum Enum1 {
51 enum1_e
52 enum1_f
53 }
54}
55
56$if new_d_1 ? {
57 pub struct Struct1 {
58 a int
59 }
60} $else $if new_d_2 ? {
61 pub struct Struct1 {
62 b int
63 }
64} $else {
65 pub struct Struct1 {
66 c int
67 }
68}
69
70$if new_e_1 ? {
71 pub fn ret() string {
72 return 'new_e_1'
73 }
74} $else $if new_e_2 ? {
75 pub fn ret() string {
76 return 'new_e_2'
77 }
78} $else {
79 pub fn ret() string {
80 return 'new_e_3'
81 }
82}
83
84fn test_main() {
85 assert time.days_in_year == 365
86 assert t in [1, 2]
87 assert sizeof(Digits) == 1 // Digits == u8
88 assert const1 == 1.1
89 _ := Enum1.enum1_e // should compile
90 _ := Struct1{
91 c: 123
92 } // should compile
93 assert ret() == 'new_e_3'
94}
95