| 1 | type TestSmart = ?string | int |
| 2 | |
| 3 | fn test_simple_case() { |
| 4 | o := ?string('abc') |
| 5 | dump(o) |
| 6 | a := if o == none { |
| 7 | 'none' |
| 8 | } else { |
| 9 | '${o} exists' |
| 10 | } |
| 11 | dump(a) |
| 12 | assert a == 'abc exists' |
| 13 | } |
| 14 | |
| 15 | fn test_comptime_smartcast() { |
| 16 | t := TestSmart(?string('foobar')) |
| 17 | $for v in TestSmart.variants { |
| 18 | if t is v { |
| 19 | $if t is ?string { |
| 20 | if t == none { |
| 21 | panic('error') |
| 22 | } else { |
| 23 | assert t == 'foobar' |
| 24 | } |
| 25 | } |
| 26 | } |
| 27 | } |
| 28 | } |
| 29 |