| 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 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 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 } | 196 } |
| 197 '''); | 197 '''); |
| 198 assertHasAssistAt('item in', AssistKind.ADD_TYPE_ANNOTATION, ''' | 198 assertHasAssistAt('item in', AssistKind.ADD_TYPE_ANNOTATION, ''' |
| 199 main(List<String> items) { | 199 main(List<String> items) { |
| 200 for (final String item in items) { | 200 for (final String item in items) { |
| 201 } | 201 } |
| 202 } | 202 } |
| 203 '''); | 203 '''); |
| 204 } | 204 } |
| 205 | 205 |
| 206 void test_addTypeAnnotation_local_OK_onVariableDeclarationStatement() { | |
| 207 _indexTestUnit(''' | |
| 208 main() { | |
| 209 var v = 123; // marker | |
| 210 } | |
| 211 '''); | |
| 212 assertHasAssistAt(' // marker', AssistKind.ADD_TYPE_ANNOTATION, ''' | |
| 213 main() { | |
| 214 int v = 123; // marker | |
| 215 } | |
| 216 '''); | |
| 217 } | |
| 218 | |
| 219 void test_addTypeAnnotation_local_OK_Function() { | 206 void test_addTypeAnnotation_local_OK_Function() { |
| 220 _indexTestUnit(''' | 207 _indexTestUnit(''' |
| 221 main() { | 208 main() { |
| 222 var v = () => 1; | 209 var v = () => 1; |
| 223 } | 210 } |
| 224 '''); | 211 '''); |
| 225 assertHasAssistAt('v =', AssistKind.ADD_TYPE_ANNOTATION, ''' | 212 assertHasAssistAt('v =', AssistKind.ADD_TYPE_ANNOTATION, ''' |
| 226 main() { | 213 main() { |
| 227 Function v = () => 1; | 214 Function v = () => 1; |
| 228 } | 215 } |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 var v = 0; | 274 var v = 0; |
| 288 } | 275 } |
| 289 '''); | 276 '''); |
| 290 assertHasAssistAt('var ', AssistKind.ADD_TYPE_ANNOTATION, ''' | 277 assertHasAssistAt('var ', AssistKind.ADD_TYPE_ANNOTATION, ''' |
| 291 main() { | 278 main() { |
| 292 int v = 0; | 279 int v = 0; |
| 293 } | 280 } |
| 294 '''); | 281 '''); |
| 295 } | 282 } |
| 296 | 283 |
| 284 void test_addTypeAnnotation_local_OK_onVariableDeclarationStatement() { |
| 285 _indexTestUnit(''' |
| 286 main() { |
| 287 var v = 123; // marker |
| 288 } |
| 289 '''); |
| 290 assertHasAssistAt(' // marker', AssistKind.ADD_TYPE_ANNOTATION, ''' |
| 291 main() { |
| 292 int v = 123; // marker |
| 293 } |
| 294 '''); |
| 295 } |
| 296 |
| 297 void test_addTypeAnnotation_local_wrong_hasTypeAnnotation() { | 297 void test_addTypeAnnotation_local_wrong_hasTypeAnnotation() { |
| 298 _indexTestUnit(''' | 298 _indexTestUnit(''' |
| 299 main() { | 299 main() { |
| 300 int v = 42; | 300 int v = 42; |
| 301 } | 301 } |
| 302 '''); | 302 '''); |
| 303 assertNoAssistAt(' = 42', AssistKind.ADD_TYPE_ANNOTATION); | 303 assertNoAssistAt(' = 42', AssistKind.ADD_TYPE_ANNOTATION); |
| 304 } | 304 } |
| 305 | 305 |
| 306 void test_addTypeAnnotation_local_wrong_multiple() { | 306 void test_addTypeAnnotation_local_wrong_multiple() { |
| (...skipping 1666 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1973 assertHasAssistAt( | 1973 assertHasAssistAt( |
| 1974 'if (true)', | 1974 'if (true)', |
| 1975 AssistKind.REPLACE_IF_ELSE_WITH_CONDITIONAL, | 1975 AssistKind.REPLACE_IF_ELSE_WITH_CONDITIONAL, |
| 1976 ''' | 1976 ''' |
| 1977 main() { | 1977 main() { |
| 1978 return true ? 111 : 222; | 1978 return true ? 111 : 222; |
| 1979 } | 1979 } |
| 1980 '''); | 1980 '''); |
| 1981 } | 1981 } |
| 1982 | 1982 |
| 1983 void test_replaceIfElseWithConditional_wrong_expressionVsReturn() { |
| 1984 _indexTestUnit(''' |
| 1985 main() { |
| 1986 if (true) { |
| 1987 print(42); |
| 1988 } else { |
| 1989 return; |
| 1990 } |
| 1991 } |
| 1992 '''); |
| 1993 assertNoAssistAt('else', AssistKind.REPLACE_IF_ELSE_WITH_CONDITIONAL); |
| 1994 } |
| 1995 |
| 1983 void test_replaceIfElseWithConditional_wrong_notIfStatement() { | 1996 void test_replaceIfElseWithConditional_wrong_notIfStatement() { |
| 1984 _indexTestUnit(''' | 1997 _indexTestUnit(''' |
| 1985 main() { | 1998 main() { |
| 1986 print(0); | 1999 print(0); |
| 1987 } | 2000 } |
| 1988 '''); | 2001 '''); |
| 1989 assertNoAssistAt('print', AssistKind.REPLACE_IF_ELSE_WITH_CONDITIONAL); | 2002 assertNoAssistAt('print', AssistKind.REPLACE_IF_ELSE_WITH_CONDITIONAL); |
| 1990 } | 2003 } |
| 1991 | 2004 |
| 1992 void test_replaceIfElseWithConditional_wrong_notSingleStatememt() { | 2005 void test_replaceIfElseWithConditional_wrong_notSingleStatememt() { |
| (...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2433 void _indexTestUnit(String code) { | 2446 void _indexTestUnit(String code) { |
| 2434 resolveTestUnit(code); | 2447 resolveTestUnit(code); |
| 2435 index.indexUnit(context, testUnit); | 2448 index.indexUnit(context, testUnit); |
| 2436 } | 2449 } |
| 2437 | 2450 |
| 2438 void _setStartEndSelection() { | 2451 void _setStartEndSelection() { |
| 2439 offset = findOffset('// start\n') + '// start\n'.length; | 2452 offset = findOffset('// start\n') + '// start\n'.length; |
| 2440 length = findOffset('// end') - offset; | 2453 length = findOffset('// end') - offset; |
| 2441 } | 2454 } |
| 2442 } | 2455 } |
| OLD | NEW |