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'; |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 | 106 |
107 test_compute_SOURCE_KIND_partSource() { | 107 test_compute_SOURCE_KIND_partSource() { |
108 bool success = provider.compute(entry2, SOURCE_KIND); | 108 bool success = provider.compute(entry2, SOURCE_KIND); |
109 expect(success, isTrue); | 109 expect(success, isTrue); |
110 expect(entry2.getValue(SOURCE_KIND), SourceKind.PART); | 110 expect(entry2.getValue(SOURCE_KIND), SourceKind.PART); |
111 } | 111 } |
112 } | 112 } |
113 | 113 |
114 @reflectiveTest | 114 @reflectiveTest |
115 class SummaryDataStoreTest { | 115 class SummaryDataStoreTest { |
116 SummaryDataStore dataStore = new SummaryDataStore(<String>[]); | 116 SummaryDataStore dataStore = |
| 117 new SummaryDataStore(<String>[], recordDependencyInfo: true); |
117 | 118 |
118 PackageBundle bundle1 = new _PackageBundleMock(); | 119 PackageBundle bundle1 = new _PackageBundleMock(); |
119 PackageBundle bundle2 = new _PackageBundleMock(); | 120 PackageBundle bundle2 = new _PackageBundleMock(); |
120 UnlinkedUnit unlinkedUnit11 = new _UnlinkedUnitMock(); | 121 UnlinkedUnit unlinkedUnit11 = new _UnlinkedUnitMock(); |
121 UnlinkedUnit unlinkedUnit12 = new _UnlinkedUnitMock(); | 122 UnlinkedUnit unlinkedUnit12 = new _UnlinkedUnitMock(); |
122 UnlinkedUnit unlinkedUnit21 = new _UnlinkedUnitMock(); | 123 UnlinkedUnit unlinkedUnit21 = new _UnlinkedUnitMock(); |
123 LinkedLibrary linkedLibrary1 = new _LinkedLibraryMock(); | 124 LinkedLibrary linkedLibrary1 = new _LinkedLibraryMock(); |
124 LinkedLibrary linkedLibrary2 = new _LinkedLibraryMock(); | 125 LinkedLibrary linkedLibrary2 = new _LinkedLibraryMock(); |
125 | 126 |
126 void setUp() { | 127 void setUp() { |
127 // bundle1 | 128 // bundle1 |
128 when(unlinkedUnit11.publicNamespace) | 129 when(unlinkedUnit11.publicNamespace) |
129 .thenReturn(_namespaceWithParts(['package:p1/u2.dart'])); | 130 .thenReturn(_namespaceWithParts(['package:p1/u2.dart'])); |
130 when(unlinkedUnit12.publicNamespace).thenReturn(_namespaceWithParts([])); | 131 when(unlinkedUnit12.publicNamespace).thenReturn(_namespaceWithParts([])); |
131 when(bundle1.unlinkedUnitUris) | 132 when(bundle1.unlinkedUnitUris) |
132 .thenReturn(<String>['package:p1/u1.dart', 'package:p1/u2.dart']); | 133 .thenReturn(<String>['package:p1/u1.dart', 'package:p1/u2.dart']); |
133 when(bundle1.unlinkedUnits) | 134 when(bundle1.unlinkedUnits) |
134 .thenReturn(<UnlinkedUnit>[unlinkedUnit11, unlinkedUnit12]); | 135 .thenReturn(<UnlinkedUnit>[unlinkedUnit11, unlinkedUnit12]); |
135 when(bundle1.linkedLibraryUris).thenReturn(<String>['package:p1/u1.dart']); | 136 when(bundle1.linkedLibraryUris).thenReturn(<String>['package:p1/u1.dart']); |
136 when(bundle1.linkedLibraries).thenReturn(<LinkedLibrary>[linkedLibrary1]); | 137 when(bundle1.linkedLibraries).thenReturn(<LinkedLibrary>[linkedLibrary1]); |
| 138 when(bundle1.apiSignature).thenReturn('signature1'); |
137 dataStore.addBundle('/p1.ds', bundle1); | 139 dataStore.addBundle('/p1.ds', bundle1); |
138 // bundle2 | 140 // bundle2 |
139 when(unlinkedUnit21.publicNamespace).thenReturn(_namespaceWithParts([])); | 141 when(unlinkedUnit21.publicNamespace).thenReturn(_namespaceWithParts([])); |
140 when(bundle2.unlinkedUnitUris).thenReturn(<String>['package:p2/u1.dart']); | 142 when(bundle2.unlinkedUnitUris).thenReturn(<String>['package:p2/u1.dart']); |
141 when(bundle2.unlinkedUnits).thenReturn(<UnlinkedUnit>[unlinkedUnit21]); | 143 when(bundle2.unlinkedUnits).thenReturn(<UnlinkedUnit>[unlinkedUnit21]); |
142 when(bundle2.linkedLibraryUris).thenReturn(<String>['package:p2/u1.dart']); | 144 when(bundle2.linkedLibraryUris).thenReturn(<String>['package:p2/u1.dart']); |
143 when(bundle2.linkedLibraries).thenReturn(<LinkedLibrary>[linkedLibrary2]); | 145 when(bundle2.linkedLibraries).thenReturn(<LinkedLibrary>[linkedLibrary2]); |
| 146 when(bundle2.apiSignature).thenReturn('signature2'); |
144 dataStore.addBundle('/p2.ds', bundle2); | 147 dataStore.addBundle('/p2.ds', bundle2); |
145 } | 148 } |
146 | 149 |
147 test_addBundle() { | 150 test_addBundle() { |
148 expect(dataStore.bundles, unorderedEquals([bundle1, bundle2])); | 151 expect(dataStore.bundles, unorderedEquals([bundle1, bundle2])); |
| 152 expect(dataStore.dependencies[0].summaryPath, '/p1.ds'); |
| 153 expect(dataStore.dependencies[0].apiSignature, 'signature1'); |
| 154 expect(dataStore.dependencies[0].includedPackageNames, ['p1']); |
| 155 expect(dataStore.dependencies[0].includesFileUris, false); |
| 156 expect(dataStore.dependencies[0].includesDartUris, false); |
| 157 expect(dataStore.dependencies[1].summaryPath, '/p2.ds'); |
| 158 expect(dataStore.dependencies[1].apiSignature, 'signature2'); |
| 159 expect(dataStore.dependencies[1].includedPackageNames, ['p2']); |
| 160 expect(dataStore.dependencies[1].includesFileUris, false); |
| 161 expect(dataStore.dependencies[1].includesDartUris, false); |
149 expect(dataStore.uriToSummaryPath, | 162 expect(dataStore.uriToSummaryPath, |
150 containsPair('package:p1/u1.dart', '/p1.ds')); | 163 containsPair('package:p1/u1.dart', '/p1.ds')); |
151 // unlinkedMap | 164 // unlinkedMap |
152 expect(dataStore.unlinkedMap, hasLength(3)); | 165 expect(dataStore.unlinkedMap, hasLength(3)); |
153 expect(dataStore.unlinkedMap, | 166 expect(dataStore.unlinkedMap, |
154 containsPair('package:p1/u1.dart', unlinkedUnit11)); | 167 containsPair('package:p1/u1.dart', unlinkedUnit11)); |
155 expect(dataStore.unlinkedMap, | 168 expect(dataStore.unlinkedMap, |
156 containsPair('package:p1/u2.dart', unlinkedUnit12)); | 169 containsPair('package:p1/u2.dart', unlinkedUnit12)); |
157 expect(dataStore.unlinkedMap, | 170 expect(dataStore.unlinkedMap, |
158 containsPair('package:p2/u1.dart', unlinkedUnit21)); | 171 containsPair('package:p2/u1.dart', unlinkedUnit21)); |
159 // linkedMap | 172 // linkedMap |
160 expect(dataStore.linkedMap, hasLength(2)); | 173 expect(dataStore.linkedMap, hasLength(2)); |
161 expect(dataStore.linkedMap, | 174 expect(dataStore.linkedMap, |
162 containsPair('package:p1/u1.dart', linkedLibrary1)); | 175 containsPair('package:p1/u1.dart', linkedLibrary1)); |
163 expect(dataStore.linkedMap, | 176 expect(dataStore.linkedMap, |
164 containsPair('package:p2/u1.dart', linkedLibrary2)); | 177 containsPair('package:p2/u1.dart', linkedLibrary2)); |
165 } | 178 } |
166 | 179 |
| 180 test_addBundle_dartUris() { |
| 181 PackageBundle bundle = new _PackageBundleMock(); |
| 182 when(bundle.unlinkedUnitUris).thenReturn(<String>['dart:core']); |
| 183 when(bundle.unlinkedUnits).thenReturn(<UnlinkedUnit>[unlinkedUnit11]); |
| 184 when(bundle.linkedLibraryUris).thenReturn(<String>['dart:core']); |
| 185 when(bundle.linkedLibraries).thenReturn(<LinkedLibrary>[linkedLibrary1]); |
| 186 when(bundle.apiSignature).thenReturn('signature'); |
| 187 dataStore.addBundle('/p3.ds', bundle); |
| 188 expect(dataStore.dependencies.last.includedPackageNames, []); |
| 189 expect(dataStore.dependencies.last.includesFileUris, false); |
| 190 expect(dataStore.dependencies.last.includesDartUris, true); |
| 191 } |
| 192 |
| 193 test_addBundle_fileUris() { |
| 194 PackageBundle bundle = new _PackageBundleMock(); |
| 195 when(bundle.unlinkedUnitUris).thenReturn(<String>['file:/foo.dart']); |
| 196 when(bundle.unlinkedUnits).thenReturn(<UnlinkedUnit>[unlinkedUnit11]); |
| 197 when(bundle.linkedLibraryUris).thenReturn(<String>['file:/foo.dart']); |
| 198 when(bundle.linkedLibraries).thenReturn(<LinkedLibrary>[linkedLibrary1]); |
| 199 when(bundle.apiSignature).thenReturn('signature'); |
| 200 dataStore.addBundle('/p3.ds', bundle); |
| 201 expect(dataStore.dependencies.last.includedPackageNames, []); |
| 202 expect(dataStore.dependencies.last.includesFileUris, true); |
| 203 expect(dataStore.dependencies.last.includesDartUris, false); |
| 204 } |
| 205 |
| 206 test_addBundle_multiProject() { |
| 207 PackageBundle bundle = new _PackageBundleMock(); |
| 208 when(bundle.unlinkedUnitUris) |
| 209 .thenReturn(<String>['package:p2/u1.dart', 'package:p1/u1.dart']); |
| 210 when(bundle.unlinkedUnits) |
| 211 .thenReturn(<UnlinkedUnit>[unlinkedUnit21, unlinkedUnit11]); |
| 212 when(bundle.linkedLibraryUris) |
| 213 .thenReturn(<String>['package:p2/u1.dart', 'package:p1/u1.dart']); |
| 214 when(bundle.linkedLibraries) |
| 215 .thenReturn(<LinkedLibrary>[linkedLibrary2, linkedLibrary1]); |
| 216 when(bundle.apiSignature).thenReturn('signature'); |
| 217 dataStore.addBundle('/p3.ds', bundle); |
| 218 expect(dataStore.dependencies.last.includedPackageNames, ['p1', 'p2']); |
| 219 } |
| 220 |
167 test_getContainingLibraryUris_libraryUri() { | 221 test_getContainingLibraryUris_libraryUri() { |
168 String partUri = 'package:p1/u1.dart'; | 222 String partUri = 'package:p1/u1.dart'; |
169 List<String> uris = dataStore.getContainingLibraryUris(partUri); | 223 List<String> uris = dataStore.getContainingLibraryUris(partUri); |
170 expect(uris, unorderedEquals([partUri])); | 224 expect(uris, unorderedEquals([partUri])); |
171 } | 225 } |
172 | 226 |
173 test_getContainingLibraryUris_partUri() { | 227 test_getContainingLibraryUris_partUri() { |
174 String partUri = 'package:p1/u2.dart'; | 228 String partUri = 'package:p1/u2.dart'; |
175 List<String> uris = dataStore.getContainingLibraryUris(partUri); | 229 List<String> uris = dataStore.getContainingLibraryUris(partUri); |
176 expect(uris, unorderedEquals(['package:p1/u1.dart'])); | 230 expect(uris, unorderedEquals(['package:p1/u1.dart'])); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 @override | 274 @override |
221 bool hasResultsForSource(Source source) { | 275 bool hasResultsForSource(Source source) { |
222 return sourcesWithResults.contains(source); | 276 return sourcesWithResults.contains(source); |
223 } | 277 } |
224 } | 278 } |
225 | 279 |
226 class _UnlinkedPublicNamespaceMock extends TypedMock | 280 class _UnlinkedPublicNamespaceMock extends TypedMock |
227 implements UnlinkedPublicNamespace {} | 281 implements UnlinkedPublicNamespace {} |
228 | 282 |
229 class _UnlinkedUnitMock extends TypedMock implements UnlinkedUnit {} | 283 class _UnlinkedUnitMock extends TypedMock implements UnlinkedUnit {} |
OLD | NEW |