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

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

Issue 1062823002: Issue 13239. Add the 'Encapsulate Field' refactoring. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 8 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 | 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:analyzer/src/generated/source.dart'; 9 import 'package:analyzer/src/generated/source.dart';
10 import 'package:unittest/unittest.dart'; 10 import 'package:unittest/unittest.dart';
(...skipping 1272 matching lines...) Expand 10 before | Expand all | Expand 10 after
1283 !'text'.isEmpty; 1283 !'text'.isEmpty;
1284 } 1284 }
1285 '''); 1285 ''');
1286 assertHasAssistAt('isEmpty', AssistKind.CONVERT_INTO_IS_NOT_EMPTY, ''' 1286 assertHasAssistAt('isEmpty', AssistKind.CONVERT_INTO_IS_NOT_EMPTY, '''
1287 main(String str) { 1287 main(String str) {
1288 'text'.isNotEmpty; 1288 'text'.isNotEmpty;
1289 } 1289 }
1290 '''); 1290 ''');
1291 } 1291 }
1292 1292
1293 void test_convertToIsNotEmpty_wrong_noBang() {
1294 verifyNoTestUnitErrors = false;
1295 resolveTestUnit('''
1296 main(String str) {
1297 ~str.isEmpty;
1298 }
1299 ''');
1300 assertNoAssistAt('isEmpty;', AssistKind.CONVERT_INTO_IS_NOT_EMPTY);
1301 }
1302
1303 void test_convertToIsNotEmpty_wrong_noIsNotEmpty() {
1304 resolveTestUnit('''
1305 class A {
1306 bool get isEmpty => false;
1307 }
1308 main(A a) {
1309 !a.isEmpty;
1310 }
1311 ''');
1312 assertNoAssistAt('isEmpty;', AssistKind.CONVERT_INTO_IS_NOT_EMPTY);
1313 }
1314
1293 void test_convertToIsNotEmpty_wrong_notInPrefixExpression() { 1315 void test_convertToIsNotEmpty_wrong_notInPrefixExpression() {
1294 resolveTestUnit(''' 1316 resolveTestUnit('''
1295 main(String str) { 1317 main(String str) {
1296 str.isEmpty; 1318 str.isEmpty;
1297 } 1319 }
1298 '''); 1320 ''');
1299 assertNoAssistAt('isEmpty;', AssistKind.CONVERT_INTO_IS_NOT_EMPTY); 1321 assertNoAssistAt('isEmpty;', AssistKind.CONVERT_INTO_IS_NOT_EMPTY);
1300 } 1322 }
1301 1323
1302 void test_convertToIsNotEmpty_wrong_notIsEmpty() { 1324 void test_convertToIsNotEmpty_wrong_notIsEmpty() {
1303 resolveTestUnit(''' 1325 resolveTestUnit('''
1304 main(int p) { 1326 main(int p) {
1305 !p.isEven; 1327 !p.isEven;
1306 } 1328 }
1307 '''); 1329 ''');
1308 assertNoAssistAt('isEven;', AssistKind.CONVERT_INTO_IS_NOT_EMPTY); 1330 assertNoAssistAt('isEven;', AssistKind.CONVERT_INTO_IS_NOT_EMPTY);
1309 } 1331 }
1310 1332
1311 void test_convertToIsNotEmpty_wrote_noIsNotEmpty() { 1333 void test_encapsulateField_BAD_alreadyPrivate() {
1312 resolveTestUnit(''' 1334 resolveTestUnit('''
1313 class A { 1335 class A {
1314 bool get isEmpty => false; 1336 int _test = 42;
1315 } 1337 }
1316 main(A a) { 1338 main(A a) {
1317 !a.isEmpty; 1339 print(a._test);
1318 } 1340 }
1319 '''); 1341 ''');
1320 assertNoAssistAt('isEmpty;', AssistKind.CONVERT_INTO_IS_NOT_EMPTY); 1342 assertNoAssistAt('_test =', AssistKind.ENCAPSULATE_FIELD);
1343 }
1344
1345 void test_encapsulateField_BAD_multipleFields() {
1346 resolveTestUnit('''
1347 class A {
1348 int aaa, bbb, ccc;
1349 }
1350 main(A a) {
1351 print(a.bbb);
1352 }
1353 ''');
1354 assertNoAssistAt('bbb, ', AssistKind.ENCAPSULATE_FIELD);
1355 }
1356
1357 void test_encapsulateField_BAD_parseError() {
1358 verifyNoTestUnitErrors = false;
1359 resolveTestUnit('''
1360 class A {
1361 int; // marker
1362 }
1363 main(A a) {
1364 print(a.test);
1365 }
1366 ''');
1367 assertNoAssistAt('; // marker', AssistKind.ENCAPSULATE_FIELD);
1368 }
1369
1370 void test_encapsulateField_OK_hasType() {
1371 resolveTestUnit('''
1372 class A {
1373 int test = 42;
1374 }
1375 main(A a) {
1376 print(a.test);
1377 }
1378 ''');
1379 assertHasAssistAt('test = 42', AssistKind.ENCAPSULATE_FIELD, '''
1380 class A {
1381 int _test = 42;
1382
1383 int get test => _test;
1384
1385 void set test(int test) {
1386 _test = test;
1387 }
1388 }
1389 main(A a) {
1390 print(a.test);
1391 }
1392 ''');
1393 }
1394
1395 void test_encapsulateField_OK_noType() {
1396 resolveTestUnit('''
1397 class A {
1398 var test = 42;
1399 }
1400 main(A a) {
1401 print(a.test);
1402 }
1403 ''');
1404 assertHasAssistAt('test = 42', AssistKind.ENCAPSULATE_FIELD, '''
1405 class A {
1406 var _test = 42;
1407
1408 get test => _test;
1409
1410 void set test(test) {
1411 _test = test;
1412 }
1413 }
1414 main(A a) {
1415 print(a.test);
1416 }
1417 ''');
1321 } 1418 }
1322 1419
1323 void test_exchangeBinaryExpressionArguments_OK_compare() { 1420 void test_exchangeBinaryExpressionArguments_OK_compare() {
1324 Map<String, String> operatorMap = { 1421 Map<String, String> operatorMap = {
1325 '<': '>', 1422 '<': '>',
1326 '<=': '>=', 1423 '<=': '>=',
1327 '>': '<', 1424 '>': '<',
1328 '>=': '<=' 1425 '>=': '<='
1329 }; 1426 };
1330 operatorMap.forEach((initialOperator, resultOperator) { 1427 operatorMap.forEach((initialOperator, resultOperator) {
(...skipping 1608 matching lines...) Expand 10 before | Expand all | Expand 10 after
2939 positions.add(new Position(testFile, offset)); 3036 positions.add(new Position(testFile, offset));
2940 } 3037 }
2941 return positions; 3038 return positions;
2942 } 3039 }
2943 3040
2944 void _setStartEndSelection() { 3041 void _setStartEndSelection() {
2945 offset = findOffset('// start\n') + '// start\n'.length; 3042 offset = findOffset('// start\n') + '// start\n'.length;
2946 length = findOffset('// end') - offset; 3043 length = findOffset('// end') - offset;
2947 } 3044 }
2948 } 3045 }
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