mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
40 lines
726 B
V
40 lines
726 B
V
struct Abc {
|
|
ncalls int
|
|
}
|
|
|
|
[unsafe]
|
|
fn fn_that_should_be_called_just_once_array() []int {
|
|
mut static ncalls := 0
|
|
ncalls++
|
|
println('${@FN} calls: $ncalls')
|
|
if ncalls > 1 {
|
|
assert false
|
|
}
|
|
return []int{len: ncalls, init: ncalls}
|
|
}
|
|
|
|
[unsafe]
|
|
fn fn_that_should_be_called_just_once_struct() Abc {
|
|
mut static ncalls := 0
|
|
ncalls++
|
|
println('${@FN} calls: $ncalls')
|
|
if ncalls > 1 {
|
|
assert false
|
|
}
|
|
return Abc{
|
|
ncalls: ncalls
|
|
}
|
|
}
|
|
|
|
fn test_assert_calls_a_function_returning_an_array_just_once() {
|
|
unsafe {
|
|
assert fn_that_should_be_called_just_once_array().len == 1
|
|
}
|
|
}
|
|
|
|
fn test_assert_calls_a_function_returning_a_struct_just_once() {
|
|
unsafe {
|
|
assert fn_that_should_be_called_just_once_struct().ncalls == 1
|
|
}
|
|
}
|