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

Side by Side Diff: pkg/analysis_server/test/services/refactoring/extract_local_test.dart

Issue 1528023002: Issue 25252. Stop collecting covering expressions at void invocations. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 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
« no previous file with comments | « pkg/analysis_server/lib/src/services/refactoring/extract_local.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.refactoring.extract_local; 5 library test.services.refactoring.extract_local;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:convert'; 8 import 'dart:convert';
9 9
10 import 'package:analysis_server/plugin/protocol/protocol.dart'; 10 import 'package:analysis_server/plugin/protocol/protocol.dart';
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 _createRefactoringForString("c'"); 143 _createRefactoringForString("c'");
144 // apply refactoring 144 // apply refactoring
145 return _assertSuccessfulRefactoring(''' 145 return _assertSuccessfulRefactoring('''
146 main() { 146 main() {
147 var res = 'abc'; 147 var res = 'abc';
148 var vvv = res; 148 var vvv = res;
149 } 149 }
150 '''); 150 ''');
151 } 151 }
152 152
153 test_checkInitialConditions_voidExpression() async {
154 indexTestUnit('''
155 main() {
156 print(42);
157 }
158 ''');
159 _createRefactoringForString('print');
160 // check conditions
161 RefactoringStatus status = await refactoring.checkInitialConditions();
162 assertRefactoringStatus(status, RefactoringProblemSeverity.FATAL,
163 expectedMessage: 'Cannot extract the void expression.');
164 }
165
153 test_checkLocalName() { 166 test_checkLocalName() {
154 indexTestUnit(''' 167 indexTestUnit('''
155 main() { 168 main() {
156 int a = 1 + 2; 169 int a = 1 + 2;
157 } 170 }
158 '''); 171 ''');
159 _createRefactoringForString('1 + 2'); 172 _createRefactoringForString('1 + 2');
160 expect(refactoring.refactoringName, 'Extract Local Variable'); 173 expect(refactoring.refactoringName, 'Extract Local Variable');
161 // null 174 // null
162 refactoring.name = null; 175 refactoring.name = null;
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 } 358 }
346 int foo(int x) => x; 359 int foo(int x) => x;
347 '''); 360 ''');
348 _createRefactoring(testCode.indexOf('11 +'), 0); 361 _createRefactoring(testCode.indexOf('11 +'), 0);
349 // check conditions 362 // check conditions
350 await refactoring.checkInitialConditions(); 363 await refactoring.checkInitialConditions();
351 List<String> subExpressions = _getCoveringExpressions(); 364 List<String> subExpressions = _getCoveringExpressions();
352 expect(subExpressions, ['111', '111 + 222', 'foo(111 + 222)']); 365 expect(subExpressions, ['111', '111 + 222', 'foo(111 + 222)']);
353 } 366 }
354 367
368 test_coveringExpressions_inInvocationOfVoidFunction() async {
369 indexTestUnit('''
370 main() {
371 foo(111 + 222);
372 }
373 void foo(int x) {}
374 ''');
375 _createRefactoring(testCode.indexOf('11 +'), 0);
376 // check conditions
377 await refactoring.checkInitialConditions();
378 List<String> subExpressions = _getCoveringExpressions();
379 expect(subExpressions, ['111', '111 + 222']);
380 }
381
355 test_coveringExpressions_skipAssignments() async { 382 test_coveringExpressions_skipAssignments() async {
356 indexTestUnit(''' 383 indexTestUnit('''
357 main() { 384 main() {
358 int v; 385 int v;
359 foo(v = 111 + 222); 386 foo(v = 111 + 222);
360 } 387 }
361 int foo(x) => 42; 388 int foo(x) => 42;
362 '''); 389 ''');
363 _createRefactoring(testCode.indexOf('11 +'), 0); 390 _createRefactoring(testCode.indexOf('11 +'), 0);
364 // check conditions 391 // check conditions
(...skipping 772 matching lines...) Expand 10 before | Expand all | Expand 10 after
1137 List<String> _getCoveringExpressions() { 1164 List<String> _getCoveringExpressions() {
1138 List<String> subExpressions = <String>[]; 1165 List<String> subExpressions = <String>[];
1139 for (int i = 0; i < refactoring.coveringExpressionOffsets.length; i++) { 1166 for (int i = 0; i < refactoring.coveringExpressionOffsets.length; i++) {
1140 int offset = refactoring.coveringExpressionOffsets[i]; 1167 int offset = refactoring.coveringExpressionOffsets[i];
1141 int length = refactoring.coveringExpressionLengths[i]; 1168 int length = refactoring.coveringExpressionLengths[i];
1142 subExpressions.add(testCode.substring(offset, offset + length)); 1169 subExpressions.add(testCode.substring(offset, offset + length));
1143 } 1170 }
1144 return subExpressions; 1171 return subExpressions;
1145 } 1172 }
1146 } 1173 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/services/refactoring/extract_local.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698