| 1 | struct Test { |
| 2 | a int |
| 3 | } |
| 4 | |
| 5 | type MySum = f64 | int |
| 6 | |
| 7 | type MyAlias = Test |
| 8 | |
| 9 | fn test_int() { |
| 10 | a := ?int(1) |
| 11 | if a != none { |
| 12 | assert dump(a) == 1 |
| 13 | assert true |
| 14 | } else { |
| 15 | assert false |
| 16 | } |
| 17 | } |
| 18 | |
| 19 | fn test_struct() { |
| 20 | b := ?Test{ |
| 21 | a: 1 |
| 22 | } |
| 23 | if b != none { |
| 24 | assert dump(b) == Test{ |
| 25 | a: 1 |
| 26 | } |
| 27 | assert true |
| 28 | } else { |
| 29 | assert false |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | fn test_string() { |
| 34 | c := ?string('foo') |
| 35 | if c != none { |
| 36 | assert dump(c) == 'foo' |
| 37 | assert true |
| 38 | } else { |
| 39 | assert false |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | fn test_sum_type() { |
| 44 | d := ?MySum(1.2) |
| 45 | assert d != none |
| 46 | |
| 47 | if d != none { |
| 48 | assert dump(d) == MySum(1.2) |
| 49 | assert true |
| 50 | } else { |
| 51 | assert false |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | fn test_alias() { |
| 56 | d := ?MyAlias(Test{ |
| 57 | a: 1 |
| 58 | }) |
| 59 | assert d != none |
| 60 | |
| 61 | if d != none { |
| 62 | assert dump(d) == Test{ |
| 63 | a: 1 |
| 64 | } |
| 65 | assert true |
| 66 | } else { |
| 67 | assert false |
| 68 | } |
| 69 | } |
| 70 |