| 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 library analyzer.test.driver; | 5 library analyzer.test.driver; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:convert'; | 8 import 'dart:convert'; |
| 9 | 9 |
| 10 import 'package:analyzer/dart/ast/ast.dart'; | 10 import 'package:analyzer/dart/ast/ast.dart'; |
| (...skipping 1153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1164 addTestFile(content); | 1164 addTestFile(content); |
| 1165 | 1165 |
| 1166 AnalysisDriverUnitIndex index = await driver.getIndex(testFile); | 1166 AnalysisDriverUnitIndex index = await driver.getIndex(testFile); |
| 1167 | 1167 |
| 1168 int unitId = index.strings.indexOf('package:test/test.dart'); | 1168 int unitId = index.strings.indexOf('package:test/test.dart'); |
| 1169 int fooId = index.strings.indexOf('foo'); | 1169 int fooId = index.strings.indexOf('foo'); |
| 1170 expect(unitId, isNonNegative); | 1170 expect(unitId, isNonNegative); |
| 1171 expect(fooId, isNonNegative); | 1171 expect(fooId, isNonNegative); |
| 1172 } | 1172 } |
| 1173 | 1173 |
| 1174 test_getLibraryByUri_external_resynthesize() async { |
| 1175 provider.newFile( |
| 1176 testFile, |
| 1177 r''' |
| 1178 class Test {} |
| 1179 '''); |
| 1180 |
| 1181 // Prepare the store with package:test/test.dart URI. |
| 1182 SummaryDataStore summaryStore = |
| 1183 createAnalysisDriver().test.getSummaryStore(testFile); |
| 1184 |
| 1185 // package:test/test.dart is in the store. |
| 1186 String uri = 'package:test/test.dart'; |
| 1187 expect(summaryStore.unlinkedMap.keys, contains(uri)); |
| 1188 expect(summaryStore.linkedMap.keys, contains(uri)); |
| 1189 |
| 1190 // Remove the file from the file system. |
| 1191 provider.deleteFile(testFile); |
| 1192 |
| 1193 // We can resynthesize the library from the store without reading the file. |
| 1194 AnalysisDriver driver = |
| 1195 createAnalysisDriver(externalSummaries: summaryStore); |
| 1196 expect(driver.test.numOfCreatedLibraryContexts, 0); |
| 1197 LibraryElement library = await driver.getLibraryByUri(uri); |
| 1198 expect(library.getType('Test'), isNotNull); |
| 1199 } |
| 1200 |
| 1201 test_getLibraryByUri_sdk_analyze() async { |
| 1202 LibraryElement coreLibrary = await driver.getLibraryByUri('dart:core'); |
| 1203 expect(coreLibrary, isNotNull); |
| 1204 expect(coreLibrary.getType('Object'), isNotNull); |
| 1205 expect(coreLibrary.getType('int'), isNotNull); |
| 1206 } |
| 1207 |
| 1208 test_getLibraryByUri_sdk_resynthesize() async { |
| 1209 SummaryDataStore sdkStore; |
| 1210 { |
| 1211 String corePath = sdk.mapDartUri('dart:core').fullName; |
| 1212 sdkStore = createAnalysisDriver().test.getSummaryStore(corePath); |
| 1213 } |
| 1214 |
| 1215 // There are dart:core and dart:async in the store. |
| 1216 expect(sdkStore.unlinkedMap.keys, contains('dart:core')); |
| 1217 expect(sdkStore.unlinkedMap.keys, contains('dart:async')); |
| 1218 expect(sdkStore.linkedMap.keys, contains('dart:core')); |
| 1219 expect(sdkStore.linkedMap.keys, contains('dart:async')); |
| 1220 |
| 1221 // We don't create new library context (so, don't parse, summarize and |
| 1222 // link) for dart:core. The library is resynthesized from the provided |
| 1223 // external store. |
| 1224 AnalysisDriver driver = createAnalysisDriver(externalSummaries: sdkStore); |
| 1225 LibraryElement coreLibrary = await driver.getLibraryByUri('dart:core'); |
| 1226 expect(driver.test.numOfCreatedLibraryContexts, 0); |
| 1227 expect(coreLibrary, isNotNull); |
| 1228 expect(coreLibrary.getType('Object'), isNotNull); |
| 1229 } |
| 1230 |
| 1174 test_getResult() async { | 1231 test_getResult() async { |
| 1175 String content = 'int f() => 42;'; | 1232 String content = 'int f() => 42;'; |
| 1176 addTestFile(content, priority: true); | 1233 addTestFile(content, priority: true); |
| 1177 | 1234 |
| 1178 AnalysisResult result = await driver.getResult(testFile); | 1235 AnalysisResult result = await driver.getResult(testFile); |
| 1179 expect(result.path, testFile); | 1236 expect(result.path, testFile); |
| 1180 expect(result.uri.toString(), 'package:test/test.dart'); | 1237 expect(result.uri.toString(), 'package:test/test.dart'); |
| 1181 expect(result.exists, isTrue); | 1238 expect(result.exists, isTrue); |
| 1182 expect(result.content, content); | 1239 expect(result.content, content); |
| 1183 expect(result.contentHash, _md5(content)); | 1240 expect(result.contentHash, _md5(content)); |
| (...skipping 1559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2743 var path = _p('/test.dart'); | 2800 var path = _p('/test.dart'); |
| 2744 expect(() { | 2801 expect(() { |
| 2745 driver.removeFile(path); | 2802 driver.removeFile(path); |
| 2746 }, throwsStateError); | 2803 }, throwsStateError); |
| 2747 } | 2804 } |
| 2748 | 2805 |
| 2749 String _p(String path) => provider.convertPath(path); | 2806 String _p(String path) => provider.convertPath(path); |
| 2750 } | 2807 } |
| 2751 | 2808 |
| 2752 class _SourceMock extends TypedMock implements Source {} | 2809 class _SourceMock extends TypedMock implements Source {} |
| OLD | NEW |