1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00
v/vlib/compiler/tests/option_test.v
Delyan Angelov 53c64abdeb compiler: make compiler an ordinary vlib/compiler module
* Move compiler/ under vlib/compiler/ .

* Add a minimal compiler/main.v driver program.

* Cleanup compiler/main.v .

* Make most compiler tests pass again.

* Apply the fix by @joe-conigliaro , so that the rest of the compiler tests are fixed too.

* Thanks to @avitkauskas, now the vlib/vcompiler/tests/str_gen_test.v test does not need to be special cased anymore.

* Reapply @joe-conigliaro fix for vgen.
2019-10-13 16:37:43 +03:00

49 lines
715 B
V

fn opt_err() ?string {return error('hi')}
fn test_err(){
v := opt_err() or {
assert err == 'hi'
return
}
assert false
println(v) // suppress not used error
}
fn err_call(ok bool) ?int {
if !ok {
return error('Not ok!')
}
return 42
}
fn ret_none() ?int {
//return error('wtf') //none
return none
}
fn test_option_for_base_type_without_variable() {
val := err_call(true) or {
panic(err)
}
assert val == 42
println('hm')
val2 := ret_none() or {
println('yep')
return
}
println('$val2 should have been `none`')
assert false
// This is invalid:
// x := 5 or {
// return
// }
}
fn test_if_opt() {
if val := err_call(false) {
assert val == 42
}
assert 1 == 1
println('nice')
}