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:
parent
99c70cf9c6
commit
6a0a2da05c
@ -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__'
|
||||
}
|
||||
|
10
vlib/v/tests/comptime_if_test_support_test.v
Normal file
10
vlib/v/tests/comptime_if_test_support_test.v
Normal file
@ -0,0 +1,10 @@
|
||||
fn test_comptime_if_test() {
|
||||
mut i := 0
|
||||
$if test {
|
||||
i++
|
||||
}
|
||||
$if !test {
|
||||
i--
|
||||
}
|
||||
assert i == 1
|
||||
}
|
Loading…
Reference in New Issue
Block a user