| 1 | module main |
| 2 | |
| 3 | fn foo(f int) !(int, ?int) { |
| 4 | if f < 0 { |
| 5 | return error('f is negative') |
| 6 | } |
| 7 | if f > 0 { |
| 8 | return 1, f |
| 9 | } |
| 10 | return 0, none |
| 11 | } |
| 12 | |
| 13 | fn test_main() { |
| 14 | a, b := foo(-1) or { 2, 2 } |
| 15 | c := b? as int |
| 16 | assert a == 2 |
| 17 | assert c == 2 |
| 18 | |
| 19 | a2, b2 := foo(0) or { 2, 2 } |
| 20 | c2 := b2? as int |
| 21 | assert a2 == 0 |
| 22 | assert c2 == 0 |
| 23 | |
| 24 | a3, b3 := foo(1) or { 2, 2 } |
| 25 | c3 := b3? as int |
| 26 | assert a3 == 1 |
| 27 | assert c3 == 1 |
| 28 | } |
| 29 |