Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(579)

Side by Side Diff: pkg/analyzer/test/src/task/dart_test.dart

Issue 1321523002: Add a task to partially resolve a compilation unit (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 test.src.task.dart_test; 5 library test.src.task.dart_test;
6 6
7 import 'package:analyzer/src/context/cache.dart'; 7 import 'package:analyzer/src/context/cache.dart';
8 import 'package:analyzer/src/generated/ast.dart'; 8 import 'package:analyzer/src/generated/ast.dart';
9 import 'package:analyzer/src/generated/constant.dart'; 9 import 'package:analyzer/src/generated/constant.dart';
10 import 'package:analyzer/src/generated/element.dart'; 10 import 'package:analyzer/src/generated/element.dart';
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 runReflectiveTests(ComputeConstantValueTaskTest); 42 runReflectiveTests(ComputeConstantValueTaskTest);
43 runReflectiveTests(ContainingLibrariesTaskTest); 43 runReflectiveTests(ContainingLibrariesTaskTest);
44 runReflectiveTests(DartErrorsTaskTest); 44 runReflectiveTests(DartErrorsTaskTest);
45 runReflectiveTests(EvaluateUnitConstantsTaskTest); 45 runReflectiveTests(EvaluateUnitConstantsTaskTest);
46 runReflectiveTests(GatherUsedImportedElementsTaskTest); 46 runReflectiveTests(GatherUsedImportedElementsTaskTest);
47 runReflectiveTests(GatherUsedLocalElementsTaskTest); 47 runReflectiveTests(GatherUsedLocalElementsTaskTest);
48 runReflectiveTests(GenerateHintsTaskTest); 48 runReflectiveTests(GenerateHintsTaskTest);
49 runReflectiveTests(LibraryErrorsReadyTaskTest); 49 runReflectiveTests(LibraryErrorsReadyTaskTest);
50 runReflectiveTests(LibraryUnitErrorsTaskTest); 50 runReflectiveTests(LibraryUnitErrorsTaskTest);
51 runReflectiveTests(ParseDartTaskTest); 51 runReflectiveTests(ParseDartTaskTest);
52 runReflectiveTests(PartiallyResolveReferencesTaskTest);
52 runReflectiveTests(ResolveUnitTypeNamesTaskTest); 53 runReflectiveTests(ResolveUnitTypeNamesTaskTest);
53 runReflectiveTests(ResolveLibraryTypeNamesTaskTest); 54 runReflectiveTests(ResolveLibraryTypeNamesTaskTest);
54 runReflectiveTests(ResolveReferencesTaskTest); 55 runReflectiveTests(ResolveReferencesTaskTest);
55 runReflectiveTests(ResolveVariableReferencesTaskTest); 56 runReflectiveTests(ResolveVariableReferencesTaskTest);
56 runReflectiveTests(ScanDartTaskTest); 57 runReflectiveTests(ScanDartTaskTest);
57 runReflectiveTests(VerifyUnitTaskTest); 58 runReflectiveTests(VerifyUnitTaskTest);
58 } 59 }
59 60
60 @reflectiveTest 61 @reflectiveTest
61 class BuildCompilationUnitElementTaskTest extends _AbstractDartTaskTest { 62 class BuildCompilationUnitElementTaskTest extends _AbstractDartTaskTest {
(...skipping 2264 matching lines...) Expand 10 before | Expand all | Expand 10 after
2326 2327
2327 static void _assertHasCore(List<Source> sources, int lenght) { 2328 static void _assertHasCore(List<Source> sources, int lenght) {
2328 expect(sources, hasLength(lenght)); 2329 expect(sources, hasLength(lenght));
2329 expect(sources, contains(predicate((Source s) { 2330 expect(sources, contains(predicate((Source s) {
2330 return s.fullName.endsWith('core.dart'); 2331 return s.fullName.endsWith('core.dart');
2331 }))); 2332 })));
2332 } 2333 }
2333 } 2334 }
2334 2335
2335 @reflectiveTest 2336 @reflectiveTest
2337 class PartiallyResolveReferencesTaskTest extends _AbstractDartTaskTest {
2338 test_perform() {
2339 Source source = newSource(
2340 '/test.dart',
2341 '''
2342 int a = b;
2343 int b = c;
2344 ''');
2345 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
2346 computeResult(target, RESOLVED_UNIT4_1);
2347 expect(task, new isInstanceOf<PartiallyResolveUnitReferencesTask>());
2348 // Test the outputs
2349 CompilationUnit unit = outputs[RESOLVED_UNIT4_1];
2350 expect(unit, same(outputs[RESOLVED_UNIT4_1]));
2351 // Test the state of the AST
2352 TopLevelVariableDeclaration a = unit.declarations[0];
2353 VariableDeclaration variableA = a.variables.variables[0];
2354 SimpleIdentifier initializer = variableA.initializer;
2355 expect(initializer.staticElement, isNotNull);
2356 // Test the error generation
2357 _fillErrorListener(PARTIALLY_RESOLVE_REFERENCES_ERRORS);
2358 errorListener.assertErrorsWithCodes(
2359 <ErrorCode>[StaticWarningCode.UNDEFINED_IDENTIFIER]);
2360 }
2361
2362 test_perform_importExport() {
2363 newSource(
2364 '/a.dart',
2365 '''
2366 library a;
2367 class A<T> {
2368 T m() {}
2369 }
2370 ''');
2371 newSource(
2372 '/b.dart',
2373 '''
2374 library b;
2375 export 'a.dart';
2376 ''');
2377 Source sourceC = newSource(
2378 '/c.dart',
2379 '''
2380 library c;
2381 import 'b.dart';
2382 main() {
2383 new A<int>().m();
2384 }
2385 ''');
2386 computeResult(new LibrarySpecificUnit(sourceC, sourceC), RESOLVED_UNIT4_1);
2387 expect(task, new isInstanceOf<PartiallyResolveUnitReferencesTask>());
2388 // validate
2389 CompilationUnit unit = outputs[RESOLVED_UNIT4_1];
2390 expect(unit, isNotNull);
2391
2392 FunctionDeclaration functionDeclaration = unit.declarations[0];
2393 BlockFunctionBody body = functionDeclaration.functionExpression.body;
2394 List<Statement> statements = body.block.statements;
2395 ExpressionStatement statement = statements[0];
2396 MethodInvocation invocation = statement.expression;
2397 MethodElement methodElement = invocation.methodName.staticElement;
2398 expect(methodElement, isNotNull);
2399 expect(methodElement.type, isNotNull);
2400 expect(methodElement.returnType.toString(), 'int');
2401 }
2402 }
2403
2404 @reflectiveTest
2336 class ResolveLibraryTypeNamesTaskTest extends _AbstractDartTaskTest { 2405 class ResolveLibraryTypeNamesTaskTest extends _AbstractDartTaskTest {
2337 test_perform() { 2406 test_perform() {
2338 Source sourceLib = newSource( 2407 Source sourceLib = newSource(
2339 '/my_lib.dart', 2408 '/my_lib.dart',
2340 ''' 2409 '''
2341 library my_lib; 2410 library my_lib;
2342 part 'my_part.dart'; 2411 part 'my_part.dart';
2343 class A {} 2412 class A {}
2344 class B extends A {} 2413 class B extends A {}
2345 '''); 2414 ''');
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after
2840 /** 2909 /**
2841 * Fill [errorListener] with [result] errors in the current [task]. 2910 * Fill [errorListener] with [result] errors in the current [task].
2842 */ 2911 */
2843 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { 2912 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) {
2844 List<AnalysisError> errors = task.outputs[result]; 2913 List<AnalysisError> errors = task.outputs[result];
2845 expect(errors, isNotNull, reason: result.name); 2914 expect(errors, isNotNull, reason: result.name);
2846 errorListener = new GatheringErrorListener(); 2915 errorListener = new GatheringErrorListener();
2847 errorListener.addAll(errors); 2916 errorListener.addAll(errors);
2848 } 2917 }
2849 } 2918 }
OLDNEW
« pkg/analyzer/lib/src/task/dart.dart ('K') | « pkg/analyzer/lib/src/task/dart.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698