mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
compiler: optionals default value
This commit is contained in:

committed by
Alexander Medvednikov

parent
4e64a58ac1
commit
df5faf35e5
@ -46,6 +46,8 @@ fn test_defer_early_exit() {
|
||||
|
||||
fn test_defer_option() {
|
||||
mut ok := Num{0}
|
||||
set_num_opt(mut ok)
|
||||
set_num_opt(mut ok) or {
|
||||
assert false
|
||||
}
|
||||
assert ok.val == 1
|
||||
}
|
||||
|
@ -58,3 +58,15 @@ fn test_if_opt() {
|
||||
assert 1 == 1
|
||||
println('nice')
|
||||
}
|
||||
|
||||
fn for_opt_default() ?string {
|
||||
return error('awww')
|
||||
}
|
||||
|
||||
fn test_opt_default() {
|
||||
a := for_opt_default() or {
|
||||
// panic(err)
|
||||
'default'
|
||||
}
|
||||
assert a == 'default'
|
||||
}
|
||||
|
Reference in New Issue
Block a user