| 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.refactoring.extract_local; | 5 library test.services.refactoring.extract_local; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analysis_server/plugin/protocol/protocol.dart'; | 9 import 'package:analysis_server/plugin/protocol/protocol.dart'; |
| 10 import 'package:analysis_server/src/services/correction/status.dart'; | 10 import 'package:analysis_server/src/services/correction/status.dart'; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 v = 1; | 62 v = 1; |
| 63 } | 63 } |
| 64 '''); | 64 '''); |
| 65 _createRefactoringWithSuffix('v', ' = 1;'); | 65 _createRefactoringWithSuffix('v', ' = 1;'); |
| 66 // check conditions | 66 // check conditions |
| 67 RefactoringStatus status = await refactoring.checkAllConditions(); | 67 RefactoringStatus status = await refactoring.checkAllConditions(); |
| 68 assertRefactoringStatus(status, RefactoringProblemSeverity.FATAL, | 68 assertRefactoringStatus(status, RefactoringProblemSeverity.FATAL, |
| 69 expectedMessage: 'Cannot extract the left-hand side of an assignment.'); | 69 expectedMessage: 'Cannot extract the left-hand side of an assignment.'); |
| 70 } | 70 } |
| 71 | 71 |
| 72 test_checkInitialConditions_methodName_reference() async { | 72 test_checkInitialConditions_namePartOfDeclaration_function() async { |
| 73 indexTestUnit(''' | 73 indexTestUnit(''' |
| 74 main() { | 74 main() { |
| 75 main(); | |
| 76 } | 75 } |
| 77 '''); | 76 '''); |
| 78 _createRefactoringWithSuffix('main', '();'); | 77 _createRefactoringWithSuffix('main', '()'); |
| 79 // check conditions | 78 // check conditions |
| 80 RefactoringStatus status = await refactoring.checkAllConditions(); | 79 RefactoringStatus status = await refactoring.checkAllConditions(); |
| 81 assertRefactoringStatus(status, RefactoringProblemSeverity.FATAL, | 80 assertRefactoringStatus(status, RefactoringProblemSeverity.FATAL, |
| 82 expectedMessage: 'Cannot extract a single method name.'); | 81 expectedMessage: 'Cannot extract the name part of a declaration.'); |
| 83 } | 82 } |
| 84 | 83 |
| 85 test_checkInitialConditions_namePartOfDeclaration_variable() async { | 84 test_checkInitialConditions_namePartOfDeclaration_variable() async { |
| 86 indexTestUnit(''' | 85 indexTestUnit(''' |
| 87 main() { | 86 main() { |
| 88 int vvv = 0; | 87 int vvv = 0; |
| 89 } | 88 } |
| 90 '''); | 89 '''); |
| 91 _createRefactoringWithSuffix('vvv', ' = 0;'); | 90 _createRefactoringWithSuffix('vvv', ' = 0;'); |
| 92 // check conditions | 91 // check conditions |
| (...skipping 759 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 852 _createRefactoringForString('1 /*abc*/'); | 851 _createRefactoringForString('1 /*abc*/'); |
| 853 // apply refactoring | 852 // apply refactoring |
| 854 return _assertSuccessfulRefactoring(''' | 853 return _assertSuccessfulRefactoring(''' |
| 855 main() { | 854 main() { |
| 856 var res = 1 /*abc*/ + 2; | 855 var res = 1 /*abc*/ + 2; |
| 857 int a = res + 345; | 856 int a = res + 345; |
| 858 } | 857 } |
| 859 '''); | 858 '''); |
| 860 } | 859 } |
| 861 | 860 |
| 861 test_singleExpression_methodName_reference() async { |
| 862 indexTestUnit(''' |
| 863 main() { |
| 864 var v = foo().length; |
| 865 } |
| 866 String foo() => ''; |
| 867 '''); |
| 868 _createRefactoringWithSuffix('foo', '().'); |
| 869 // apply refactoring |
| 870 return _assertSuccessfulRefactoring(''' |
| 871 main() { |
| 872 var res = foo(); |
| 873 var v = res.length; |
| 874 } |
| 875 String foo() => ''; |
| 876 '''); |
| 877 } |
| 878 |
| 862 test_singleExpression_nameOfProperty_prefixedIdentifier() async { | 879 test_singleExpression_nameOfProperty_prefixedIdentifier() async { |
| 863 indexTestUnit(''' | 880 indexTestUnit(''' |
| 864 main(p) { | 881 main(p) { |
| 865 var v = p.value; // marker | 882 var v = p.value; // marker |
| 866 } | 883 } |
| 867 '''); | 884 '''); |
| 868 _createRefactoringWithSuffix('value', '; // marker'); | 885 _createRefactoringWithSuffix('value', '; // marker'); |
| 869 // apply refactoring | 886 // apply refactoring |
| 870 return _assertSuccessfulRefactoring(''' | 887 return _assertSuccessfulRefactoring(''' |
| 871 main(p) { | 888 main(p) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 887 return _assertSuccessfulRefactoring(''' | 904 return _assertSuccessfulRefactoring(''' |
| 888 main() { | 905 main() { |
| 889 var res = foo().length; | 906 var res = foo().length; |
| 890 var v = res; // marker | 907 var v = res; // marker |
| 891 } | 908 } |
| 892 String foo() => ''; | 909 String foo() => ''; |
| 893 '''); | 910 '''); |
| 894 } | 911 } |
| 895 | 912 |
| 896 /** | 913 /** |
| 897 * Here we use knowledge how exactly `1 + 2 + 3 + 41 is parsed. We know that | 914 * Here we use knowledge how exactly `1 + 2 + 3 + 4` is parsed. We know that |
| 898 * `1 + 2` will be a separate and complete binary expression, so it can be | 915 * `1 + 2` will be a separate and complete binary expression, so it can be |
| 899 * handled as a single expression. | 916 * handled as a single expression. |
| 900 */ | 917 */ |
| 901 test_singleExpression_partOfBinaryExpression() { | 918 test_singleExpression_partOfBinaryExpression() { |
| 902 indexTestUnit(''' | 919 indexTestUnit(''' |
| 903 main() { | 920 main() { |
| 904 int a = 1 + 2 + 3 + 4; | 921 int a = 1 + 2 + 3 + 4; |
| 905 } | 922 } |
| 906 '''); | 923 '''); |
| 907 _createRefactoringForString('1 + 2'); | 924 _createRefactoringForString('1 + 2'); |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1030 int length = search.length; | 1047 int length = search.length; |
| 1031 _createRefactoring(offset, length); | 1048 _createRefactoring(offset, length); |
| 1032 } | 1049 } |
| 1033 | 1050 |
| 1034 void _createRefactoringWithSuffix(String selectionSearch, String suffix) { | 1051 void _createRefactoringWithSuffix(String selectionSearch, String suffix) { |
| 1035 int offset = findOffset(selectionSearch + suffix); | 1052 int offset = findOffset(selectionSearch + suffix); |
| 1036 int length = selectionSearch.length; | 1053 int length = selectionSearch.length; |
| 1037 _createRefactoring(offset, length); | 1054 _createRefactoring(offset, length); |
| 1038 } | 1055 } |
| 1039 } | 1056 } |
| OLD | NEW |