| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 library analyzer.test.src.summary.in_summary_source_test; |
| 6 |
| 7 import 'package:analyzer/file_system/physical_file_system.dart'; |
| 8 import 'package:analyzer/src/generated/source_io.dart'; |
| 9 import 'package:analyzer/src/summary/format.dart'; |
| 10 import 'package:analyzer/src/summary/idl.dart'; |
| 11 import 'package:analyzer/src/summary/package_bundle_reader.dart'; |
| 12 import 'package:path/path.dart'; |
| 13 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 14 import 'package:unittest/unittest.dart'; |
| 15 |
| 16 main() { |
| 17 groupSep = ' | '; |
| 18 defineReflectiveTests(InSummarySourceTest); |
| 19 } |
| 20 |
| 21 @reflectiveTest |
| 22 class InSummarySourceTest extends ReflectiveTest { |
| 23 test_fallbackPath() { |
| 24 String fooFallbackPath = absolute('path', 'to', 'foo.dart'); |
| 25 var sourceFactory = new SourceFactory([ |
| 26 new InSummaryUriResolver( |
| 27 PhysicalResourceProvider.INSTANCE, |
| 28 new MockSummaryDataStore.fake({ |
| 29 'package:foo/foo.dart': 'foo.sum', |
| 30 }, uriToFallbackModePath: { |
| 31 'package:foo/foo.dart': fooFallbackPath |
| 32 })) |
| 33 ]); |
| 34 |
| 35 InSummarySource source = sourceFactory.forUri('package:foo/foo.dart'); |
| 36 expect(source, isNotNull); |
| 37 expect(source.fullName, fooFallbackPath); |
| 38 } |
| 39 |
| 40 test_InSummarySource() { |
| 41 var sourceFactory = new SourceFactory([ |
| 42 new InSummaryUriResolver( |
| 43 PhysicalResourceProvider.INSTANCE, |
| 44 new MockSummaryDataStore.fake({ |
| 45 'package:foo/foo.dart': 'foo.sum', |
| 46 'package:foo/src/foo_impl.dart': 'foo.sum', |
| 47 'package:bar/baz.dart': 'bar.sum', |
| 48 })) |
| 49 ]); |
| 50 |
| 51 InSummarySource source = sourceFactory.forUri('package:foo/foo.dart'); |
| 52 expect(source, isNotNull); |
| 53 expect(source.summaryPath, 'foo.sum'); |
| 54 |
| 55 source = sourceFactory.forUri('package:foo/src/foo_impl.dart'); |
| 56 expect(source, isNotNull); |
| 57 expect(source.summaryPath, 'foo.sum'); |
| 58 |
| 59 source = sourceFactory.forUri('package:bar/baz.dart'); |
| 60 expect(source, isNotNull); |
| 61 expect(source.summaryPath, 'bar.sum'); |
| 62 } |
| 63 } |
| 64 |
| 65 class MockSummaryDataStore implements SummaryDataStore { |
| 66 final Map<String, LinkedLibrary> linkedMap; |
| 67 final Map<String, UnlinkedUnit> unlinkedMap; |
| 68 final Map<String, String> uriToSummaryPath; |
| 69 |
| 70 MockSummaryDataStore(this.linkedMap, this.unlinkedMap, this.uriToSummaryPath); |
| 71 |
| 72 factory MockSummaryDataStore.fake(Map<String, String> uriToSummary, |
| 73 {Map<String, String> uriToFallbackModePath: const {}}) { |
| 74 // Create fake unlinked map. |
| 75 // We don't populate the values as it is not needed for the test. |
| 76 var unlinkedMap = new Map<String, UnlinkedUnit>.fromIterable( |
| 77 uriToSummary.keys, |
| 78 value: (uri) => new UnlinkedUnitBuilder( |
| 79 fallbackModePath: uriToFallbackModePath[uri])); |
| 80 return new MockSummaryDataStore(null, unlinkedMap, uriToSummary); |
| 81 } |
| 82 |
| 83 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 84 } |
| OLD | NEW |