1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

cgen: support $if test { ... }

This commit is contained in:
Delyan Angelov 2020-06-03 10:16:08 +03:00
parent 99c70cf9c6
commit 6a0a2da05c
2 changed files with 16 additions and 0 deletions

View File

@ -267,6 +267,9 @@ pub fn (mut g Gen) init() {
if g.pref.is_debug || 'debug' in g.pref.compile_defines {
g.comptime_defines.writeln('#define _VDEBUG (1)')
}
if g.pref.is_test || 'test' in g.pref.compile_defines {
g.comptime_defines.writeln('#define _VTEST (1)')
}
if g.pref.is_livemain || g.pref.is_liveshared {
g.generate_hotcode_reloading_declarations()
}
@ -3451,6 +3454,9 @@ fn (mut g Gen) comp_if_to_ifdef(name string, is_comptime_optional bool) string {
'debug' {
return '_VDEBUG'
}
'test' {
return '_VTEST'
}
'glibc' {
return '__GLIBC__'
}

View File

@ -0,0 +1,10 @@
fn test_comptime_if_test() {
mut i := 0
$if test {
i++
}
$if !test {
i--
}
assert i == 1
}