OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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.src.task.dart_test; | 5 library analyzer.test.src.task.dart_test; |
6 | 6 |
7 import 'package:analyzer/dart/ast/ast.dart'; | 7 import 'package:analyzer/dart/ast/ast.dart'; |
8 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; | 8 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; |
9 import 'package:analyzer/dart/ast/token.dart'; | 9 import 'package:analyzer/dart/ast/token.dart'; |
10 import 'package:analyzer/dart/ast/visitor.dart'; | 10 import 'package:analyzer/dart/ast/visitor.dart'; |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 CompilationUnit libraryUnitA = context | 287 CompilationUnit libraryUnitA = context |
288 .getCacheEntry(new LibrarySpecificUnit(sourceA, sourceA)) | 288 .getCacheEntry(new LibrarySpecificUnit(sourceA, sourceA)) |
289 .getValue(RESOLVED_UNIT1); | 289 .getValue(RESOLVED_UNIT1); |
290 { | 290 { |
291 ImportDirective importNode = libraryUnitA.directives[1]; | 291 ImportDirective importNode = libraryUnitA.directives[1]; |
292 ImportElement importElement = importNode.element; | 292 ImportElement importElement = importNode.element; |
293 expect(importElement, isNotNull); | 293 expect(importElement, isNotNull); |
294 expect(importElement.importedLibrary, libraryElementB); | 294 expect(importElement.importedLibrary, libraryElementB); |
295 expect(importElement.prefix, isNull); | 295 expect(importElement.prefix, isNull); |
296 expect(importElement.nameOffset, 14); | 296 expect(importElement.nameOffset, 14); |
297 expect(importElement.uriOffset, 21); | |
298 expect(importElement.uriEnd, 32); | |
299 } | 297 } |
300 { | 298 { |
301 ExportDirective exportNode = libraryUnitA.directives[2]; | 299 ExportDirective exportNode = libraryUnitA.directives[2]; |
302 ExportElement exportElement = exportNode.element; | 300 ExportElement exportElement = exportNode.element; |
303 expect(exportElement, isNotNull); | 301 expect(exportElement, isNotNull); |
304 expect(exportElement.exportedLibrary, libraryElementC); | 302 expect(exportElement.exportedLibrary, libraryElementC); |
305 expect(exportElement.nameOffset, 34); | 303 expect(exportElement.nameOffset, 34); |
306 expect(exportElement.uriOffset, 41); | |
307 expect(exportElement.uriEnd, 52); | |
308 } | 304 } |
309 // validate LibraryElement | 305 // validate LibraryElement |
310 expect(libraryElementA.hasExtUri, isFalse); | 306 expect(libraryElementA.hasExtUri, isFalse); |
311 // has an artificial "dart:core" import | 307 // has an artificial "dart:core" import |
312 { | 308 { |
313 List<ImportElement> imports = libraryElementA.imports; | 309 List<ImportElement> imports = libraryElementA.imports; |
314 expect(imports, hasLength(2)); | 310 expect(imports, hasLength(2)); |
315 expect(imports[1].importedLibrary.isDartCore, isTrue); | 311 expect(imports[1].importedLibrary.isDartCore, isTrue); |
316 expect(imports[1].isSynthetic, isTrue); | 312 expect(imports[1].isSynthetic, isTrue); |
317 } | 313 } |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 if (dart.library.io) 'foo_io.dart' | 361 if (dart.library.io) 'foo_io.dart' |
366 if (dart.library.html) 'foo_html.dart'; | 362 if (dart.library.html) 'foo_html.dart'; |
367 '''); | 363 '''); |
368 // Perform the task. | 364 // Perform the task. |
369 computeResult(testSource, LIBRARY_ELEMENT2, | 365 computeResult(testSource, LIBRARY_ELEMENT2, |
370 matcher: isBuildDirectiveElementsTask); | 366 matcher: isBuildDirectiveElementsTask); |
371 LibraryElement testLibrary = outputs[LIBRARY_ELEMENT2]; | 367 LibraryElement testLibrary = outputs[LIBRARY_ELEMENT2]; |
372 // Validate the export element. | 368 // Validate the export element. |
373 ExportElement export = testLibrary.exports[0]; | 369 ExportElement export = testLibrary.exports[0]; |
374 expect(export.exportedLibrary.source, foo_io); | 370 expect(export.exportedLibrary.source, foo_io); |
375 expect(export.uri, 'foo_io.dart'); | |
376 } | 371 } |
377 | 372 |
378 test_perform_configurations_import() { | 373 test_perform_configurations_import() { |
379 context.declaredVariables.define('dart.library.io', 'true'); | 374 context.declaredVariables.define('dart.library.io', 'true'); |
380 context.declaredVariables.define('dart.library.html', 'true'); | 375 context.declaredVariables.define('dart.library.html', 'true'); |
381 newSource('/foo.dart', ''); | 376 newSource('/foo.dart', ''); |
382 var foo_io = newSource('/foo_io.dart', ''); | 377 var foo_io = newSource('/foo_io.dart', ''); |
383 newSource('/foo_html.dart', ''); | 378 newSource('/foo_html.dart', ''); |
384 var testSource = newSource('/test.dart', r''' | 379 var testSource = newSource('/test.dart', r''' |
385 import 'foo.dart' | 380 import 'foo.dart' |
386 if (dart.library.io) 'foo_io.dart' | 381 if (dart.library.io) 'foo_io.dart' |
387 if (dart.library.html) 'foo_html.dart'; | 382 if (dart.library.html) 'foo_html.dart'; |
388 '''); | 383 '''); |
389 // Perform the task. | 384 // Perform the task. |
390 computeResult(testSource, LIBRARY_ELEMENT2, | 385 computeResult(testSource, LIBRARY_ELEMENT2, |
391 matcher: isBuildDirectiveElementsTask); | 386 matcher: isBuildDirectiveElementsTask); |
392 LibraryElement testLibrary = outputs[LIBRARY_ELEMENT2]; | 387 LibraryElement testLibrary = outputs[LIBRARY_ELEMENT2]; |
393 // Validate the import element. | 388 // Validate the import element. |
394 ImportElement import = testLibrary.imports[0]; | 389 ImportElement import = testLibrary.imports[0]; |
395 expect(import.importedLibrary.source, foo_io); | 390 expect(import.importedLibrary.source, foo_io); |
396 expect(import.uri, 'foo_io.dart'); | |
397 } | 391 } |
398 | 392 |
399 test_perform_dartCoreContext() { | 393 test_perform_dartCoreContext() { |
400 List<Source> sources = newSources({'/libA.dart': ''}); | 394 List<Source> sources = newSources({'/libA.dart': ''}); |
401 Source source = sources[0]; | 395 Source source = sources[0]; |
402 // perform task | 396 // perform task |
403 computeResult(source, LIBRARY_ELEMENT2, | 397 computeResult(source, LIBRARY_ELEMENT2, |
404 matcher: isBuildDirectiveElementsTask); | 398 matcher: isBuildDirectiveElementsTask); |
405 // prepare outputs | 399 // prepare outputs |
406 LibraryElement libraryElement = outputs[LIBRARY_ELEMENT2]; | 400 LibraryElement libraryElement = outputs[LIBRARY_ELEMENT2]; |
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
801 // LibraryElement references | 795 // LibraryElement references |
802 expect((libraryUnit.directives[0] as LibraryDirective).element, | 796 expect((libraryUnit.directives[0] as LibraryDirective).element, |
803 same(libraryElement)); | 797 same(libraryElement)); |
804 expect((partUnits[0].directives[0] as PartOfDirective).element, | 798 expect((partUnits[0].directives[0] as PartOfDirective).element, |
805 same(libraryElement)); | 799 same(libraryElement)); |
806 expect((partUnits[1].directives[0] as PartOfDirective).element, | 800 expect((partUnits[1].directives[0] as PartOfDirective).element, |
807 same(libraryElement)); | 801 same(libraryElement)); |
808 // CompilationUnitElement(s) | 802 // CompilationUnitElement(s) |
809 CompilationUnitElement firstPart; | 803 CompilationUnitElement firstPart; |
810 CompilationUnitElement secondPart; | 804 CompilationUnitElement secondPart; |
811 if (resolutionMap.elementDeclaredByCompilationUnit(partUnits[0]).uri == | 805 if (resolutionMap |
| 806 .elementDeclaredByCompilationUnit(partUnits[0]) |
| 807 .source |
| 808 .shortName == |
812 'part1.dart') { | 809 'part1.dart') { |
813 firstPart = partUnits[0].element; | 810 firstPart = partUnits[0].element; |
814 secondPart = partUnits[1].element; | 811 secondPart = partUnits[1].element; |
815 } else { | 812 } else { |
816 firstPart = partUnits[1].element; | 813 firstPart = partUnits[1].element; |
817 secondPart = partUnits[0].element; | 814 secondPart = partUnits[0].element; |
818 } | 815 } |
819 expect(firstPart.uri, 'part1.dart'); | 816 expect(firstPart.source.shortName, 'part1.dart'); |
820 expect(firstPart.uriOffset, 18); | |
821 expect(firstPart.uriEnd, 30); | |
822 expect( | 817 expect( |
823 (libraryUnit.directives[1] as PartDirective).element, same(firstPart)); | 818 (libraryUnit.directives[1] as PartDirective).element, same(firstPart)); |
824 | 819 |
825 expect(secondPart.uri, 'part2.dart'); | 820 expect(secondPart.source.shortName, 'part2.dart'); |
826 expect(secondPart.uriOffset, 37); | |
827 expect(secondPart.uriEnd, 49); | |
828 expect( | 821 expect( |
829 (libraryUnit.directives[2] as PartDirective).element, same(secondPart)); | 822 (libraryUnit.directives[2] as PartDirective).element, same(secondPart)); |
830 } | 823 } |
831 | 824 |
832 test_perform_error_missingLibraryDirectiveWithPart() { | 825 test_perform_error_missingLibraryDirectiveWithPart() { |
833 _performBuildTask({ | 826 _performBuildTask({ |
834 '/lib.dart': ''' | 827 '/lib.dart': ''' |
835 part 'partA.dart'; | 828 part 'partA.dart'; |
836 part 'partB.dart'; | 829 part 'partB.dart'; |
837 ''', | 830 ''', |
(...skipping 4152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4990 /** | 4983 /** |
4991 * Fill [errorListener] with [result] errors in the current [task]. | 4984 * Fill [errorListener] with [result] errors in the current [task]. |
4992 */ | 4985 */ |
4993 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { | 4986 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { |
4994 List<AnalysisError> errors = task.outputs[result] as List<AnalysisError>; | 4987 List<AnalysisError> errors = task.outputs[result] as List<AnalysisError>; |
4995 expect(errors, isNotNull, reason: result.name); | 4988 expect(errors, isNotNull, reason: result.name); |
4996 errorListener = new GatheringErrorListener(); | 4989 errorListener = new GatheringErrorListener(); |
4997 errorListener.addAll(errors); | 4990 errorListener.addAll(errors); |
4998 } | 4991 } |
4999 } | 4992 } |
OLD | NEW |