| 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 886 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 897 void test_importAddShow_BAD_hasShow() { | 897 void test_importAddShow_BAD_hasShow() { |
| 898 _indexTestUnit(''' | 898 _indexTestUnit(''' |
| 899 import 'dart:math' show PI; | 899 import 'dart:math' show PI; |
| 900 main() { | 900 main() { |
| 901 PI; | 901 PI; |
| 902 } | 902 } |
| 903 '''); | 903 '''); |
| 904 assertNoAssistAt('import ', AssistKind.IMPORT_ADD_SHOW); | 904 assertNoAssistAt('import ', AssistKind.IMPORT_ADD_SHOW); |
| 905 } | 905 } |
| 906 | 906 |
| 907 void test_importAddShow_BAD_unresolvedUri() { |
| 908 _indexTestUnit(''' |
| 909 import '/no/such/lib.dart'; |
| 910 '''); |
| 911 assertNoAssistAt('import ', AssistKind.IMPORT_ADD_SHOW); |
| 912 } |
| 913 |
| 907 void test_importAddShow_BAD_unused() { | 914 void test_importAddShow_BAD_unused() { |
| 908 _indexTestUnit(''' | 915 _indexTestUnit(''' |
| 909 import 'dart:math'; | 916 import 'dart:math'; |
| 910 '''); | 917 '''); |
| 911 assertNoAssistAt('import ', AssistKind.IMPORT_ADD_SHOW); | 918 assertNoAssistAt('import ', AssistKind.IMPORT_ADD_SHOW); |
| 912 } | 919 } |
| 913 | |
| 914 void test_importAddShow_BAD_unresolvedUri() { | |
| 915 _indexTestUnit(''' | |
| 916 import '/no/such/lib.dart'; | |
| 917 '''); | |
| 918 assertNoAssistAt('import ', AssistKind.IMPORT_ADD_SHOW); | |
| 919 } | |
| 920 | 920 |
| 921 void test_importAddShow_OK_hasUnresolvedIdentifier() { | 921 void test_importAddShow_OK_hasUnresolvedIdentifier() { |
| 922 _indexTestUnit(''' | 922 _indexTestUnit(''' |
| 923 import 'dart:math'; | 923 import 'dart:math'; |
| 924 main(x) { | 924 main(x) { |
| 925 PI; | 925 PI; |
| 926 return x.foo(); | 926 return x.foo(); |
| 927 } | 927 } |
| 928 '''); | 928 '''); |
| 929 assertHasAssistAt('import ', AssistKind.IMPORT_ADD_SHOW, ''' | 929 assertHasAssistAt('import ', AssistKind.IMPORT_ADD_SHOW, ''' |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 966 assertHasAssistAt('art:math', AssistKind.IMPORT_ADD_SHOW, ''' | 966 assertHasAssistAt('art:math', AssistKind.IMPORT_ADD_SHOW, ''' |
| 967 import 'dart:math' show E, PI, max; | 967 import 'dart:math' show E, PI, max; |
| 968 main() { | 968 main() { |
| 969 PI; | 969 PI; |
| 970 E; | 970 E; |
| 971 max(1, 2); | 971 max(1, 2); |
| 972 } | 972 } |
| 973 '''); | 973 '''); |
| 974 } | 974 } |
| 975 | 975 |
| 976 void test_introduceLocalCastType_BAD_notBlock() { |
| 977 _indexTestUnit(''' |
| 978 main(p) { |
| 979 if (p is String) |
| 980 print('not a block'); |
| 981 } |
| 982 '''); |
| 983 assertNoAssistAt('if (p', AssistKind.INTRODUCE_LOCAL_CAST_TYPE); |
| 984 } |
| 985 |
| 986 void test_introduceLocalCastType_BAD_notIsExpression() { |
| 987 _indexTestUnit(''' |
| 988 main(p) { |
| 989 if (p == null) { |
| 990 } |
| 991 } |
| 992 '''); |
| 993 assertNoAssistAt('if (p', AssistKind.INTRODUCE_LOCAL_CAST_TYPE); |
| 994 } |
| 995 |
| 996 void test_introduceLocalCastType_OK_if() { |
| 997 _indexTestUnit(''' |
| 998 class MyTypeName {} |
| 999 main(p) { |
| 1000 if (p is MyTypeName) { |
| 1001 } |
| 1002 p = null; |
| 1003 } |
| 1004 '''); |
| 1005 String expected = ''' |
| 1006 class MyTypeName {} |
| 1007 main(p) { |
| 1008 if (p is MyTypeName) { |
| 1009 MyTypeName myTypeName = p; |
| 1010 } |
| 1011 p = null; |
| 1012 } |
| 1013 '''; |
| 1014 assertHasAssistAt( |
| 1015 'is MyType', |
| 1016 AssistKind.INTRODUCE_LOCAL_CAST_TYPE, |
| 1017 expected); |
| 1018 _assertLinkedGroup( |
| 1019 change.linkedEditGroups[0], |
| 1020 ['myTypeName = '], |
| 1021 expectedSuggestions( |
| 1022 LinkedEditSuggestionKind.VARIABLE, |
| 1023 ['myTypeName', 'typeName', 'name'])); |
| 1024 // another good location |
| 1025 assertHasAssistAt('if (p', AssistKind.INTRODUCE_LOCAL_CAST_TYPE, expected); |
| 1026 } |
| 1027 |
| 1028 void test_introduceLocalCastType_OK_while() { |
| 1029 _indexTestUnit(''' |
| 1030 main(p) { |
| 1031 while (p is String) { |
| 1032 } |
| 1033 p = null; |
| 1034 } |
| 1035 '''); |
| 1036 String expected = ''' |
| 1037 main(p) { |
| 1038 while (p is String) { |
| 1039 String s = p; |
| 1040 } |
| 1041 p = null; |
| 1042 } |
| 1043 '''; |
| 1044 assertHasAssistAt( |
| 1045 'is String', |
| 1046 AssistKind.INTRODUCE_LOCAL_CAST_TYPE, |
| 1047 expected); |
| 1048 assertHasAssistAt( |
| 1049 'while (p', |
| 1050 AssistKind.INTRODUCE_LOCAL_CAST_TYPE, |
| 1051 expected); |
| 1052 } |
| 1053 |
| 976 void test_invertIfStatement_blocks() { | 1054 void test_invertIfStatement_blocks() { |
| 977 _indexTestUnit(''' | 1055 _indexTestUnit(''' |
| 978 main() { | 1056 main() { |
| 979 if (true) { | 1057 if (true) { |
| 980 0; | 1058 0; |
| 981 } else { | 1059 } else { |
| 982 1; | 1060 1; |
| 983 } | 1061 } |
| 984 } | 1062 } |
| 985 '''); | 1063 '''); |
| (...skipping 1256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2242 void _indexTestUnit(String code) { | 2320 void _indexTestUnit(String code) { |
| 2243 resolveTestUnit(code); | 2321 resolveTestUnit(code); |
| 2244 index.indexUnit(context, testUnit); | 2322 index.indexUnit(context, testUnit); |
| 2245 } | 2323 } |
| 2246 | 2324 |
| 2247 void _setStartEndSelection() { | 2325 void _setStartEndSelection() { |
| 2248 offset = findOffset('// start\n') + '// start\n'.length; | 2326 offset = findOffset('// start\n') + '// start\n'.length; |
| 2249 length = findOffset('// end') - offset; | 2327 length = findOffset('// end') - offset; |
| 2250 } | 2328 } |
| 2251 } | 2329 } |
| OLD | NEW |