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

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

Issue 805053003: Disable 'Split && condition' if there is an 'else' statement. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years 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/lib/src/services/correction/assist_internal.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 2202 matching lines...) Expand 10 before | Expand all | Expand 10 after
2213 print(0); 2213 print(0);
2214 if (3 == 3) { 2214 if (3 == 3) {
2215 print(1); 2215 print(1);
2216 } 2216 }
2217 } 2217 }
2218 } 2218 }
2219 } 2219 }
2220 '''); 2220 ''');
2221 } 2221 }
2222 2222
2223 void test_splitAndCondition_OK_thenBlock_elseBlock() {
2224 _indexTestUnit('''
2225 main() {
2226 if (true && false) {
2227 print(0);
2228 } else {
2229 print(1);
2230 if (2 == 2) {
2231 print(2);
2232 }
2233 }
2234 }
2235 ''');
2236 assertHasAssistAt('&& false', AssistKind.SPLIT_AND_CONDITION, '''
2237 main() {
2238 if (true) {
2239 if (false) {
2240 print(0);
2241 } else {
2242 print(1);
2243 if (2 == 2) {
2244 print(2);
2245 }
2246 }
2247 }
2248 }
2249 ''');
2250 }
2251
2252 void test_splitAndCondition_OK_thenStatement() { 2223 void test_splitAndCondition_OK_thenStatement() {
2253 _indexTestUnit(''' 2224 _indexTestUnit('''
2254 main() { 2225 main() {
2255 if (true && false) 2226 if (true && false)
2256 print(0); 2227 print(0);
2257 } 2228 }
2258 '''); 2229 ''');
2259 assertHasAssistAt('&& false', AssistKind.SPLIT_AND_CONDITION, ''' 2230 assertHasAssistAt('&& false', AssistKind.SPLIT_AND_CONDITION, '''
2260 main() { 2231 main() {
2261 if (true) 2232 if (true)
2262 if (false) 2233 if (false)
2263 print(0); 2234 print(0);
2264 } 2235 }
2265 '''); 2236 ''');
2266 } 2237 }
2267 2238
2268 void test_splitAndCondition_OK_thenStatement_elseStatement() {
2269 _indexTestUnit('''
2270 main() {
2271 if (true && false)
2272 print(0);
2273 else
2274 print(1);
2275 }
2276 ''');
2277 assertHasAssistAt('&& false', AssistKind.SPLIT_AND_CONDITION, '''
2278 main() {
2279 if (true)
2280 if (false)
2281 print(0);
2282 else
2283 print(1);
2284 }
2285 ''');
2286 }
2287
2288 void test_splitAndCondition_wrong() { 2239 void test_splitAndCondition_wrong() {
2289 _indexTestUnit(''' 2240 _indexTestUnit('''
2290 main() { 2241 main() {
2291 if (1 == 1 && 2 == 2) { 2242 if (1 == 1 && 2 == 2) {
2292 print(0); 2243 print(0);
2293 } 2244 }
2294 print(3 == 3 && 4 == 4); 2245 print(3 == 3 && 4 == 4);
2295 } 2246 }
2296 '''); 2247 ''');
2297 // not binary expression 2248 // not binary expression
2298 assertNoAssistAt('main() {', AssistKind.SPLIT_AND_CONDITION); 2249 assertNoAssistAt('main() {', AssistKind.SPLIT_AND_CONDITION);
2299 // selection is not empty and includes more than just operator 2250 // selection is not empty and includes more than just operator
2300 { 2251 {
2301 length = 5; 2252 length = 5;
2302 assertNoAssistAt('&& 2 == 2', AssistKind.SPLIT_AND_CONDITION); 2253 assertNoAssistAt('&& 2 == 2', AssistKind.SPLIT_AND_CONDITION);
2303 } 2254 }
2304 } 2255 }
2305 2256
2306 void test_splitAndCondition_wrong_notAnd() { 2257 void test_splitAndCondition_wrong_notAnd() {
2307 _indexTestUnit(''' 2258 _indexTestUnit('''
2308 main() { 2259 main() {
2309 if (1 == 1 || 2 == 2) { 2260 if (1 == 1 || 2 == 2) {
2310 print(0); 2261 print(0);
2311 } 2262 }
2312 } 2263 }
2313 '''); 2264 ''');
2314 assertNoAssistAt('|| 2', AssistKind.SPLIT_AND_CONDITION); 2265 assertNoAssistAt('|| 2', AssistKind.SPLIT_AND_CONDITION);
2315 } 2266 }
2316 2267
2268 void test_splitAndCondition_wrong_hasElse() {
2269 _indexTestUnit('''
2270 main() {
2271 if (1 == 1 && 2 == 2) {
2272 print(1);
2273 } else {
2274 print(2);
2275 }
2276 }
2277 ''');
2278 assertNoAssistAt('&& 2', AssistKind.SPLIT_AND_CONDITION);
2279 }
2280
2317 void test_splitAndCondition_wrong_notPartOfIf() { 2281 void test_splitAndCondition_wrong_notPartOfIf() {
2318 _indexTestUnit(''' 2282 _indexTestUnit('''
2319 main() { 2283 main() {
2320 print(1 == 1 && 2 == 2); 2284 print(1 == 1 && 2 == 2);
2321 } 2285 }
2322 '''); 2286 ''');
2323 assertNoAssistAt('&& 2', AssistKind.SPLIT_AND_CONDITION); 2287 assertNoAssistAt('&& 2', AssistKind.SPLIT_AND_CONDITION);
2324 } 2288 }
2325 2289
2326 void test_splitAndCondition_wrong_notTopLevelAnd() { 2290 void test_splitAndCondition_wrong_notTopLevelAnd() {
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
2604 void _indexTestUnit(String code) { 2568 void _indexTestUnit(String code) {
2605 resolveTestUnit(code); 2569 resolveTestUnit(code);
2606 index.indexUnit(context, testUnit); 2570 index.indexUnit(context, testUnit);
2607 } 2571 }
2608 2572
2609 void _setStartEndSelection() { 2573 void _setStartEndSelection() {
2610 offset = findOffset('// start\n') + '// start\n'.length; 2574 offset = findOffset('// start\n') + '// start\n'.length;
2611 length = findOffset('// end') - offset; 2575 length = findOffset('// end') - offset;
2612 } 2576 }
2613 } 2577 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/services/correction/assist_internal.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698