| 129 | } |
| 130 | |
| 131 | func TestUnifyTable(t *testing.T) { |
| 132 | type test struct { // an individual test |
| 133 | name string |
| 134 | typ1 *types.Type |
| 135 | typ2 *types.Type |
| 136 | fail bool |
| 137 | exp *types.Type // concrete type without unification variables |
| 138 | } |
| 139 | testCases := []test{} |
| 140 | |
| 141 | testCases = append(testCases, test{ // 0 |
| 142 | "nil", |
| 143 | nil, |
| 144 | nil, |
| 145 | true, |
| 146 | nil, |
| 147 | }) |
| 148 | testCases = append(testCases, test{ |
| 149 | name: "two strings", |
| 150 | typ1: types.TypeStr, |
| 151 | typ2: types.TypeStr, |
| 152 | fail: false, |
| 153 | }) |
| 154 | testCases = append(testCases, test{ |
| 155 | name: "different simple types", |
| 156 | typ1: types.TypeStr, |
| 157 | typ2: types.TypeBool, |
| 158 | fail: true, |
| 159 | }) |
| 160 | testCases = append(testCases, test{ |
| 161 | name: "two lists", |
| 162 | typ1: types.TypeListStr, |
| 163 | typ2: types.TypeListStr, |
| 164 | fail: false, |
| 165 | }) |
| 166 | testCases = append(testCases, test{ |
| 167 | name: "two lists, one elem", |
| 168 | typ1: types.TypeListStr, // []str |
| 169 | typ2: types.NewType("[]?1"), // []?1 |
| 170 | fail: false, |
| 171 | }) |
| 172 | testCases = append(testCases, test{ |
| 173 | name: "two functions", |
| 174 | typ1: types.NewType("func([]str, ?42, float, int) ?42"), |
| 175 | typ2: types.NewType("func(?13, bool, ?4, int) ?42"), |
| 176 | fail: false, |
| 177 | exp: types.NewType("func([]str, bool, float, int) bool"), |
| 178 | }) |
| 179 | |
| 180 | names := []string{} |
| 181 | for index, tc := range testCases { // run all the tests |
| 182 | if tc.name == "" { |
| 183 | t.Errorf("test #%d: not named", index) |
| 184 | continue |
| 185 | } |
| 186 | if util.StrInList(tc.name, names) { |
| 187 | t.Errorf("test #%d: duplicate sub test name of: %s", index, tc.name) |
| 188 | continue |