| 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/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 Loading... |
| 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.localVariableInfo.potentiallyMutatedInClosure, |
| 4075 mutatedInClosure ? contains(variable) : isNot(contains(variable))); |
| 4076 expect(body.localVariableInfo.potentiallyMutatedInScope, |
| 4077 mutatedInScope ? contains(variable) : isNot(contains(variable))); |
| 4074 } | 4078 } |
| 4075 | 4079 |
| 4076 test_created_resolved_unit() { | 4080 test_created_resolved_unit() { |
| 4077 Source source = newSource( | 4081 Source source = newSource( |
| 4078 '/test.dart', | 4082 '/test.dart', |
| 4079 r''' | 4083 r''' |
| 4080 library lib; | 4084 library lib; |
| 4081 class A {} | 4085 class A {} |
| 4082 '''); | 4086 '''); |
| 4083 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 4087 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 4113 v3 = 3; | 4117 v3 = 3; |
| 4114 v4 = 3; | 4118 v4 = 3; |
| 4115 } | 4119 } |
| 4116 } | 4120 } |
| 4117 '''); | 4121 '''); |
| 4118 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 4122 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 4119 computeResult(target, RESOLVED_UNIT4, | 4123 computeResult(target, RESOLVED_UNIT4, |
| 4120 matcher: isResolveVariableReferencesTask); | 4124 matcher: isResolveVariableReferencesTask); |
| 4121 // validate | 4125 // validate |
| 4122 CompilationUnit unit = outputs[RESOLVED_UNIT4]; | 4126 CompilationUnit unit = outputs[RESOLVED_UNIT4]; |
| 4123 FunctionElement main = unit.element.functions[0]; | 4127 FunctionDeclaration mainDeclaration = unit.declarations[0]; |
| 4124 expectMutated(main.localVariables[0], isFalse, isFalse); | 4128 FunctionBody body = mainDeclaration.functionExpression.body; |
| 4125 expectMutated(main.localVariables[1], isFalse, isTrue); | 4129 FunctionElement main = mainDeclaration.element; |
| 4126 expectMutated(main.localVariables[2], isTrue, isTrue); | 4130 expectMutated(body, main.localVariables[0], false, false); |
| 4127 expectMutated(main.localVariables[3], isTrue, isTrue); | 4131 expectMutated(body, main.localVariables[1], false, true); |
| 4132 expectMutated(body, main.localVariables[2], true, true); |
| 4133 expectMutated(body, main.localVariables[3], true, true); |
| 4128 } | 4134 } |
| 4129 | 4135 |
| 4130 test_perform_parameter() { | 4136 test_perform_parameter() { |
| 4131 Source source = newSource( | 4137 Source source = newSource( |
| 4132 '/test.dart', | 4138 '/test.dart', |
| 4133 ''' | 4139 ''' |
| 4134 main(p1, p2, p3, p4) { | 4140 main(p1, p2, p3, p4) { |
| 4135 p2 = 2; | 4141 p2 = 2; |
| 4136 p4 = 2; | 4142 p4 = 2; |
| 4137 localFunction() { | 4143 localFunction() { |
| 4138 p3 = 3; | 4144 p3 = 3; |
| 4139 p4 = 3; | 4145 p4 = 3; |
| 4140 } | 4146 } |
| 4141 } | 4147 } |
| 4142 '''); | 4148 '''); |
| 4143 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 4149 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 4144 computeResult(target, RESOLVED_UNIT4, | 4150 computeResult(target, RESOLVED_UNIT4, |
| 4145 matcher: isResolveVariableReferencesTask); | 4151 matcher: isResolveVariableReferencesTask); |
| 4146 // validate | 4152 // validate |
| 4147 CompilationUnit unit = outputs[RESOLVED_UNIT4]; | 4153 CompilationUnit unit = outputs[RESOLVED_UNIT4]; |
| 4148 FunctionElement main = unit.element.functions[0]; | 4154 FunctionDeclaration mainDeclaration = unit.declarations[0]; |
| 4149 expectMutated(main.parameters[0], isFalse, isFalse); | 4155 FunctionBody body = mainDeclaration.functionExpression.body; |
| 4150 expectMutated(main.parameters[1], isFalse, isTrue); | 4156 FunctionElement main = mainDeclaration.element; |
| 4151 expectMutated(main.parameters[2], isTrue, isTrue); | 4157 expectMutated(body, main.parameters[0], false, false); |
| 4152 expectMutated(main.parameters[3], isTrue, isTrue); | 4158 expectMutated(body, main.parameters[1], false, true); |
| 4159 expectMutated(body, main.parameters[2], true, true); |
| 4160 expectMutated(body, main.parameters[3], true, true); |
| 4153 } | 4161 } |
| 4154 } | 4162 } |
| 4155 | 4163 |
| 4156 @reflectiveTest | 4164 @reflectiveTest |
| 4157 class ScanDartTaskTest extends _AbstractDartTaskTest { | 4165 class ScanDartTaskTest extends _AbstractDartTaskTest { |
| 4158 test_perform_errors() { | 4166 test_perform_errors() { |
| 4159 _performScanTask('import "'); | 4167 _performScanTask('import "'); |
| 4160 expect(outputs, hasLength(3)); | 4168 expect(outputs, hasLength(3)); |
| 4161 expect(outputs[LINE_INFO], isNotNull); | 4169 expect(outputs[LINE_INFO], isNotNull); |
| 4162 expect(outputs[SCAN_ERRORS], hasLength(1)); | 4170 expect(outputs[SCAN_ERRORS], hasLength(1)); |
| (...skipping 794 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4957 /** | 4965 /** |
| 4958 * Fill [errorListener] with [result] errors in the current [task]. | 4966 * Fill [errorListener] with [result] errors in the current [task]. |
| 4959 */ | 4967 */ |
| 4960 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { | 4968 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { |
| 4961 List<AnalysisError> errors = task.outputs[result]; | 4969 List<AnalysisError> errors = task.outputs[result]; |
| 4962 expect(errors, isNotNull, reason: result.name); | 4970 expect(errors, isNotNull, reason: result.name); |
| 4963 errorListener = new GatheringErrorListener(); | 4971 errorListener = new GatheringErrorListener(); |
| 4964 errorListener.addAll(errors); | 4972 errorListener.addAll(errors); |
| 4965 } | 4973 } |
| 4966 } | 4974 } |
| OLD | NEW |