OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 engine.incremental_resolver_test; | 5 library engine.incremental_resolver_test; |
6 | 6 |
7 import 'package:analyzer/src/context/cache.dart' as task; | 7 import 'package:analyzer/src/context/cache.dart' as task; |
8 import 'package:analyzer/src/generated/ast.dart'; | 8 import 'package:analyzer/src/generated/ast.dart'; |
9 import 'package:analyzer/src/generated/element.dart'; | 9 import 'package:analyzer/src/generated/element.dart'; |
10 import 'package:analyzer/src/generated/engine.dart'; | 10 import 'package:analyzer/src/generated/engine.dart'; |
(...skipping 4073 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4084 a() { | 4084 a() { |
4085 print(1) | 4085 print(1) |
4086 } | 4086 } |
4087 b() { | 4087 b() { |
4088 foo(42); | 4088 foo(42); |
4089 } | 4089 } |
4090 foo(String p) {} | 4090 foo(String p) {} |
4091 '''); | 4091 '''); |
4092 } | 4092 } |
4093 | 4093 |
| 4094 void test_true_todoHint() { |
| 4095 _resolveUnit(r''' |
| 4096 main() { |
| 4097 print(1); |
| 4098 } |
| 4099 foo() { |
| 4100 // TODO |
| 4101 } |
| 4102 '''); |
| 4103 List<AnalysisError> oldErrors = analysisContext.computeErrors(source); |
| 4104 _updateAndValidate(r''' |
| 4105 main() { |
| 4106 print(2); |
| 4107 } |
| 4108 foo() { |
| 4109 // TODO |
| 4110 } |
| 4111 '''); |
| 4112 List<AnalysisError> newErrors = analysisContext.computeErrors(source); |
| 4113 _assertEqualErrors(newErrors, oldErrors); |
| 4114 } |
| 4115 |
4094 void test_true_wholeConstructor() { | 4116 void test_true_wholeConstructor() { |
4095 _resolveUnit(r''' | 4117 _resolveUnit(r''' |
4096 class A { | 4118 class A { |
4097 A(int a) { | 4119 A(int a) { |
4098 print(a); | 4120 print(a); |
4099 } | 4121 } |
4100 } | 4122 } |
4101 '''); | 4123 '''); |
4102 _updateAndValidate(r''' | 4124 _updateAndValidate(r''' |
4103 class A { | 4125 class A { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4161 '''); | 4183 '''); |
4162 _updateAndValidate(r''' | 4184 _updateAndValidate(r''' |
4163 class A { | 4185 class A { |
4164 main(int b) { | 4186 main(int b) { |
4165 print(b); | 4187 print(b); |
4166 } | 4188 } |
4167 } | 4189 } |
4168 '''); | 4190 '''); |
4169 } | 4191 } |
4170 | 4192 |
4171 void test_true_todoHint() { | |
4172 _resolveUnit(r''' | |
4173 main() { | |
4174 print(1); | |
4175 } | |
4176 foo() { | |
4177 // TODO | |
4178 } | |
4179 '''); | |
4180 List<AnalysisError> oldErrors = analysisContext.computeErrors(source); | |
4181 _updateAndValidate(r''' | |
4182 main() { | |
4183 print(2); | |
4184 } | |
4185 foo() { | |
4186 // TODO | |
4187 } | |
4188 '''); | |
4189 List<AnalysisError> newErrors = analysisContext.computeErrors(source); | |
4190 _assertEqualErrors(newErrors, oldErrors); | |
4191 } | |
4192 | |
4193 void test_unusedHint_add_wasUsedOnlyInPart() { | 4193 void test_unusedHint_add_wasUsedOnlyInPart() { |
4194 Source partSource = addNamedSource( | 4194 Source partSource = addNamedSource( |
4195 '/my_unit.dart', | 4195 '/my_unit.dart', |
4196 r''' | 4196 r''' |
4197 part of lib; | 4197 part of lib; |
4198 | 4198 |
4199 f(A a) { | 4199 f(A a) { |
4200 a._foo(); | 4200 a._foo(); |
4201 } | 4201 } |
4202 '''); | 4202 '''); |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4433 } | 4433 } |
4434 f2() { | 4434 f2() { |
4435 print(22); | 4435 print(22); |
4436 } | 4436 } |
4437 f3() { | 4437 f3() { |
4438 print(333) | 4438 print(333) |
4439 } | 4439 } |
4440 '''); | 4440 '''); |
4441 } | 4441 } |
4442 | 4442 |
| 4443 void test_whitespace_getElementAt() { |
| 4444 _resolveUnit(r''' |
| 4445 class A {} |
| 4446 class B extends A {} |
| 4447 '''); |
| 4448 { |
| 4449 ClassElement typeA = oldUnitElement.getType('A'); |
| 4450 expect(oldUnitElement.getElementAt(typeA.nameOffset), typeA); |
| 4451 } |
| 4452 { |
| 4453 ClassElement typeB = oldUnitElement.getType('B'); |
| 4454 expect(oldUnitElement.getElementAt(typeB.nameOffset), typeB); |
| 4455 } |
| 4456 _updateAndValidate(r''' |
| 4457 class A {} |
| 4458 |
| 4459 class B extends A {} |
| 4460 '''); |
| 4461 // getElementAt() caches results, it should be notificed it when offset |
| 4462 // are changed. |
| 4463 { |
| 4464 ClassElement typeA = oldUnitElement.getType('A'); |
| 4465 expect(oldUnitElement.getElementAt(typeA.nameOffset), typeA); |
| 4466 } |
| 4467 { |
| 4468 ClassElement typeB = oldUnitElement.getType('B'); |
| 4469 expect(oldUnitElement.getElementAt(typeB.nameOffset), typeB); |
| 4470 } |
| 4471 } |
| 4472 |
4443 void _assertEqualLineInfo(LineInfo incrLineInfo, LineInfo fullLineInfo) { | 4473 void _assertEqualLineInfo(LineInfo incrLineInfo, LineInfo fullLineInfo) { |
4444 for (int offset = 0; offset < 1000; offset++) { | 4474 for (int offset = 0; offset < 1000; offset++) { |
4445 LineInfo_Location incrLocation = incrLineInfo.getLocation(offset); | 4475 LineInfo_Location incrLocation = incrLineInfo.getLocation(offset); |
4446 LineInfo_Location fullLocation = fullLineInfo.getLocation(offset); | 4476 LineInfo_Location fullLocation = fullLineInfo.getLocation(offset); |
4447 if (incrLocation.lineNumber != fullLocation.lineNumber || | 4477 if (incrLocation.lineNumber != fullLocation.lineNumber || |
4448 incrLocation.columnNumber != fullLocation.columnNumber) { | 4478 incrLocation.columnNumber != fullLocation.columnNumber) { |
4449 fail('At offset $offset ' + | 4479 fail('At offset $offset ' + |
4450 '(${incrLocation.lineNumber}, ${incrLocation.columnNumber})' + | 4480 '(${incrLocation.lineNumber}, ${incrLocation.columnNumber})' + |
4451 ' != ' + | 4481 ' != ' + |
4452 '(${fullLocation.lineNumber}, ${fullLocation.columnNumber})'); | 4482 '(${fullLocation.lineNumber}, ${fullLocation.columnNumber})'); |
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4774 return ResolutionContextBuilder.contextFor(node, listener).scope; | 4804 return ResolutionContextBuilder.contextFor(node, listener).scope; |
4775 } | 4805 } |
4776 } | 4806 } |
4777 | 4807 |
4778 class _Edit { | 4808 class _Edit { |
4779 final int offset; | 4809 final int offset; |
4780 final int length; | 4810 final int length; |
4781 final String replacement; | 4811 final String replacement; |
4782 _Edit(this.offset, this.length, this.replacement); | 4812 _Edit(this.offset, this.length, this.replacement); |
4783 } | 4813 } |
OLD | NEW |