| 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/src/context/cache.dart'; | 5 import 'package:analyzer/src/context/cache.dart'; |
| 6 import 'package:analyzer/src/generated/engine.dart'; | 6 import 'package:analyzer/src/generated/engine.dart'; |
| 7 import 'package:analyzer/src/generated/source.dart'; | 7 import 'package:analyzer/src/generated/source.dart'; |
| 8 import 'package:analyzer/src/summary/idl.dart'; | 8 import 'package:analyzer/src/summary/idl.dart'; |
| 9 import 'package:analyzer/src/summary/package_bundle_reader.dart'; | 9 import 'package:analyzer/src/summary/package_bundle_reader.dart'; |
| 10 import 'package:analyzer/src/task/dart.dart'; | 10 import 'package:analyzer/src/task/dart.dart'; |
| 11 import 'package:analyzer/task/dart.dart'; | 11 import 'package:analyzer/task/dart.dart'; |
| 12 import 'package:analyzer/task/general.dart'; | 12 import 'package:analyzer/task/general.dart'; |
| 13 import 'package:test/test.dart'; | 13 import 'package:test/test.dart'; |
| 14 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 14 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 15 import 'package:typed_mock/typed_mock.dart'; | 15 import 'package:typed_mock/typed_mock.dart'; |
| 16 | 16 |
| 17 main() { | 17 main() { |
| 18 defineReflectiveSuite(() { | 18 defineReflectiveSuite(() { |
| 19 defineReflectiveTests(ResynthesizerResultProviderTest); | 19 defineReflectiveTests(ResynthesizerResultProviderTest); |
| 20 defineReflectiveTests(SummaryDataStoreTest); | 20 defineReflectiveTests(SummaryDataStoreTest); |
| 21 }); | 21 }); |
| 22 } | 22 } |
| 23 | 23 |
| 24 /// A matcher for ConflictingSummaryException. |
| 25 const Matcher isConflictingSummaryException = |
| 26 const _ConflictingSummaryException(); |
| 27 |
| 24 UnlinkedPublicNamespace _namespaceWithParts(List<String> parts) { | 28 UnlinkedPublicNamespace _namespaceWithParts(List<String> parts) { |
| 25 UnlinkedPublicNamespace namespace = new _UnlinkedPublicNamespaceMock(); | 29 UnlinkedPublicNamespace namespace = new _UnlinkedPublicNamespaceMock(); |
| 26 when(namespace.parts).thenReturn(parts); | 30 when(namespace.parts).thenReturn(parts); |
| 27 return namespace; | 31 return namespace; |
| 28 } | 32 } |
| 29 | 33 |
| 30 @reflectiveTest | 34 @reflectiveTest |
| 31 class ResynthesizerResultProviderTest { | 35 class ResynthesizerResultProviderTest { |
| 32 SourceFactory sourceFactory = new _SourceFactoryMock(); | 36 SourceFactory sourceFactory = new _SourceFactoryMock(); |
| 33 InternalAnalysisContext context = new _InternalAnalysisContextMock(); | 37 InternalAnalysisContext context = new _InternalAnalysisContextMock(); |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 recordDependencyInfo: true, disallowOverlappingSummaries: true); | 156 recordDependencyInfo: true, disallowOverlappingSummaries: true); |
| 153 | 157 |
| 154 PackageBundle bundle1 = new _PackageBundleMock(); | 158 PackageBundle bundle1 = new _PackageBundleMock(); |
| 155 PackageBundle bundle2 = new _PackageBundleMock(); | 159 PackageBundle bundle2 = new _PackageBundleMock(); |
| 156 UnlinkedUnit unlinkedUnit11 = new _UnlinkedUnitMock(); | 160 UnlinkedUnit unlinkedUnit11 = new _UnlinkedUnitMock(); |
| 157 UnlinkedUnit unlinkedUnit12 = new _UnlinkedUnitMock(); | 161 UnlinkedUnit unlinkedUnit12 = new _UnlinkedUnitMock(); |
| 158 UnlinkedUnit unlinkedUnit21 = new _UnlinkedUnitMock(); | 162 UnlinkedUnit unlinkedUnit21 = new _UnlinkedUnitMock(); |
| 159 LinkedLibrary linkedLibrary1 = new _LinkedLibraryMock(); | 163 LinkedLibrary linkedLibrary1 = new _LinkedLibraryMock(); |
| 160 LinkedLibrary linkedLibrary2 = new _LinkedLibraryMock(); | 164 LinkedLibrary linkedLibrary2 = new _LinkedLibraryMock(); |
| 161 | 165 |
| 162 void _setupDataStore(SummaryDataStore store) { | |
| 163 // bundle1 | |
| 164 when(unlinkedUnit11.publicNamespace) | |
| 165 .thenReturn(_namespaceWithParts(['package:p1/u2.dart'])); | |
| 166 when(unlinkedUnit12.publicNamespace).thenReturn(_namespaceWithParts([])); | |
| 167 when(bundle1.unlinkedUnitUris) | |
| 168 .thenReturn(<String>['package:p1/u1.dart', 'package:p1/u2.dart']); | |
| 169 when(bundle1.unlinkedUnits) | |
| 170 .thenReturn(<UnlinkedUnit>[unlinkedUnit11, unlinkedUnit12]); | |
| 171 when(bundle1.linkedLibraryUris).thenReturn(<String>['package:p1/u1.dart']); | |
| 172 when(bundle1.linkedLibraries).thenReturn(<LinkedLibrary>[linkedLibrary1]); | |
| 173 when(bundle1.apiSignature).thenReturn('signature1'); | |
| 174 store.addBundle('/p1.ds', bundle1); | |
| 175 // bundle2 | |
| 176 when(unlinkedUnit21.publicNamespace).thenReturn(_namespaceWithParts([])); | |
| 177 when(bundle2.unlinkedUnitUris).thenReturn(<String>['package:p2/u1.dart']); | |
| 178 when(bundle2.unlinkedUnits).thenReturn(<UnlinkedUnit>[unlinkedUnit21]); | |
| 179 when(bundle2.linkedLibraryUris).thenReturn(<String>['package:p2/u1.dart']); | |
| 180 when(bundle2.linkedLibraries).thenReturn(<LinkedLibrary>[linkedLibrary2]); | |
| 181 when(bundle2.apiSignature).thenReturn('signature2'); | |
| 182 store.addBundle('/p2.ds', bundle2); | |
| 183 } | |
| 184 | |
| 185 void setUp() { | 166 void setUp() { |
| 186 _setupDataStore(dataStore); | 167 _setupDataStore(dataStore); |
| 187 } | 168 } |
| 188 | 169 |
| 189 test_addBundle() { | 170 test_addBundle() { |
| 190 expect(dataStore.bundles, unorderedEquals([bundle1, bundle2])); | 171 expect(dataStore.bundles, unorderedEquals([bundle1, bundle2])); |
| 191 expect(dataStore.dependencies[0].summaryPath, '/p1.ds'); | 172 expect(dataStore.dependencies[0].summaryPath, '/p1.ds'); |
| 192 expect(dataStore.dependencies[0].apiSignature, 'signature1'); | 173 expect(dataStore.dependencies[0].apiSignature, 'signature1'); |
| 193 expect(dataStore.dependencies[0].includedPackageNames, ['p1']); | 174 expect(dataStore.dependencies[0].includedPackageNames, ['p1']); |
| 194 expect(dataStore.dependencies[0].includesFileUris, false); | 175 expect(dataStore.dependencies[0].includesFileUris, false); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 String partUri = 'package:p1/u2.dart'; | 270 String partUri = 'package:p1/u2.dart'; |
| 290 List<String> uris = dataStore.getContainingLibraryUris(partUri); | 271 List<String> uris = dataStore.getContainingLibraryUris(partUri); |
| 291 expect(uris, unorderedEquals(['package:p1/u1.dart'])); | 272 expect(uris, unorderedEquals(['package:p1/u1.dart'])); |
| 292 } | 273 } |
| 293 | 274 |
| 294 test_getContainingLibraryUris_unknownUri() { | 275 test_getContainingLibraryUris_unknownUri() { |
| 295 String partUri = 'package:notInStore/foo.dart'; | 276 String partUri = 'package:notInStore/foo.dart'; |
| 296 List<String> uris = dataStore.getContainingLibraryUris(partUri); | 277 List<String> uris = dataStore.getContainingLibraryUris(partUri); |
| 297 expect(uris, isNull); | 278 expect(uris, isNull); |
| 298 } | 279 } |
| 280 |
| 281 void _setupDataStore(SummaryDataStore store) { |
| 282 // bundle1 |
| 283 when(unlinkedUnit11.publicNamespace) |
| 284 .thenReturn(_namespaceWithParts(['package:p1/u2.dart'])); |
| 285 when(unlinkedUnit12.publicNamespace).thenReturn(_namespaceWithParts([])); |
| 286 when(bundle1.unlinkedUnitUris) |
| 287 .thenReturn(<String>['package:p1/u1.dart', 'package:p1/u2.dart']); |
| 288 when(bundle1.unlinkedUnits) |
| 289 .thenReturn(<UnlinkedUnit>[unlinkedUnit11, unlinkedUnit12]); |
| 290 when(bundle1.linkedLibraryUris).thenReturn(<String>['package:p1/u1.dart']); |
| 291 when(bundle1.linkedLibraries).thenReturn(<LinkedLibrary>[linkedLibrary1]); |
| 292 when(bundle1.apiSignature).thenReturn('signature1'); |
| 293 store.addBundle('/p1.ds', bundle1); |
| 294 // bundle2 |
| 295 when(unlinkedUnit21.publicNamespace).thenReturn(_namespaceWithParts([])); |
| 296 when(bundle2.unlinkedUnitUris).thenReturn(<String>['package:p2/u1.dart']); |
| 297 when(bundle2.unlinkedUnits).thenReturn(<UnlinkedUnit>[unlinkedUnit21]); |
| 298 when(bundle2.linkedLibraryUris).thenReturn(<String>['package:p2/u1.dart']); |
| 299 when(bundle2.linkedLibraries).thenReturn(<LinkedLibrary>[linkedLibrary2]); |
| 300 when(bundle2.apiSignature).thenReturn('signature2'); |
| 301 store.addBundle('/p2.ds', bundle2); |
| 302 } |
| 303 } |
| 304 |
| 305 class _ConflictingSummaryException extends TypeMatcher { |
| 306 const _ConflictingSummaryException() : super("ConflictingSummaryException"); |
| 307 bool matches(item, Map matchState) => item is ConflictingSummaryException; |
| 299 } | 308 } |
| 300 | 309 |
| 301 class _InternalAnalysisContextMock extends TypedMock | 310 class _InternalAnalysisContextMock extends TypedMock |
| 302 implements InternalAnalysisContext {} | 311 implements InternalAnalysisContext {} |
| 303 | 312 |
| 304 class _LinkedLibraryMock extends TypedMock implements LinkedLibrary {} | 313 class _LinkedLibraryMock extends TypedMock implements LinkedLibrary {} |
| 305 | 314 |
| 306 class _PackageBundleMock extends TypedMock implements PackageBundle {} | 315 class _PackageBundleMock extends TypedMock implements PackageBundle {} |
| 307 | 316 |
| 308 class _SourceFactoryMock extends TypedMock implements SourceFactory {} | 317 class _SourceFactoryMock extends TypedMock implements SourceFactory {} |
| (...skipping 26 matching lines...) Expand all Loading... |
| 335 @override | 344 @override |
| 336 bool hasResultsForSource(Source source) { | 345 bool hasResultsForSource(Source source) { |
| 337 return sourcesWithResults.contains(source); | 346 return sourcesWithResults.contains(source); |
| 338 } | 347 } |
| 339 } | 348 } |
| 340 | 349 |
| 341 class _UnlinkedPublicNamespaceMock extends TypedMock | 350 class _UnlinkedPublicNamespaceMock extends TypedMock |
| 342 implements UnlinkedPublicNamespace {} | 351 implements UnlinkedPublicNamespace {} |
| 343 | 352 |
| 344 class _UnlinkedUnitMock extends TypedMock implements UnlinkedUnit {} | 353 class _UnlinkedUnitMock extends TypedMock implements UnlinkedUnit {} |
| 345 | |
| 346 /// A matcher for ConflictingSummaryException. | |
| 347 const Matcher isConflictingSummaryException = | |
| 348 const _ConflictingSummaryException(); | |
| 349 | |
| 350 class _ConflictingSummaryException extends TypeMatcher { | |
| 351 const _ConflictingSummaryException() : super("ConflictingSummaryException"); | |
| 352 bool matches(item, Map matchState) => item is ConflictingSummaryException; | |
| 353 } | |
| OLD | NEW |