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

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

Issue 1522193002: Issue 25251. Fix for extracting string literal part with zero length. (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/test/edit/refactoring_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.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 942 matching lines...) Expand 10 before | Expand all | Expand 10 after
953 _createRefactoringForString('1 + 2'); 953 _createRefactoringForString('1 + 2');
954 // apply refactoring 954 // apply refactoring
955 return _assertSuccessfulRefactoring(''' 955 return _assertSuccessfulRefactoring('''
956 main() { 956 main() {
957 var res = 1 + 2; 957 var res = 1 + 2;
958 int a = res + 3 + 4; 958 int a = res + 3 + 4;
959 } 959 }
960 '''); 960 ''');
961 } 961 }
962 962
963 test_singleExpression_string() {
964 indexTestUnit('''
965 void main() {
966 print("1234");
967 }
968 ''');
969 _createRefactoringAtString('34"');
970 // apply refactoring
971 return _assertSuccessfulRefactoring('''
972 void main() {
973 var res = "1234";
974 print(res);
975 }
976 ''');
977 }
978
963 test_singleExpression_trailingNotWhitespace() { 979 test_singleExpression_trailingNotWhitespace() {
964 indexTestUnit(''' 980 indexTestUnit('''
965 main() { 981 main() {
966 int a = 12 + 345; 982 int a = 12 + 345;
967 } 983 }
968 '''); 984 ''');
969 _createRefactoringForString('12 +'); 985 _createRefactoringForString('12 +');
970 // apply refactoring 986 // apply refactoring
971 return _assertSuccessfulRefactoring(''' 987 return _assertSuccessfulRefactoring('''
972 main() { 988 main() {
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
1086 this.refactoringChange = refactoringChange; 1102 this.refactoringChange = refactoringChange;
1087 assertTestChangeResult(expectedCode); 1103 assertTestChangeResult(expectedCode);
1088 } 1104 }
1089 1105
1090 void _createRefactoring(int offset, int length) { 1106 void _createRefactoring(int offset, int length) {
1091 refactoring = new ExtractLocalRefactoring(testUnit, offset, length); 1107 refactoring = new ExtractLocalRefactoring(testUnit, offset, length);
1092 refactoring.name = 'res'; 1108 refactoring.name = 'res';
1093 } 1109 }
1094 1110
1095 /** 1111 /**
1112 * Creates a new refactoring in [refactoring] at the offset of the given
1113 * [search] pattern, and with the length `0`.
1114 */
1115 void _createRefactoringAtString(String search) {
1116 int offset = findOffset(search);
1117 int length = 0;
1118 _createRefactoring(offset, length);
1119 }
1120
1121 /**
1096 * Creates a new refactoring in [refactoring] for the selection range of the 1122 * Creates a new refactoring in [refactoring] for the selection range of the
1097 * given [search] pattern. 1123 * given [search] pattern.
1098 */ 1124 */
1099 void _createRefactoringForString(String search) { 1125 void _createRefactoringForString(String search) {
1100 int offset = findOffset(search); 1126 int offset = findOffset(search);
1101 int length = search.length; 1127 int length = search.length;
1102 _createRefactoring(offset, length); 1128 _createRefactoring(offset, length);
1103 } 1129 }
1104 1130
1105 void _createRefactoringWithSuffix(String selectionSearch, String suffix) { 1131 void _createRefactoringWithSuffix(String selectionSearch, String suffix) {
1106 int offset = findOffset(selectionSearch + suffix); 1132 int offset = findOffset(selectionSearch + suffix);
1107 int length = selectionSearch.length; 1133 int length = selectionSearch.length;
1108 _createRefactoring(offset, length); 1134 _createRefactoring(offset, length);
1109 } 1135 }
1110 1136
1111 List<String> _getCoveringExpressions() { 1137 List<String> _getCoveringExpressions() {
1112 List<String> subExpressions = <String>[]; 1138 List<String> subExpressions = <String>[];
1113 for (int i = 0; i < refactoring.coveringExpressionOffsets.length; i++) { 1139 for (int i = 0; i < refactoring.coveringExpressionOffsets.length; i++) {
1114 int offset = refactoring.coveringExpressionOffsets[i]; 1140 int offset = refactoring.coveringExpressionOffsets[i];
1115 int length = refactoring.coveringExpressionLengths[i]; 1141 int length = refactoring.coveringExpressionLengths[i];
1116 subExpressions.add(testCode.substring(offset, offset + length)); 1142 subExpressions.add(testCode.substring(offset, offset + length));
1117 } 1143 }
1118 return subExpressions; 1144 return subExpressions;
1119 } 1145 }
1120 } 1146 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/test/edit/refactoring_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698