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

Unified Diff: pkg/analysis_server/test/services/refactoring/extract_local_test.dart

Issue 1528013004: Issue 25253. Improve collecting names that may conflict with the extracted local variable. (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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analysis_server/test/services/refactoring/extract_local_test.dart
diff --git a/pkg/analysis_server/test/services/refactoring/extract_local_test.dart b/pkg/analysis_server/test/services/refactoring/extract_local_test.dart
index 5bea780f8164b456df16bb059d5b1b90fc01d98a..cac1c16fa75897c3aefd6381b3ab07b4a2172c6e 100644
--- a/pkg/analysis_server/test/services/refactoring/extract_local_test.dart
+++ b/pkg/analysis_server/test/services/refactoring/extract_local_test.dart
@@ -36,9 +36,8 @@ main() {
_createRefactoringForString('1 + 2');
// conflicting name
RefactoringStatus status = await refactoring.checkAllConditions();
- assertRefactoringStatus(status, RefactoringProblemSeverity.WARNING,
- expectedMessage:
- "A variable with name 'res' is already defined in the visible scope.");
+ assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR,
+ expectedMessage: "The name 'res' is already used in the scope.");
}
test_checkFinalConditions_sameVariable_before() async {
@@ -51,9 +50,8 @@ main() {
_createRefactoringForString('1 + 2');
// conflicting name
RefactoringStatus status = await refactoring.checkAllConditions();
- assertRefactoringStatus(status, RefactoringProblemSeverity.WARNING,
- expectedMessage:
- "A variable with name 'res' is already defined in the visible scope.");
+ assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR,
+ expectedMessage: "The name 'res' is already used in the scope.");
}
test_checkInitialConditions_assignmentLeftHandSize() async {
@@ -163,7 +161,7 @@ main() {
expectedMessage: 'Cannot extract the void expression.');
}
- test_checkLocalName() {
+ test_checkName() {
indexTestUnit('''
main() {
int a = 1 + 2;
@@ -186,6 +184,55 @@ main() {
assertRefactoringStatusOK(refactoring.checkName());
}
+ test_checkName_conflict_withInvokedFunction() async {
+ indexTestUnit('''
+main() {
+ int a = 1 + 2;
+ res();
+}
+
+void res() {}
+''');
+ _createRefactoringForString('1 + 2');
+ await refactoring.checkInitialConditions();
+ refactoring.name = 'res';
+ assertRefactoringStatus(
+ refactoring.checkName(), RefactoringProblemSeverity.ERROR,
+ expectedMessage: "The name 'res' is already used in the scope.");
+ }
+
+ test_checkName_conflict_withOtherLocal() async {
+ indexTestUnit('''
+main() {
+ var res;
+ int a = 1 + 2;
+}
+''');
+ _createRefactoringForString('1 + 2');
+ await refactoring.checkInitialConditions();
+ refactoring.name = 'res';
+ assertRefactoringStatus(
+ refactoring.checkName(), RefactoringProblemSeverity.ERROR,
+ expectedMessage: "The name 'res' is already used in the scope.");
+ }
+
+ test_checkName_conflict_withTypeName() async {
+ indexTestUnit('''
+main() {
+ int a = 1 + 2;
+ Res b = null;
+}
+
+class Res {}
+''');
+ _createRefactoringForString('1 + 2');
+ await refactoring.checkInitialConditions();
+ refactoring.name = 'Res';
+ assertRefactoringStatus(
+ refactoring.checkName(), RefactoringProblemSeverity.ERROR,
+ expectedMessage: "The name 'Res' is already used in the scope.");
+ }
+
test_completeStatementExpression() {
indexTestUnit('''
main(p) {
« 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