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

Side by Side Diff: pkg/analysis_server/test/services/correction/assist_test.dart

Issue 680133003: Issue 21458. Support for 'Add type' Quick Assist in for-each loops. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « pkg/analysis_server/test/mock_sdk.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) 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 test.services.correction.assist; 5 library test.services.correction.assist;
6 6
7 import 'package:analysis_server/src/protocol.dart'; 7 import 'package:analysis_server/src/protocol.dart';
8 import 'package:analysis_server/src/services/correction/assist.dart'; 8 import 'package:analysis_server/src/services/correction/assist.dart';
9 import 'package:analysis_server/src/services/index/index.dart'; 9 import 'package:analysis_server/src/services/index/index.dart';
10 import 'package:analysis_server/src/services/index/local_memory_index.dart'; 10 import 'package:analysis_server/src/services/index/local_memory_index.dart';
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 var f = 0; 126 var f = 0;
127 } 127 }
128 '''); 128 ''');
129 assertHasAssistAt('var ', AssistKind.ADD_TYPE_ANNOTATION, ''' 129 assertHasAssistAt('var ', AssistKind.ADD_TYPE_ANNOTATION, '''
130 class A { 130 class A {
131 int f = 0; 131 int f = 0;
132 } 132 }
133 '''); 133 ''');
134 } 134 }
135 135
136 void test_addTypeAnnotation_declaredIdentifier_BAD_hasTypeAnnotation() {
137 _indexTestUnit('''
138 main(List<String> items) {
139 for (String item in items) {
140 }
141 }
142 ''');
143 assertNoAssistAt('item in', AssistKind.ADD_TYPE_ANNOTATION);
144 }
145
146 void test_addTypeAnnotation_declaredIdentifier_BAD_inForEachBody() {
147 _indexTestUnit('''
148 main(List<String> items) {
149 for (var item in items) {
150 int fooBar;
Paul Berry 2014/10/29 20:56:23 Can we change this to "var fooBar;"? As written t
scheglov 2014/10/29 20:59:27 Done.
151 }
152 }
153 ''');
154 assertNoAssistAt('fooBar', AssistKind.ADD_TYPE_ANNOTATION);
155 }
156
157 void test_addTypeAnnotation_declaredIdentifier_BAD_unknownType() {
158 verifyNoTestUnitErrors = false;
159 _indexTestUnit('''
160 main() {
161 for (var item in unknownList) {
162 }
163 }
164 ''');
165 assertNoAssistAt('item in', AssistKind.ADD_TYPE_ANNOTATION);
166 }
167
168 void test_addTypeAnnotation_declaredIdentifier_OK() {
169 _indexTestUnit('''
170 main(List<String> items) {
171 for (var item in items) {
172 }
173 }
174 ''');
175 // on identifier
176 assertHasAssistAt('item in', AssistKind.ADD_TYPE_ANNOTATION, '''
177 main(List<String> items) {
178 for (String item in items) {
179 }
180 }
181 ''');
182 // on "for"
183 assertHasAssistAt('for (', AssistKind.ADD_TYPE_ANNOTATION, '''
184 main(List<String> items) {
185 for (String item in items) {
186 }
187 }
188 ''');
189 }
190
191 void test_addTypeAnnotation_declaredIdentifier_OK_final() {
192 _indexTestUnit('''
193 main(List<String> items) {
194 for (final item in items) {
195 }
196 }
197 ''');
198 assertHasAssistAt('item in', AssistKind.ADD_TYPE_ANNOTATION, '''
199 main(List<String> items) {
200 for (final String item in items) {
201 }
202 }
203 ''');
204 }
205
136 void test_addTypeAnnotation_local_OK_Function() { 206 void test_addTypeAnnotation_local_OK_Function() {
137 _indexTestUnit(''' 207 _indexTestUnit('''
138 main() { 208 main() {
139 var v = () => 1; 209 var v = () => 1;
140 } 210 }
141 '''); 211 ''');
142 assertHasAssistAt('v =', AssistKind.ADD_TYPE_ANNOTATION, ''' 212 assertHasAssistAt('v =', AssistKind.ADD_TYPE_ANNOTATION, '''
143 main() { 213 main() {
144 Function v = () => 1; 214 Function v = () => 1;
145 } 215 }
(...skipping 2204 matching lines...) Expand 10 before | Expand all | Expand 10 after
2350 void _indexTestUnit(String code) { 2420 void _indexTestUnit(String code) {
2351 resolveTestUnit(code); 2421 resolveTestUnit(code);
2352 index.indexUnit(context, testUnit); 2422 index.indexUnit(context, testUnit);
2353 } 2423 }
2354 2424
2355 void _setStartEndSelection() { 2425 void _setStartEndSelection() {
2356 offset = findOffset('// start\n') + '// start\n'.length; 2426 offset = findOffset('// start\n') + '// start\n'.length;
2357 length = findOffset('// end') - offset; 2427 length = findOffset('// end') - offset;
2358 } 2428 }
2359 } 2429 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/test/mock_sdk.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698