OLD | NEW |
| (Empty) |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | |
2 // for details. All rights reserved. Use of this source code is governed by a | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 import 'package:kernel/kernel.dart'; | |
5 import 'type_parser.dart'; | |
6 import 'type_unification_test.dart' show testCases; | |
7 import 'package:test/test.dart'; | |
8 | |
9 void checkHashCodeEquality(DartType type1, DartType type2) { | |
10 if (type1 == type2 && type1.hashCode != type2.hashCode) { | |
11 fail('Equal types with different hash codes: $type1 and $type2'); | |
12 } | |
13 } | |
14 | |
15 const int MinimumSmi = -(1 << 30); | |
16 const int MaximumSmi = (1 << 30) - 1; | |
17 | |
18 bool isSmallInteger(int hash) { | |
19 return MinimumSmi <= hash && hash <= MaximumSmi; | |
20 } | |
21 | |
22 void checkHashCodeRange(DartType type) { | |
23 int hash = type.hashCode; | |
24 if (!isSmallInteger(hash)) { | |
25 fail('Hash code for $type is not a SMI: $hash'); | |
26 } | |
27 } | |
28 | |
29 void main() { | |
30 for (var testCase in testCases) { | |
31 test('$testCase', () { | |
32 var env = new LazyTypeEnvironment(); | |
33 var type1 = env.parse(testCase.type1); | |
34 var type2 = env.parse(testCase.type2); | |
35 checkHashCodeEquality(type1, type2); | |
36 checkHashCodeRange(type1); | |
37 checkHashCodeRange(type2); | |
38 }); | |
39 } | |
40 } | |
OLD | NEW |