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/ast/ast.dart'; | 5 import 'package:analyzer/dart/ast/ast.dart'; |
6 import 'package:analyzer/dart/ast/token.dart'; | 6 import 'package:analyzer/dart/ast/token.dart'; |
7 import 'package:analyzer/error/listener.dart'; | 7 import 'package:analyzer/error/listener.dart'; |
8 import 'package:analyzer/file_system/file_system.dart'; | 8 import 'package:analyzer/file_system/file_system.dart'; |
9 import 'package:analyzer/src/dart/scanner/reader.dart'; | 9 import 'package:analyzer/src/dart/scanner/reader.dart'; |
10 import 'package:analyzer/src/dart/scanner/scanner.dart'; | 10 import 'package:analyzer/src/dart/scanner/scanner.dart'; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 sourceFactory = new SourceFactory(<UriResolver>[ | 42 sourceFactory = new SourceFactory(<UriResolver>[ |
43 sdkResolver, | 43 sdkResolver, |
44 resourceResolver, | 44 resourceResolver, |
45 new _TestPackageResolver(resourceProvider) | 45 new _TestPackageResolver(resourceProvider) |
46 ], null, resourceProvider); | 46 ], null, resourceProvider); |
47 context.sourceFactory = sourceFactory; | 47 context.sourceFactory = sourceFactory; |
48 // Create a new SummaryProvider instance. | 48 // Create a new SummaryProvider instance. |
49 manager = new SummaryProvider(resourceProvider, _getOutputFolder, context); | 49 manager = new SummaryProvider(resourceProvider, _getOutputFolder, context); |
50 } | 50 } |
51 | 51 |
| 52 test_getLinkedPackages_null_missingBundle() { |
| 53 _setComponentFile('aaa', 'a.dart', 'class A {}'); |
| 54 // We don't write 'aaa', so we cannot get its package. |
| 55 // Ask the package for the URI. |
| 56 Source source = _resolveUri('package:components.aaa/a.dart'); |
| 57 List<Package> packages = manager.getLinkedPackages(source); |
| 58 expect(packages, isNull); |
| 59 } |
| 60 |
| 61 test_getLinkedPackages_null_missingDirectDependency() { |
| 62 _setComponentFile('aaa', 'a.dart', 'class A {}'); |
| 63 _setComponentFile( |
| 64 'bbb', |
| 65 'b.dart', |
| 66 r''' |
| 67 import 'package:components.aaa/a.dart'; |
| 68 class B extends A {} |
| 69 '''); |
| 70 _writeUnlinkedBundle('components.bbb'); |
| 71 // We cannot find 'aaa' bundle, so 'bbb' linking fails. |
| 72 Source source = _resolveUri('package:components.bbb/b.dart'); |
| 73 List<Package> packages = manager.getLinkedPackages(source); |
| 74 expect(packages, isNull); |
| 75 } |
| 76 |
| 77 test_getLinkedPackages_null_missingIndirectDependency() { |
| 78 _setComponentFile('aaa', 'a.dart', 'class A {}'); |
| 79 _setComponentFile( |
| 80 'bbb', |
| 81 'b.dart', |
| 82 r''' |
| 83 import 'package:components.aaa/a.dart'; |
| 84 class B extends A {} |
| 85 '''); |
| 86 _setComponentFile( |
| 87 'ccc', |
| 88 'c.dart', |
| 89 r''' |
| 90 import 'package:components.bbb/b.dart'; |
| 91 class C extends B {} |
| 92 '''); |
| 93 _writeUnlinkedBundle('components.bbb'); |
| 94 _writeUnlinkedBundle('components.ccc'); |
| 95 // We cannot find 'aaa' bundle, so 'ccc' linking fails. |
| 96 Source source = _resolveUri('package:components.ccc/c.dart'); |
| 97 List<Package> packages = manager.getLinkedPackages(source); |
| 98 expect(packages, isNull); |
| 99 } |
| 100 |
| 101 test_getLinkedPackages_withDependency_export() { |
| 102 _setComponentFile('aaa', 'a.dart', 'class A {}'); |
| 103 _setComponentFile( |
| 104 'bbb', |
| 105 'b.dart', |
| 106 r''' |
| 107 export 'package:components.aaa/a.dart'; |
| 108 '''); |
| 109 _writeUnlinkedBundle('components.aaa'); |
| 110 _writeUnlinkedBundle('components.bbb'); |
| 111 Source source = _resolveUri('package:components.bbb/b.dart'); |
| 112 List<Package> packages = manager.getLinkedPackages(source); |
| 113 expect(packages, hasLength(2)); |
| 114 } |
| 115 |
| 116 test_getLinkedPackages_withDependency_import() { |
| 117 _setComponentFile('aaa', 'a.dart', 'class A {}'); |
| 118 _setComponentFile( |
| 119 'bbb', |
| 120 'b.dart', |
| 121 r''' |
| 122 import 'package:components.aaa/a.dart'; |
| 123 class B extends A {} |
| 124 '''); |
| 125 _writeUnlinkedBundle('components.aaa'); |
| 126 _writeUnlinkedBundle('components.bbb'); |
| 127 Source source = _resolveUri('package:components.bbb/b.dart'); |
| 128 List<Package> packages = manager.getLinkedPackages(source); |
| 129 expect(packages, hasLength(2)); |
| 130 } |
| 131 |
| 132 test_getLinkedPackages_withDependency_import_cycle() { |
| 133 _setComponentFile( |
| 134 'aaa', |
| 135 'a.dart', |
| 136 r''' |
| 137 import 'package:components.bbb/b.dart'; |
| 138 class A {} |
| 139 class A2 extends B {} |
| 140 '''); |
| 141 _setComponentFile( |
| 142 'bbb', |
| 143 'b.dart', |
| 144 r''' |
| 145 import 'package:components.aaa/a.dart'; |
| 146 class B extends A {} |
| 147 class B2 extends A2 {} |
| 148 '''); |
| 149 _writeUnlinkedBundle('components.aaa'); |
| 150 _writeUnlinkedBundle('components.bbb'); |
| 151 Source source = _resolveUri('package:components.bbb/b.dart'); |
| 152 List<Package> packages = manager.getLinkedPackages(source); |
| 153 expect(packages, hasLength(2)); |
| 154 } |
| 155 |
| 156 test_getLinkedPackages_withDependency_import_indirect() { |
| 157 _setComponentFile('aaa', 'a.dart', 'class A {}'); |
| 158 _setComponentFile( |
| 159 'bbb', |
| 160 'b.dart', |
| 161 r''' |
| 162 import 'package:components.aaa/a.dart'; |
| 163 class B extends A {} |
| 164 '''); |
| 165 _setComponentFile( |
| 166 'ccc', |
| 167 'c.dart', |
| 168 r''' |
| 169 import 'package:components.bbb/b.dart'; |
| 170 class C extends B {} |
| 171 '''); |
| 172 _writeUnlinkedBundle('components.aaa'); |
| 173 _writeUnlinkedBundle('components.bbb'); |
| 174 _writeUnlinkedBundle('components.ccc'); |
| 175 Source source = _resolveUri('package:components.ccc/c.dart'); |
| 176 List<Package> packages = manager.getLinkedPackages(source); |
| 177 expect(packages, hasLength(3)); |
| 178 } |
| 179 |
| 180 test_getLinkedPackages_withoutDependencies() { |
| 181 _setComponentFile('aaa', 'a.dart', 'class A {}'); |
| 182 _writeUnlinkedBundle('components.aaa'); |
| 183 // Ask the package for the URI. |
| 184 Source source = _resolveUri('package:components.aaa/a.dart'); |
| 185 List<Package> packages = manager.getLinkedPackages(source); |
| 186 expect(packages, hasLength(1)); |
| 187 } |
| 188 |
52 test_getUnlinkedForUri() { | 189 test_getUnlinkedForUri() { |
53 _setComponentFile('aaa', 'a1.dart', 'class A1 {}'); | 190 _setComponentFile('aaa', 'a1.dart', 'class A1 {}'); |
54 _setComponentFile('aaa', 'a2.dart', 'class A2 {}'); | 191 _setComponentFile('aaa', 'a2.dart', 'class A2 {}'); |
55 _writeUnlinkedBundle('components.aaa'); | 192 _writeUnlinkedBundle('components.aaa'); |
56 // Ask the package for the URI. | 193 // Ask the package for the URI. |
57 Source source1 = _resolveUri('package:components.aaa/a1.dart'); | 194 Source source1 = _resolveUri('package:components.aaa/a1.dart'); |
58 Source source2 = _resolveUri('package:components.aaa/a2.dart'); | 195 Source source2 = _resolveUri('package:components.aaa/a2.dart'); |
59 Package package = manager.getUnlinkedForUri(source1.uri); | 196 Package package = manager.getUnlinkedForUri(source1.uri); |
60 expect(package, isNotNull); | 197 expect(package, isNotNull); |
61 // The same instance is returned to another URI in the same package. | 198 // The same instance is returned to another URI in the same package. |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 } | 335 } |
199 } | 336 } |
200 return null; | 337 return null; |
201 } | 338 } |
202 | 339 |
203 @override | 340 @override |
204 Uri restoreAbsolute(Source source) { | 341 Uri restoreAbsolute(Source source) { |
205 throw new UnimplementedError(); | 342 throw new UnimplementedError(); |
206 } | 343 } |
207 } | 344 } |
OLD | NEW |