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

Unified Diff: pkg/analysis_server/test/edit/refactoring_test.dart

Issue 717513003: Issue 21552. Fixes for navigation, hover and rename in instance creation expressions. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 1 month 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
Index: pkg/analysis_server/test/edit/refactoring_test.dart
diff --git a/pkg/analysis_server/test/edit/refactoring_test.dart b/pkg/analysis_server/test/edit/refactoring_test.dart
index bc3656e4c7d39a47b8f4a593b7006567bdfd2469..76350befedc40c6a66bf5343ad231ebb8330151e 100644
--- a/pkg/analysis_server/test/edit/refactoring_test.dart
+++ b/pkg/analysis_server/test/edit/refactoring_test.dart
@@ -300,6 +300,25 @@ main() {
''');
}
+ test_names() {
+ addTestFile('''
+class TreeItem {}
+TreeItem getSelectedItem() => null;
+main() {
+ var a = getSelectedItem();
+}
+''');
+ return getRefactoringResult(() {
+ return sendStringSuffixRequest('getSelectedItem()', ';', null, true);
+ }).then((result) {
+ ExtractLocalVariableFeedback feedback = result.feedback;
+ expect(
+ feedback.names,
+ unorderedEquals(['treeItem', 'item', 'selectedItem']));
+ expect(result.change, isNull);
+ });
+ }
+
test_nameWarning() {
addTestFile('''
main() {
@@ -322,25 +341,6 @@ main() {
});
}
- test_names() {
- addTestFile('''
-class TreeItem {}
-TreeItem getSelectedItem() => null;
-main() {
- var a = getSelectedItem();
-}
-''');
- return getRefactoringResult(() {
- return sendStringSuffixRequest('getSelectedItem()', ';', null, true);
- }).then((result) {
- ExtractLocalVariableFeedback feedback = result.feedback;
- expect(
- feedback.names,
- unorderedEquals(['treeItem', 'item', 'selectedItem']));
- expect(result.change, isNull);
- });
- }
-
test_offsetsLengths() {
addTestFile('''
main() {
@@ -733,24 +733,6 @@ main() {
@ReflectiveTestCase()
class InlineLocalTest extends _AbstractGetRefactoring_Test {
- test_OK() {
- addTestFile('''
-main() {
- int test = 42;
- int a = test + 2;
- print(test);
-}
-''');
- return assertSuccessfulRefactoring(() {
- return _sendInlineRequest('test + 2');
- }, '''
-main() {
- int a = 42 + 2;
- print(42);
-}
-''');
- }
-
test_feedback() {
addTestFile('''
main() {
@@ -781,6 +763,24 @@ main() {
});
}
+ test_OK() {
+ addTestFile('''
+main() {
+ int test = 42;
+ int a = test + 2;
+ print(test);
+}
+''');
+ return assertSuccessfulRefactoring(() {
+ return _sendInlineRequest('test + 2');
+ }, '''
+main() {
+ int a = 42 + 2;
+ print(42);
+}
+''');
+ }
+
Future<Response> _sendInlineRequest(String search) {
Request request = new EditGetRefactoringParams(
RefactoringKind.INLINE_LOCAL_VARIABLE,
@@ -969,19 +969,102 @@ class RenameTest extends _AbstractGetRefactoring_Test {
test_class() {
addTestFile('''
-class Test {}
+class Test {
+ Test() {}
+ Test.named() {}
+}
main() {
Test v;
+ new Test();
+ new Test.named();
}
''');
return assertSuccessfulRefactoring(() {
- return sendRenameRequest('Test {}', 'NewName');
+ return sendRenameRequest('Test {', 'NewName');
}, '''
+class NewName {
+ NewName() {}
+ NewName.named() {}
+}
+main() {
+ NewName v;
+ new NewName();
+ new NewName.named();
+}
+''');
+ }
+
+ test_class_options_fatalError() {
+ addTestFile('''
+class Test {}
+main() {
+ Test v;
+}
+''');
+ return getRefactoringResult(() {
+ return sendRenameRequest('Test {}', '');
+ }).then((result) {
+ assertResultProblemsFatal(
+ result.optionsProblems,
+ 'Class name must not be empty.');
+ // ...there is no any change
+ expect(result.change, isNull);
+ });
+ }
+
+ test_class_validateOnly() {
+ addTestFile('''
+class Test {}
+main() {
+ Test v;
+}
+''');
+ return getRefactoringResult(() {
+ return sendRenameRequest('Test {}', 'NewName', true);
+ }).then((result) {
+ RenameFeedback feedback = result.feedback;
+ assertResultProblemsOK(result);
+ expect(feedback.elementKindName, 'class');
+ expect(feedback.oldName, 'Test');
+ expect(result.change, isNull);
+ });
+ }
+
+ test_class_warning() {
+ addTestFile('''
+class Test {}
+main() {
+ Test v;
+}
+''');
+ return getRefactoringResult(() {
+ return sendRenameRequest('Test {}', 'newName');
+ }).then((result) {
+ assertResultProblemsWarning(
+ result.optionsProblems,
+ 'Class name should start with an uppercase letter.');
+ // ...but there is still a change
+ assertTestRefactoringResult(result, '''
+class newName {}
+main() {
+ newName v;
+}
+''');
+ }).then((_) {
+ // "NewName" is a perfectly valid name
+ return getRefactoringResult(() {
+ return sendRenameRequest('Test {}', 'NewName');
+ }).then((result) {
+ assertResultProblemsOK(result);
+ // ...and there is a new change
+ assertTestRefactoringResult(result, '''
class NewName {}
main() {
NewName v;
}
''');
+ });
+ });
}
test_classMember_field() {
@@ -1101,115 +1184,59 @@ class A {
''');
}
- test_class_fromInstanceCreation() {
+ test_constructor_fromInstanceCreation() {
addTestFile('''
-class Test {
- Test() {}
- Test.named() {}
+class A {
+ A.test() {}
}
main() {
- new Test();
- new Test.named();
+ new A.test();
}
''');
return assertSuccessfulRefactoring(() {
- return sendRenameRequest('Test();', 'NewName');
+ return sendRenameRequest('test();', 'newName');
}, '''
-class NewName {
- NewName() {}
- NewName.named() {}
+class A {
+ A.newName() {}
}
main() {
- new NewName();
- new NewName.named();
-}
-''');
- }
-
- test_class_options_fatalError() {
- addTestFile('''
-class Test {}
-main() {
- Test v;
+ new A.newName();
}
''');
- return getRefactoringResult(() {
- return sendRenameRequest('Test {}', '');
- }).then((result) {
- assertResultProblemsFatal(
- result.optionsProblems,
- 'Class name must not be empty.');
- // ...there is no any change
- expect(result.change, isNull);
- });
}
- test_class_validateOnly() {
+ test_constructor_fromInstanceCreation_default_onClassName() {
addTestFile('''
-class Test {}
-main() {
- Test v;
+class A {
+ A() {}
}
-''');
- return getRefactoringResult(() {
- return sendRenameRequest('Test {}', 'NewName', true);
- }).then((result) {
- RenameFeedback feedback = result.feedback;
- assertResultProblemsOK(result);
- expect(feedback.elementKindName, 'class');
- expect(feedback.oldName, 'Test');
- expect(result.change, isNull);
- });
- }
-
- test_class_warning() {
- addTestFile('''
-class Test {}
main() {
- Test v;
+ new A();
}
''');
- return getRefactoringResult(() {
- return sendRenameRequest('Test {}', 'newName');
- }).then((result) {
- assertResultProblemsWarning(
- result.optionsProblems,
- 'Class name should start with an uppercase letter.');
- // ...but there is still a change
- assertTestRefactoringResult(result, '''
-class newName {}
-main() {
- newName v;
+ return assertSuccessfulRefactoring(() {
+ return sendRenameRequest('A();', 'newName');
+ }, '''
+class A {
+ A.newName() {}
}
-''');
- }).then((_) {
- // "NewName" is a perfectly valid name
- return getRefactoringResult(() {
- return sendRenameRequest('Test {}', 'NewName');
- }).then((result) {
- assertResultProblemsOK(result);
- // ...and there is a new change
- assertTestRefactoringResult(result, '''
-class NewName {}
main() {
- NewName v;
+ new A.newName();
}
''');
- });
- });
}
- test_constructor_fromInstanceCreation() {
+ test_constructor_fromInstanceCreation_default_onNew() {
addTestFile('''
class A {
- A.test() {}
+ A() {}
}
main() {
- new A.test();
+ new A();
}
''');
return assertSuccessfulRefactoring(() {
- return sendRenameRequest('test();', 'newName');
+ return sendRenameRequest('new A();', 'newName');
}, '''
class A {
A.newName() {}

Powered by Google App Engine
This is Rietveld 408576698