| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 import 'package:test/test.dart'; | 5 import 'package:test/test.dart'; |
| 6 import 'package:kernel/ast.dart'; | 6 import 'package:kernel/ast.dart'; |
| 7 import 'package:kernel/class_hierarchy.dart'; | 7 import 'package:kernel/class_hierarchy.dart'; |
| 8 import 'package:kernel/type_environment.dart'; | 8 import 'package:kernel/type_environment.dart'; |
| 9 import 'type_parser.dart'; | 9 import 'type_parser.dart'; |
| 10 | 10 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 LazyTypeEnvironment environment; | 114 LazyTypeEnvironment environment; |
| 115 | 115 |
| 116 MockSubtypeTester( | 116 MockSubtypeTester( |
| 117 this.hierarchy, this.objectType, this.rawFunctionType, this.environment); | 117 this.hierarchy, this.objectType, this.rawFunctionType, this.environment); |
| 118 } | 118 } |
| 119 | 119 |
| 120 MockSubtypeTester makeSubtypeTester(Map<String, List<String>> testcase) { | 120 MockSubtypeTester makeSubtypeTester(Map<String, List<String>> testcase) { |
| 121 LazyTypeEnvironment environment = new LazyTypeEnvironment(); | 121 LazyTypeEnvironment environment = new LazyTypeEnvironment(); |
| 122 Class objectClass = environment.lookup('Object'); | 122 Class objectClass = environment.lookup('Object'); |
| 123 Class functionClass = environment.lookup('Function'); | 123 Class functionClass = environment.lookup('Function'); |
| 124 functionClass.supertype = objectClass.rawType; | 124 functionClass.supertype = objectClass.asRawSupertype; |
| 125 for (var typeString in testcase.keys) { | 125 for (var typeString in testcase.keys) { |
| 126 InterfaceType type = environment.parseFresh(typeString); | 126 InterfaceType type = environment.parseFresh(typeString); |
| 127 Class class_ = type.classNode; | 127 Class class_ = type.classNode; |
| 128 for (TypeParameterType typeArg in type.typeArguments) { | 128 for (TypeParameterType typeArg in type.typeArguments) { |
| 129 class_.typeParameters.add(typeArg.parameter); | 129 class_.typeParameters.add(typeArg.parameter); |
| 130 } | 130 } |
| 131 for (var supertypeString in testcase[typeString]) { | 131 for (var supertypeString in testcase[typeString]) { |
| 132 if (class_.supertype == null) { | 132 if (class_.supertype == null) { |
| 133 class_.supertype = environment.parse(supertypeString); | 133 class_.supertype = environment.parseSuper(supertypeString); |
| 134 } else { | 134 } else { |
| 135 class_.implementedTypes.add(environment.parse(supertypeString)); | 135 class_.implementedTypes.add(environment.parseSuper(supertypeString)); |
| 136 } | 136 } |
| 137 } | 137 } |
| 138 } | 138 } |
| 139 var program = new Program([environment.dummyLibrary]); | 139 var program = new Program([environment.dummyLibrary]); |
| 140 var hierarchy = new ClassHierarchy(program); | 140 var hierarchy = new ClassHierarchy(program); |
| 141 return new MockSubtypeTester( | 141 return new MockSubtypeTester( |
| 142 hierarchy, objectClass.rawType, functionClass.rawType, environment); | 142 hierarchy, objectClass.rawType, functionClass.rawType, environment); |
| 143 } | 143 } |
| 144 | 144 |
| 145 main() { | 145 main() { |
| 146 var tester = makeSubtypeTester(classEnvironment); | 146 var tester = makeSubtypeTester(classEnvironment); |
| 147 var environment = tester.environment; | 147 var environment = tester.environment; |
| 148 for (var testCase in testCases) { | 148 for (var testCase in testCases) { |
| 149 test('$testCase', () { | 149 test('$testCase', () { |
| 150 var subtype = environment.parseFresh(testCase.subtype); | 150 var subtype = environment.parseFresh(testCase.subtype); |
| 151 var supertype = environment.parseFresh(testCase.supertype); | 151 var supertype = environment.parseFresh(testCase.supertype); |
| 152 if (tester.isSubtypeOf(subtype, supertype) != testCase.isSubtype) { | 152 if (tester.isSubtypeOf(subtype, supertype) != testCase.isSubtype) { |
| 153 fail('isSubtypeOf(${testCase.subtype}, ${testCase.supertype}) returned ' | 153 fail('isSubtypeOf(${testCase.subtype}, ${testCase.supertype}) returned ' |
| 154 '${!testCase.isSubtype} but should return ${testCase.isSubtype}'); | 154 '${!testCase.isSubtype} but should return ${testCase.isSubtype}'); |
| 155 } | 155 } |
| 156 if (subtype != supertype && tester.isSubtypeOf(supertype, subtype)) { | 156 if (subtype != supertype && tester.isSubtypeOf(supertype, subtype)) { |
| 157 fail('isSubtypeOf(${testCase.supertype}, ${testCase.subtype}) returned ' | 157 fail('isSubtypeOf(${testCase.supertype}, ${testCase.subtype}) returned ' |
| 158 'true but should return false'); | 158 'true but should return false'); |
| 159 } | 159 } |
| 160 }); | 160 }); |
| 161 } | 161 } |
| 162 } | 162 } |
| OLD | NEW |