|
1 | 1 | type Type0 = string |
2 | 2 | type Type1 = int | string |
3 | 3 | type Type2 = string | int |
| 4 | +type Type3 = Type0 | int |
| 5 | +type Type4 = Type3 | Type1 | f32 |
| 6 | +type Type5 = Type4 | bool |
4 | 7 |
|
5 | 8 | struct Foo { |
6 | 9 | field_0 Type0 |
7 | 10 | field_1 Type1 |
8 | 11 | field_2 Type2 |
| 12 | + field_3 Type3 |
| 13 | + field_4 Type4 |
| 14 | + field_5 Type5 |
9 | 15 | } |
10 | 16 |
|
11 | | -fn main() { |
| 17 | +fn basic_assertion() { |
| 18 | + foo := Type1('') |
| 19 | + assert foo == Type1('') |
| 20 | +} |
| 21 | + |
| 22 | +fn struct_with_default_values() { |
12 | 23 | foo := Foo{} |
13 | 24 |
|
14 | | - // checks alias types |
15 | 25 | assert foo.field_0 == '' |
16 | 26 |
|
17 | | - // checks sum types |
18 | 27 | if foo.field_1 is int { |
19 | 28 | assert foo.field_1 == 0 |
20 | 29 | } else { |
21 | 30 | assert false |
22 | 31 | } |
23 | 32 |
|
24 | | - // checks sum types |
25 | 33 | if foo.field_2 is string { |
26 | 34 | assert foo.field_2 == '' |
27 | 35 | } else { |
28 | 36 | assert false |
29 | 37 | } |
| 38 | + |
| 39 | + if foo.field_3 is Type0 { |
| 40 | + assert foo.field_3 == '' |
| 41 | + assert foo.field_3 == Type0('') |
| 42 | + } else { |
| 43 | + assert false |
| 44 | + } |
| 45 | + |
| 46 | + // TODO: uncomment until the C backend is improved |
| 47 | + // if foo.field_4 is Type3 { |
| 48 | + // assert foo.field_4 == Type3(Type0('')) |
| 49 | + // } else { |
| 50 | + // assert false |
| 51 | + // } |
| 52 | + |
| 53 | + // TODO: uncomment until the C backend is improved |
| 54 | + // if foo.field_5 is Type4 { |
| 55 | + // assert foo.field_4 == Type4(Type3(Type0(''))) |
| 56 | + // } else { |
| 57 | + // assert false |
| 58 | + // } |
| 59 | +} |
| 60 | + |
| 61 | +fn struct_with_values() { |
| 62 | + // test 0 |
| 63 | + f0 := Foo{ |
| 64 | + field_0: 'hello' |
| 65 | + field_1: 'world' |
| 66 | + field_2: 100 |
| 67 | + field_3: 200 |
| 68 | + field_4: f32(3.14) |
| 69 | + field_5: true |
| 70 | + } |
| 71 | + |
| 72 | + assert f0.field_0 == 'hello' |
| 73 | + |
| 74 | + if f0.field_1 is string { |
| 75 | + assert f0.field_1 == 'world' |
| 76 | + } else { |
| 77 | + assert false |
| 78 | + } |
| 79 | + |
| 80 | + if f0.field_2 is int { |
| 81 | + assert f0.field_2 == 100 |
| 82 | + } else { |
| 83 | + assert false |
| 84 | + } |
| 85 | + |
| 86 | + if f0.field_3 is int { |
| 87 | + assert f0.field_3 == 200 |
| 88 | + } else { |
| 89 | + assert false |
| 90 | + } |
| 91 | + |
| 92 | + if f0.field_4 is f32 { |
| 93 | + assert f0.field_4 == 3.14 |
| 94 | + } else { |
| 95 | + assert false |
| 96 | + } |
| 97 | + |
| 98 | + if f0.field_5 is bool { |
| 99 | + assert f0.field_5 |
| 100 | + } else { |
| 101 | + assert false |
| 102 | + } |
| 103 | + |
| 104 | + // test 1 |
| 105 | + f1 := Foo{ |
| 106 | + field_4: Type3(100) |
| 107 | + field_5: Type4(Type3(Type0('hello'))) |
| 108 | + } |
| 109 | + |
| 110 | + if f1.field_4 is Type3 { |
| 111 | + assert f1.field_4 == Type3(100) |
| 112 | + } else { |
| 113 | + assert false |
| 114 | + } |
| 115 | + |
| 116 | + if f1.field_5 is Type4 { |
| 117 | + assert f1.field_5 == Type4(Type3(Type0('hello'))) |
| 118 | + } else { |
| 119 | + assert false |
| 120 | + } |
| 121 | +} |
| 122 | + |
| 123 | +fn main() { |
| 124 | + basic_assertion() |
| 125 | + struct_with_default_values() |
| 126 | + struct_with_values() |
30 | 127 | } |
0 commit comments