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.fix; | 5 library test.services.correction.fix; |
6 | 6 |
7 import 'package:analysis_server/edit/fix/fix_core.dart'; | 7 import 'package:analysis_server/edit/fix/fix_core.dart'; |
8 import 'package:analysis_server/src/protocol.dart' hide AnalysisError; | 8 import 'package:analysis_server/src/protocol.dart' hide AnalysisError; |
9 import 'package:analysis_server/src/services/correction/fix.dart'; | 9 import 'package:analysis_server/src/services/correction/fix.dart'; |
10 import 'package:analysis_server/src/services/correction/fix_internal.dart'; | 10 import 'package:analysis_server/src/services/correction/fix_internal.dart'; |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 assertHasFix(DartFixKind.ADD_FIELD_FORMAL_PARAMETERS, ''' | 155 assertHasFix(DartFixKind.ADD_FIELD_FORMAL_PARAMETERS, ''' |
156 class Test { | 156 class Test { |
157 final int a; | 157 final int a; |
158 final int b; | 158 final int b; |
159 final int c; | 159 final int c; |
160 Test(this.a, this.b, [this.c]); | 160 Test(this.a, this.b, [this.c]); |
161 } | 161 } |
162 '''); | 162 '''); |
163 } | 163 } |
164 | 164 |
| 165 void test_addMissingParameter_function_positional_hasZero() { |
| 166 resolveTestUnit(''' |
| 167 test() {} |
| 168 main() { |
| 169 test(1); |
| 170 } |
| 171 '''); |
| 172 assertHasFix(DartFixKind.ADD_MISSING_PARAMETER_POSITIONAL, ''' |
| 173 test([int i]) {} |
| 174 main() { |
| 175 test(1); |
| 176 } |
| 177 '''); |
| 178 } |
| 179 |
| 180 void test_addMissingParameter_function_required_hasOne() { |
| 181 resolveTestUnit(''' |
| 182 test(int a) {} |
| 183 main() { |
| 184 test(1, 2.0); |
| 185 } |
| 186 '''); |
| 187 assertHasFix(DartFixKind.ADD_MISSING_PARAMETER_REQUIRED, ''' |
| 188 test(int a, double d) {} |
| 189 main() { |
| 190 test(1, 2.0); |
| 191 } |
| 192 '''); |
| 193 } |
| 194 |
| 195 void test_addMissingParameter_function_required_hasZero() { |
| 196 resolveTestUnit(''' |
| 197 test() {} |
| 198 main() { |
| 199 test(1); |
| 200 } |
| 201 '''); |
| 202 assertHasFix(DartFixKind.ADD_MISSING_PARAMETER_REQUIRED, ''' |
| 203 test(int i) {} |
| 204 main() { |
| 205 test(1); |
| 206 } |
| 207 '''); |
| 208 } |
| 209 |
| 210 void test_addMissingParameter_method_positional_hasOne() { |
| 211 resolveTestUnit(''' |
| 212 class A { |
| 213 test(int a) {} |
| 214 main() { |
| 215 test(1, 2.0); |
| 216 } |
| 217 } |
| 218 '''); |
| 219 assertHasFix(DartFixKind.ADD_MISSING_PARAMETER_POSITIONAL, ''' |
| 220 class A { |
| 221 test(int a, [double d]) {} |
| 222 main() { |
| 223 test(1, 2.0); |
| 224 } |
| 225 } |
| 226 '''); |
| 227 } |
| 228 |
| 229 void test_addMissingParameter_method_required_hasOne() { |
| 230 resolveTestUnit(''' |
| 231 class A { |
| 232 test(int a) {} |
| 233 main() { |
| 234 test(1, 2.0); |
| 235 } |
| 236 } |
| 237 '''); |
| 238 assertHasFix(DartFixKind.ADD_MISSING_PARAMETER_REQUIRED, ''' |
| 239 class A { |
| 240 test(int a, double d) {} |
| 241 main() { |
| 242 test(1, 2.0); |
| 243 } |
| 244 } |
| 245 '''); |
| 246 } |
| 247 |
| 248 void test_addMissingParameter_method_required_hasZero() { |
| 249 resolveTestUnit(''' |
| 250 class A { |
| 251 test() {} |
| 252 main() { |
| 253 test(1); |
| 254 } |
| 255 } |
| 256 '''); |
| 257 assertHasFix(DartFixKind.ADD_MISSING_PARAMETER_REQUIRED, ''' |
| 258 class A { |
| 259 test(int i) {} |
| 260 main() { |
| 261 test(1); |
| 262 } |
| 263 } |
| 264 '''); |
| 265 } |
| 266 |
165 void test_addPartOfDirective() { | 267 void test_addPartOfDirective() { |
166 String partCode = r''' | 268 String partCode = r''' |
167 // Comment first. | 269 // Comment first. |
168 // Comment second. | 270 // Comment second. |
169 | 271 |
170 class A {} | 272 class A {} |
171 '''; | 273 '''; |
172 addSource('/part.dart', partCode); | 274 addSource('/part.dart', partCode); |
173 resolveTestUnit(''' | 275 resolveTestUnit(''' |
174 library my.lib; | 276 library my.lib; |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 Test v = null; | 485 Test v = null; |
384 } | 486 } |
385 | 487 |
386 class Test { | 488 class Test { |
387 } | 489 } |
388 '''); | 490 '''); |
389 _assertLinkedGroup(change.linkedEditGroups[0], ['Test v =', 'Test {']); | 491 _assertLinkedGroup(change.linkedEditGroups[0], ['Test v =', 'Test {']); |
390 } | 492 } |
391 | 493 |
392 void test_createClass_inLibraryOfPrefix() { | 494 void test_createClass_inLibraryOfPrefix() { |
393 // TODO | |
394 String libCode = r''' | 495 String libCode = r''' |
395 library my.lib; | 496 library my.lib; |
396 | 497 |
397 class A {} | 498 class A {} |
398 '''; | 499 '''; |
399 addSource('/lib.dart', libCode); | 500 addSource('/lib.dart', libCode); |
400 resolveTestUnit(''' | 501 resolveTestUnit(''' |
401 import 'lib.dart' as lib; | 502 import 'lib.dart' as lib; |
402 | 503 |
403 main() { | 504 main() { |
(...skipping 3356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3760 | 3861 |
3761 List<Position> _findResultPositions(List<String> searchStrings) { | 3862 List<Position> _findResultPositions(List<String> searchStrings) { |
3762 List<Position> positions = <Position>[]; | 3863 List<Position> positions = <Position>[]; |
3763 for (String search in searchStrings) { | 3864 for (String search in searchStrings) { |
3764 int offset = resultCode.indexOf(search); | 3865 int offset = resultCode.indexOf(search); |
3765 positions.add(new Position(testFile, offset)); | 3866 positions.add(new Position(testFile, offset)); |
3766 } | 3867 } |
3767 return positions; | 3868 return positions; |
3768 } | 3869 } |
3769 } | 3870 } |
OLD | NEW |