| 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:analyzer/dart/element/type.dart'; | 5 import 'package:analyzer/dart/element/type.dart'; |
| 6 import 'package:analyzer/src/summary/format.dart'; | 6 import 'package:analyzer/src/summary/format.dart'; |
| 7 import 'package:analyzer/src/summary/link.dart'; | 7 import 'package:analyzer/src/summary/link.dart'; |
| 8 import 'package:unittest/unittest.dart'; | 8 import 'package:unittest/unittest.dart'; |
| 9 | 9 |
| 10 import '../../reflective_tests.dart'; | 10 import '../../reflective_tests.dart'; |
| 11 import 'summarize_ast_test.dart'; | 11 import 'summarize_ast_test.dart'; |
| 12 | 12 |
| 13 main() { | 13 main() { |
| 14 groupSep = ' | '; | 14 groupSep = ' | '; |
| 15 runReflectiveTests(LinkerUnitTest); | 15 runReflectiveTests(LinkerUnitTest); |
| 16 } | 16 } |
| 17 | 17 |
| 18 @reflectiveTest | 18 @reflectiveTest |
| 19 class LinkerUnitTest extends SummaryLinkerTest { | 19 class LinkerUnitTest extends SummaryLinkerTest { |
| 20 Linker linker; | 20 Linker linker; |
| 21 | 21 |
| 22 LinkerInputs linkerInputs; | 22 LinkerInputs linkerInputs; |
| 23 LibraryElementInBuildUnit _testLibrary; | 23 LibraryElementInBuildUnit _testLibrary; |
| 24 @override | 24 @override |
| 25 bool get allowMissingFiles => false; | 25 bool get allowMissingFiles => false; |
| 26 | 26 |
| 27 Matcher get isUndefined => new isInstanceOf<UndefinedElementForLink>(); |
| 28 |
| 27 LibraryElementInBuildUnit get testLibrary => _testLibrary ??= | 29 LibraryElementInBuildUnit get testLibrary => _testLibrary ??= |
| 28 linker.getLibrary(linkerInputs.testDartUri) as LibraryElementInBuildUnit; | 30 linker.getLibrary(linkerInputs.testDartUri) as LibraryElementInBuildUnit; |
| 29 | 31 |
| 30 void createLinker(String text, {String path: '/test.dart'}) { | 32 void createLinker(String text, {String path: '/test.dart'}) { |
| 31 linkerInputs = createLinkerInputs(text, path: path); | 33 linkerInputs = createLinkerInputs(text, path: path); |
| 32 Map<String, LinkedLibraryBuilder> linkedLibraries = | 34 Map<String, LinkedLibraryBuilder> linkedLibraries = |
| 33 setupForLink(linkerInputs.linkedLibraries, linkerInputs.getUnit); | 35 setupForLink(linkerInputs.linkedLibraries, linkerInputs.getUnit); |
| 34 linker = new Linker(linkedLibraries, linkerInputs.getDependency, | 36 linker = new Linker(linkedLibraries, linkerInputs.getDependency, |
| 35 linkerInputs.getUnit, true); | 37 linkerInputs.getUnit, true); |
| 36 } | 38 } |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 final y; | 145 final y; |
| 144 const C() : y = x.length; | 146 const C() : y = x.length; |
| 145 } | 147 } |
| 146 const x = [const C()]; | 148 const x = [const C()]; |
| 147 '''); | 149 '''); |
| 148 testLibrary.libraryCycleForLink.ensureLinked(); | 150 testLibrary.libraryCycleForLink.ensureLinked(); |
| 149 ClassElementForLink classC = testLibrary.getContainedName('C'); | 151 ClassElementForLink classC = testLibrary.getContainedName('C'); |
| 150 expect(classC.unnamedConstructor.isCycleFree, false); | 152 expect(classC.unnamedConstructor.isCycleFree, false); |
| 151 } | 153 } |
| 152 | 154 |
| 155 void test_getContainedName_nonStaticField() { |
| 156 createLinker('class C { var f; }'); |
| 157 LibraryElementForLink library = linker.getLibrary(linkerInputs.testDartUri); |
| 158 ClassElementForLink_Class c = library.getContainedName('C'); |
| 159 expect(c.getContainedName('f'), isNot(isUndefined)); |
| 160 } |
| 161 |
| 162 void test_getContainedName_nonStaticGetter() { |
| 163 createLinker('class C { get g => null; }'); |
| 164 LibraryElementForLink library = linker.getLibrary(linkerInputs.testDartUri); |
| 165 ClassElementForLink_Class c = library.getContainedName('C'); |
| 166 expect(c.getContainedName('g'), isNot(isUndefined)); |
| 167 } |
| 168 |
| 169 void test_getContainedName_nonStaticMethod() { |
| 170 createLinker('class C { m() {} }'); |
| 171 LibraryElementForLink library = linker.getLibrary(linkerInputs.testDartUri); |
| 172 ClassElementForLink_Class c = library.getContainedName('C'); |
| 173 expect(c.getContainedName('m'), isNot(isUndefined)); |
| 174 } |
| 175 |
| 176 void test_getContainedName_nonStaticSetter() { |
| 177 createLinker('class C { void set s(value) {} }'); |
| 178 LibraryElementForLink library = linker.getLibrary(linkerInputs.testDartUri); |
| 179 ClassElementForLink_Class c = library.getContainedName('C'); |
| 180 expect(c.getContainedName('s='), isNot(isUndefined)); |
| 181 } |
| 182 |
| 153 void test_inferredType_closure_fromBundle() { | 183 void test_inferredType_closure_fromBundle() { |
| 154 var bundle = createPackageBundle( | 184 var bundle = createPackageBundle( |
| 155 ''' | 185 ''' |
| 156 var x = () {}; | 186 var x = () {}; |
| 157 ''', | 187 ''', |
| 158 path: '/a.dart'); | 188 path: '/a.dart'); |
| 159 addBundle(bundle); | 189 addBundle(bundle); |
| 160 createLinker(''' | 190 createLinker(''' |
| 161 import 'a.dart'; | 191 import 'a.dart'; |
| 162 var y = x; | 192 var y = x; |
| (...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 686 TypeParameterElementForLink t = c.typeParameters[0]; | 716 TypeParameterElementForLink t = c.typeParameters[0]; |
| 687 TypeParameterElementForLink u = c.typeParameters[1]; | 717 TypeParameterElementForLink u = c.typeParameters[1]; |
| 688 TypeParameterElementForLink v = d.typeParameters[0]; | 718 TypeParameterElementForLink v = d.typeParameters[0]; |
| 689 TypeParameterElementForLink w = d.typeParameters[1]; | 719 TypeParameterElementForLink w = d.typeParameters[1]; |
| 690 expect(c.isTypeParameterInScope(v), false); | 720 expect(c.isTypeParameterInScope(v), false); |
| 691 expect(c.isTypeParameterInScope(w), false); | 721 expect(c.isTypeParameterInScope(w), false); |
| 692 expect(d.isTypeParameterInScope(t), false); | 722 expect(d.isTypeParameterInScope(t), false); |
| 693 expect(d.isTypeParameterInScope(u), false); | 723 expect(d.isTypeParameterInScope(u), false); |
| 694 } | 724 } |
| 695 } | 725 } |
| OLD | NEW |