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

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

Issue 1700263002: Add data structures to AST to indicate potentially mutated variables. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Follow Brian's suggestion Created 4 years, 10 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
« no previous file with comments | « pkg/analyzer/lib/src/generated/resolver.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 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/token.dart'; 8 import 'package:analyzer/dart/ast/token.dart';
9 import 'package:analyzer/dart/ast/visitor.dart'; 9 import 'package:analyzer/dart/ast/visitor.dart';
10 import 'package:analyzer/dart/element/element.dart'; 10 import 'package:analyzer/dart/element/element.dart';
(...skipping 4049 matching lines...) Expand 10 before | Expand all | Expand 10 after
4060 .assertErrorsWithCodes(<ErrorCode>[StaticWarningCode.UNDEFINED_CLASS]); 4060 .assertErrorsWithCodes(<ErrorCode>[StaticWarningCode.UNDEFINED_CLASS]);
4061 } 4061 }
4062 } 4062 }
4063 4063
4064 @reflectiveTest 4064 @reflectiveTest
4065 class ResolveVariableReferencesTaskTest extends _AbstractDartTaskTest { 4065 class ResolveVariableReferencesTaskTest extends _AbstractDartTaskTest {
4066 /** 4066 /**
4067 * Verify that the mutated states of the given [variable] correspond to the 4067 * Verify that the mutated states of the given [variable] correspond to the
4068 * [mutatedInClosure] and [mutatedInScope] matchers. 4068 * [mutatedInClosure] and [mutatedInScope] matchers.
4069 */ 4069 */
4070 void expectMutated(VariableElement variable, Matcher mutatedInClosure, 4070 void expectMutated(FunctionBody body, VariableElement variable,
4071 Matcher mutatedInScope) { 4071 bool mutatedInClosure, bool mutatedInScope) {
4072 expect(variable.isPotentiallyMutatedInClosure, mutatedInClosure); 4072 expect(variable.isPotentiallyMutatedInClosure, mutatedInClosure);
4073 expect(variable.isPotentiallyMutatedInScope, mutatedInScope); 4073 expect(variable.isPotentiallyMutatedInScope, mutatedInScope);
4074 expect(body.isPotentiallyMutatedInClosure(variable), mutatedInClosure);
4075 expect(body.isPotentiallyMutatedInScope(variable), mutatedInScope);
4074 } 4076 }
4075 4077
4076 test_created_resolved_unit() { 4078 test_created_resolved_unit() {
4077 Source source = newSource( 4079 Source source = newSource(
4078 '/test.dart', 4080 '/test.dart',
4079 r''' 4081 r'''
4080 library lib; 4082 library lib;
4081 class A {} 4083 class A {}
4082 '''); 4084 ''');
4083 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); 4085 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
(...skipping 29 matching lines...) Expand all
4113 v3 = 3; 4115 v3 = 3;
4114 v4 = 3; 4116 v4 = 3;
4115 } 4117 }
4116 } 4118 }
4117 '''); 4119 ''');
4118 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); 4120 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
4119 computeResult(target, RESOLVED_UNIT4, 4121 computeResult(target, RESOLVED_UNIT4,
4120 matcher: isResolveVariableReferencesTask); 4122 matcher: isResolveVariableReferencesTask);
4121 // validate 4123 // validate
4122 CompilationUnit unit = outputs[RESOLVED_UNIT4]; 4124 CompilationUnit unit = outputs[RESOLVED_UNIT4];
4123 FunctionElement main = unit.element.functions[0]; 4125 FunctionDeclaration mainDeclaration = unit.declarations[0];
4124 expectMutated(main.localVariables[0], isFalse, isFalse); 4126 FunctionBody body = mainDeclaration.functionExpression.body;
4125 expectMutated(main.localVariables[1], isFalse, isTrue); 4127 FunctionElement main = mainDeclaration.element;
4126 expectMutated(main.localVariables[2], isTrue, isTrue); 4128 expectMutated(body, main.localVariables[0], false, false);
4127 expectMutated(main.localVariables[3], isTrue, isTrue); 4129 expectMutated(body, main.localVariables[1], false, true);
4130 expectMutated(body, main.localVariables[2], true, true);
4131 expectMutated(body, main.localVariables[3], true, true);
4128 } 4132 }
4129 4133
4130 test_perform_parameter() { 4134 test_perform_parameter() {
4131 Source source = newSource( 4135 Source source = newSource(
4132 '/test.dart', 4136 '/test.dart',
4133 ''' 4137 '''
4134 main(p1, p2, p3, p4) { 4138 main(p1, p2, p3, p4) {
4135 p2 = 2; 4139 p2 = 2;
4136 p4 = 2; 4140 p4 = 2;
4137 localFunction() { 4141 localFunction() {
4138 p3 = 3; 4142 p3 = 3;
4139 p4 = 3; 4143 p4 = 3;
4140 } 4144 }
4141 } 4145 }
4142 '''); 4146 ''');
4143 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); 4147 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
4144 computeResult(target, RESOLVED_UNIT4, 4148 computeResult(target, RESOLVED_UNIT4,
4145 matcher: isResolveVariableReferencesTask); 4149 matcher: isResolveVariableReferencesTask);
4146 // validate 4150 // validate
4147 CompilationUnit unit = outputs[RESOLVED_UNIT4]; 4151 CompilationUnit unit = outputs[RESOLVED_UNIT4];
4148 FunctionElement main = unit.element.functions[0]; 4152 FunctionDeclaration mainDeclaration = unit.declarations[0];
4149 expectMutated(main.parameters[0], isFalse, isFalse); 4153 FunctionBody body = mainDeclaration.functionExpression.body;
4150 expectMutated(main.parameters[1], isFalse, isTrue); 4154 FunctionElement main = mainDeclaration.element;
4151 expectMutated(main.parameters[2], isTrue, isTrue); 4155 expectMutated(body, main.parameters[0], false, false);
4152 expectMutated(main.parameters[3], isTrue, isTrue); 4156 expectMutated(body, main.parameters[1], false, true);
4157 expectMutated(body, main.parameters[2], true, true);
4158 expectMutated(body, main.parameters[3], true, true);
4153 } 4159 }
4154 } 4160 }
4155 4161
4156 @reflectiveTest 4162 @reflectiveTest
4157 class ScanDartTaskTest extends _AbstractDartTaskTest { 4163 class ScanDartTaskTest extends _AbstractDartTaskTest {
4158 test_perform_errors() { 4164 test_perform_errors() {
4159 _performScanTask('import "'); 4165 _performScanTask('import "');
4160 expect(outputs, hasLength(3)); 4166 expect(outputs, hasLength(3));
4161 expect(outputs[LINE_INFO], isNotNull); 4167 expect(outputs[LINE_INFO], isNotNull);
4162 expect(outputs[SCAN_ERRORS], hasLength(1)); 4168 expect(outputs[SCAN_ERRORS], hasLength(1));
(...skipping 794 matching lines...) Expand 10 before | Expand all | Expand 10 after
4957 /** 4963 /**
4958 * Fill [errorListener] with [result] errors in the current [task]. 4964 * Fill [errorListener] with [result] errors in the current [task].
4959 */ 4965 */
4960 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { 4966 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) {
4961 List<AnalysisError> errors = task.outputs[result]; 4967 List<AnalysisError> errors = task.outputs[result];
4962 expect(errors, isNotNull, reason: result.name); 4968 expect(errors, isNotNull, reason: result.name);
4963 errorListener = new GatheringErrorListener(); 4969 errorListener = new GatheringErrorListener();
4964 errorListener.addAll(errors); 4970 errorListener.addAll(errors);
4965 } 4971 }
4966 } 4972 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/resolver.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698