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

Side by Side Diff: pkg/analysis_server/test/services/completion/keyword_contributor_test.dart

Issue 1271723002: fix completion replacement offset/length for invalid token in switch statement (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: merge and address comments Created 5 years, 4 months 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
« no previous file with comments | « pkg/analysis_server/test/services/completion/completion_target_test.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.completion.dart.keyword; 5 library test.services.completion.dart.keyword;
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/completion/dart_completion_manager. dart'; 8 import 'package:analysis_server/src/services/completion/dart_completion_manager. dart';
9 import 'package:analysis_server/src/services/completion/keyword_contributor.dart '; 9 import 'package:analysis_server/src/services/completion/keyword_contributor.dart ';
10 import 'package:analyzer/src/generated/scanner.dart'; 10 import 'package:analyzer/src/generated/scanner.dart';
(...skipping 1110 matching lines...) Expand 10 before | Expand all | Expand 10 after
1121 relevance: DART_RELEVANCE_HIGH); 1121 relevance: DART_RELEVANCE_HIGH);
1122 } 1122 }
1123 1123
1124 test_switch_start4() { 1124 test_switch_start4() {
1125 addTestSource('main() {switch(1) {^ default:}}'); 1125 addTestSource('main() {switch(1) {^ default:}}');
1126 expect(computeFast(), isTrue); 1126 expect(computeFast(), isTrue);
1127 assertSuggestKeywords([Keyword.CASE, Keyword.DEFAULT], 1127 assertSuggestKeywords([Keyword.CASE, Keyword.DEFAULT],
1128 relevance: DART_RELEVANCE_HIGH); 1128 relevance: DART_RELEVANCE_HIGH);
1129 } 1129 }
1130 1130
1131 test_switch_start5() {
1132 addTestSource('main() {switch(1) {c^ default:}}');
1133 expect(computeFast(), isTrue);
1134 assertSuggestKeywords([Keyword.CASE, Keyword.DEFAULT],
1135 relevance: DART_RELEVANCE_HIGH);
1136 expect(request.replacementOffset, 19);
1137 expect(request.replacementLength, 1);
1138 }
1139
1140 test_switch_start6() {
1141 addTestSource('main() {switch(1) {c^}}');
1142 expect(computeFast(), isTrue);
1143 assertSuggestKeywords([Keyword.CASE, Keyword.DEFAULT],
1144 relevance: DART_RELEVANCE_HIGH);
1145 expect(request.replacementOffset, 19);
1146 expect(request.replacementLength, 1);
1147 }
1148
1149 test_switch_start7() {
1150 addTestSource('main() {switch(1) { c^ }}');
1151 expect(computeFast(), isTrue);
1152 assertSuggestKeywords([Keyword.CASE, Keyword.DEFAULT],
1153 relevance: DART_RELEVANCE_HIGH);
1154 expect(request.replacementOffset, 20);
1155 expect(request.replacementLength, 1);
1156 }
1157
1131 test_switch_statement() { 1158 test_switch_statement() {
1132 addTestSource('main() {switch(1) {case 1:^}}'); 1159 addTestSource('main() {switch(1) {case 1:^}}');
1133 expect(computeFast(), isTrue); 1160 expect(computeFast(), isTrue);
1134 assertSuggestKeywords(STMT_START_IN_SWITCH_OUTSIDE_CLASS); 1161 assertSuggestKeywords(STMT_START_IN_SWITCH_OUTSIDE_CLASS);
1135 } 1162 }
1136 1163
1137 test_switch_statement2() { 1164 test_switch_statement2() {
1138 addTestSource('class A{foo() {switch(1) {case 1:^}}}'); 1165 addTestSource('class A{foo() {switch(1) {case 1:^}}}');
1139 expect(computeFast(), isTrue); 1166 expect(computeFast(), isTrue);
1140 assertSuggestKeywords(STMT_START_IN_SWITCH_IN_CLASS); 1167 assertSuggestKeywords(STMT_START_IN_SWITCH_IN_CLASS);
1141 } 1168 }
1142 1169
1143 void _appendCompletions( 1170 void _appendCompletions(
1144 StringBuffer msg, Iterable<String> completions, Iterable<String> other) { 1171 StringBuffer msg, Iterable<String> completions, Iterable<String> other) {
1145 List<String> sorted = completions.toList(); 1172 List<String> sorted = completions.toList();
1146 sorted.sort((c1, c2) => c1.compareTo(c2)); 1173 sorted.sort((c1, c2) => c1.compareTo(c2));
1147 sorted.forEach( 1174 sorted.forEach(
1148 (c) => msg.writeln(' $c, ${other.contains(c) ? '' : '<<<<<<<<<<<'}')); 1175 (c) => msg.writeln(' $c, ${other.contains(c) ? '' : '<<<<<<<<<<<'}'));
1149 } 1176 }
1150 1177
1151 bool _equalSets(Iterable<String> iter1, Iterable<String> iter2) { 1178 bool _equalSets(Iterable<String> iter1, Iterable<String> iter2) {
1152 if (iter1.length != iter2.length) return false; 1179 if (iter1.length != iter2.length) return false;
1153 if (iter1.any((c) => !iter2.contains(c))) return false; 1180 if (iter1.any((c) => !iter2.contains(c))) return false;
1154 if (iter2.any((c) => !iter1.contains(c))) return false; 1181 if (iter2.any((c) => !iter1.contains(c))) return false;
1155 return true; 1182 return true;
1156 } 1183 }
1157 } 1184 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/test/services/completion/completion_target_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698