| 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:mockito/mockito.dart'; |
| 13 import 'package:test/test.dart'; | 14 import 'package:test/test.dart'; |
| 14 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 15 import 'package:test_reflective_loader/test_reflective_loader.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. | 24 /// A matcher for ConflictingSummaryException. |
| 25 const Matcher isConflictingSummaryException = | 25 const Matcher isConflictingSummaryException = |
| (...skipping 28 matching lines...) Expand all Loading... |
| 54 | 54 |
| 55 void setUp() { | 55 void setUp() { |
| 56 cachePartition = new UniversalCachePartition(context); | 56 cachePartition = new UniversalCachePartition(context); |
| 57 entry1 = new CacheEntry(source1); | 57 entry1 = new CacheEntry(source1); |
| 58 entry2 = new CacheEntry(source2); | 58 entry2 = new CacheEntry(source2); |
| 59 entry3 = new CacheEntry(source3); | 59 entry3 = new CacheEntry(source3); |
| 60 cachePartition.put(entry1); | 60 cachePartition.put(entry1); |
| 61 cachePartition.put(entry2); | 61 cachePartition.put(entry2); |
| 62 cachePartition.put(entry3); | 62 cachePartition.put(entry3); |
| 63 | 63 |
| 64 when(sourceFactory.resolveUri(anyObject, 'package:p1/u1.dart')) | 64 when(sourceFactory.resolveUri(any, 'package:p1/u1.dart')) |
| 65 .thenReturn(source1); | 65 .thenReturn(source1); |
| 66 when(sourceFactory.resolveUri(anyObject, 'package:p1/u2.dart')) | 66 when(sourceFactory.resolveUri(any, 'package:p1/u2.dart')) |
| 67 .thenReturn(source2); | 67 .thenReturn(source2); |
| 68 when(context.sourceFactory).thenReturn(sourceFactory); | 68 when(context.sourceFactory).thenReturn(sourceFactory); |
| 69 | 69 |
| 70 when(bundle.unlinkedUnitUris) | 70 when(bundle.unlinkedUnitUris) |
| 71 .thenReturn(<String>['package:p1/u1.dart', 'package:p1/u2.dart']); | 71 .thenReturn(<String>['package:p1/u1.dart', 'package:p1/u2.dart']); |
| 72 when(bundle.unlinkedUnits) | 72 when(bundle.unlinkedUnits) |
| 73 .thenReturn(<UnlinkedUnit>[unlinkedUnit1, unlinkedUnit2]); | 73 .thenReturn(<UnlinkedUnit>[unlinkedUnit1, unlinkedUnit2]); |
| 74 when(bundle.linkedLibraryUris).thenReturn(<String>['package:p1/u1.dart']); | 74 when(bundle.linkedLibraryUris).thenReturn(<String>['package:p1/u1.dart']); |
| 75 when(bundle.linkedLibraries).thenReturn(<LinkedLibrary>[linkedLibrary]); | 75 when(bundle.linkedLibraries).thenReturn(<LinkedLibrary>[linkedLibrary]); |
| 76 dataStore.addBundle('/p1.ds', bundle); | 76 dataStore.addBundle('/p1.ds', bundle); |
| 77 | 77 |
| 78 when(unlinkedUnit1.isPartOf).thenReturn(false); | 78 when(unlinkedUnit1.isPartOf).thenReturn(false); |
| 79 when(unlinkedUnit2.isPartOf).thenReturn(true); | 79 when(unlinkedUnit2.isPartOf).thenReturn(true); |
| 80 | 80 |
| 81 when(unlinkedUnit1.publicNamespace) | 81 var namespace1 = _namespaceWithParts(['package:p1/u2.dart']); |
| 82 .thenReturn(_namespaceWithParts(['package:p1/u2.dart'])); | 82 var namespace2 = _namespaceWithParts([]); |
| 83 when(unlinkedUnit2.publicNamespace).thenReturn(_namespaceWithParts([])); | 83 when(unlinkedUnit1.publicNamespace).thenReturn(namespace1); |
| 84 when(unlinkedUnit2.publicNamespace).thenReturn(namespace2); |
| 84 | 85 |
| 85 provider = new _TestResynthesizerResultProvider(context, dataStore); | 86 provider = new _TestResynthesizerResultProvider(context, dataStore); |
| 86 provider.sourcesWithResults.add(source1); | 87 provider.sourcesWithResults.add(source1); |
| 87 provider.sourcesWithResults.add(source2); | 88 provider.sourcesWithResults.add(source2); |
| 88 } | 89 } |
| 89 | 90 |
| 90 test_compute_CONTAINING_LIBRARIES_librarySource() { | 91 test_compute_CONTAINING_LIBRARIES_librarySource() { |
| 91 bool success = provider.compute(entry1, CONTAINING_LIBRARIES); | 92 bool success = provider.compute(entry1, CONTAINING_LIBRARIES); |
| 92 expect(success, isTrue); | 93 expect(success, isTrue); |
| 93 expect(entry1.getValue(CONTAINING_LIBRARIES), unorderedEquals([source1])); | 94 expect(entry1.getValue(CONTAINING_LIBRARIES), unorderedEquals([source1])); |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 expect(uris, unorderedEquals(['package:p1/u1.dart'])); | 273 expect(uris, unorderedEquals(['package:p1/u1.dart'])); |
| 273 } | 274 } |
| 274 | 275 |
| 275 test_getContainingLibraryUris_unknownUri() { | 276 test_getContainingLibraryUris_unknownUri() { |
| 276 String partUri = 'package:notInStore/foo.dart'; | 277 String partUri = 'package:notInStore/foo.dart'; |
| 277 List<String> uris = dataStore.getContainingLibraryUris(partUri); | 278 List<String> uris = dataStore.getContainingLibraryUris(partUri); |
| 278 expect(uris, isNull); | 279 expect(uris, isNull); |
| 279 } | 280 } |
| 280 | 281 |
| 281 void _setupDataStore(SummaryDataStore store) { | 282 void _setupDataStore(SummaryDataStore store) { |
| 283 var namespace1 = _namespaceWithParts(['package:p1/u2.dart']); |
| 284 var namespace2 = _namespaceWithParts([]); |
| 282 // bundle1 | 285 // bundle1 |
| 283 when(unlinkedUnit11.publicNamespace) | 286 when(unlinkedUnit11.publicNamespace).thenReturn(namespace1); |
| 284 .thenReturn(_namespaceWithParts(['package:p1/u2.dart'])); | 287 when(unlinkedUnit12.publicNamespace).thenReturn(namespace2); |
| 285 when(unlinkedUnit12.publicNamespace).thenReturn(_namespaceWithParts([])); | |
| 286 when(bundle1.unlinkedUnitUris) | 288 when(bundle1.unlinkedUnitUris) |
| 287 .thenReturn(<String>['package:p1/u1.dart', 'package:p1/u2.dart']); | 289 .thenReturn(<String>['package:p1/u1.dart', 'package:p1/u2.dart']); |
| 288 when(bundle1.unlinkedUnits) | 290 when(bundle1.unlinkedUnits) |
| 289 .thenReturn(<UnlinkedUnit>[unlinkedUnit11, unlinkedUnit12]); | 291 .thenReturn(<UnlinkedUnit>[unlinkedUnit11, unlinkedUnit12]); |
| 290 when(bundle1.linkedLibraryUris).thenReturn(<String>['package:p1/u1.dart']); | 292 when(bundle1.linkedLibraryUris).thenReturn(<String>['package:p1/u1.dart']); |
| 291 when(bundle1.linkedLibraries).thenReturn(<LinkedLibrary>[linkedLibrary1]); | 293 when(bundle1.linkedLibraries).thenReturn(<LinkedLibrary>[linkedLibrary1]); |
| 292 when(bundle1.apiSignature).thenReturn('signature1'); | 294 when(bundle1.apiSignature).thenReturn('signature1'); |
| 293 store.addBundle('/p1.ds', bundle1); | 295 store.addBundle('/p1.ds', bundle1); |
| 294 // bundle2 | 296 // bundle2 |
| 295 when(unlinkedUnit21.publicNamespace).thenReturn(_namespaceWithParts([])); | 297 when(unlinkedUnit21.publicNamespace).thenReturn(namespace2); |
| 296 when(bundle2.unlinkedUnitUris).thenReturn(<String>['package:p2/u1.dart']); | 298 when(bundle2.unlinkedUnitUris).thenReturn(<String>['package:p2/u1.dart']); |
| 297 when(bundle2.unlinkedUnits).thenReturn(<UnlinkedUnit>[unlinkedUnit21]); | 299 when(bundle2.unlinkedUnits).thenReturn(<UnlinkedUnit>[unlinkedUnit21]); |
| 298 when(bundle2.linkedLibraryUris).thenReturn(<String>['package:p2/u1.dart']); | 300 when(bundle2.linkedLibraryUris).thenReturn(<String>['package:p2/u1.dart']); |
| 299 when(bundle2.linkedLibraries).thenReturn(<LinkedLibrary>[linkedLibrary2]); | 301 when(bundle2.linkedLibraries).thenReturn(<LinkedLibrary>[linkedLibrary2]); |
| 300 when(bundle2.apiSignature).thenReturn('signature2'); | 302 when(bundle2.apiSignature).thenReturn('signature2'); |
| 301 store.addBundle('/p2.ds', bundle2); | 303 store.addBundle('/p2.ds', bundle2); |
| 302 } | 304 } |
| 303 } | 305 } |
| 304 | 306 |
| 305 class _ConflictingSummaryException extends TypeMatcher { | 307 class _ConflictingSummaryException extends TypeMatcher { |
| 306 const _ConflictingSummaryException() : super("ConflictingSummaryException"); | 308 const _ConflictingSummaryException() : super("ConflictingSummaryException"); |
| 307 bool matches(item, Map matchState) => item is ConflictingSummaryException; | 309 bool matches(item, Map matchState) => item is ConflictingSummaryException; |
| 308 } | 310 } |
| 309 | 311 |
| 310 class _InternalAnalysisContextMock extends TypedMock | 312 class _InternalAnalysisContextMock extends Mock |
| 311 implements InternalAnalysisContext {} | 313 implements InternalAnalysisContext {} |
| 312 | 314 |
| 313 class _LinkedLibraryMock extends TypedMock implements LinkedLibrary {} | 315 class _LinkedLibraryMock extends Mock implements LinkedLibrary {} |
| 314 | 316 |
| 315 class _PackageBundleMock extends TypedMock implements PackageBundle {} | 317 class _PackageBundleMock extends Mock implements PackageBundle {} |
| 316 | 318 |
| 317 class _SourceFactoryMock extends TypedMock implements SourceFactory {} | 319 class _SourceFactoryMock extends Mock implements SourceFactory {} |
| 318 | 320 |
| 319 class _SourceMock implements Source { | 321 class _SourceMock implements Source { |
| 320 final Uri uri; | 322 final Uri uri; |
| 321 final String fullName; | 323 final String fullName; |
| 322 | 324 |
| 323 _SourceMock(String uriStr, this.fullName) : uri = Uri.parse(uriStr); | 325 _SourceMock(String uriStr, this.fullName) : uri = Uri.parse(uriStr); |
| 324 | 326 |
| 325 @override | 327 @override |
| 326 Source get librarySource => null; | 328 Source get librarySource => null; |
| 327 | 329 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 340 _TestResynthesizerResultProvider( | 342 _TestResynthesizerResultProvider( |
| 341 InternalAnalysisContext context, SummaryDataStore dataStore) | 343 InternalAnalysisContext context, SummaryDataStore dataStore) |
| 342 : super(context, dataStore); | 344 : super(context, dataStore); |
| 343 | 345 |
| 344 @override | 346 @override |
| 345 bool hasResultsForSource(Source source) { | 347 bool hasResultsForSource(Source source) { |
| 346 return sourcesWithResults.contains(source); | 348 return sourcesWithResults.contains(source); |
| 347 } | 349 } |
| 348 } | 350 } |
| 349 | 351 |
| 350 class _UnlinkedPublicNamespaceMock extends TypedMock | 352 class _UnlinkedPublicNamespaceMock extends Mock |
| 351 implements UnlinkedPublicNamespace {} | 353 implements UnlinkedPublicNamespace {} |
| 352 | 354 |
| 353 class _UnlinkedUnitMock extends TypedMock implements UnlinkedUnit {} | 355 class _UnlinkedUnitMock extends Mock implements UnlinkedUnit {} |
| OLD | NEW |