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

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

Issue 565973006: Issue 19800. Support for inlining getters/setters. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: pkg/analysis_server/test/services/refactoring/inline_method_test.dart
diff --git a/pkg/analysis_server/test/services/refactoring/inline_method_test.dart b/pkg/analysis_server/test/services/refactoring/inline_method_test.dart
index 1236fb2aaa983dccbfde95d9608a66374f8e11bc..d665de6f6dc65057421c905808573db1f8792d72 100644
--- a/pkg/analysis_server/test/services/refactoring/inline_method_test.dart
+++ b/pkg/analysis_server/test/services/refactoring/inline_method_test.dart
@@ -9,10 +9,10 @@ import 'dart:async';
import 'package:analysis_server/src/protocol.dart' hide Element;
import 'package:analysis_server/src/services/refactoring/inline_method.dart';
import 'package:analysis_server/src/services/refactoring/refactoring.dart';
-import '../../reflective_tests.dart';
import 'package:analyzer/src/generated/source.dart';
import 'package:unittest/unittest.dart';
+import '../../reflective_tests.dart';
import 'abstract_refactoring.dart';
@@ -92,6 +92,17 @@ main() {
});
}
+ test_bad_constructor() {
+ indexTestUnit(r'''
+class A {
+ A.named() {}
+}
+''');
+ _createRefactoring('named() {}');
+ // error
+ return _assertInvalidSelection();
+ }
+
test_bad_deleteSource_inlineOne() {
indexTestUnit(r'''
test(a, b) {
@@ -124,8 +135,7 @@ main() {
''');
_createRefactoring(') {');
// error
- return _assertConditionsFatal(
- 'Method declaration or reference must be selected to activate this refactoring.');
+ return _assertInvalidSelection();
}
test_bad_notSimpleIdentifier() {
@@ -137,8 +147,7 @@ main() {
''');
_createRefactoring('test;');
// error
- return _assertConditionsFatal(
- 'Method declaration or reference must be selected to activate this refactoring.');
+ return _assertInvalidSelection();
}
test_bad_operator() {
@@ -694,6 +703,64 @@ main() {
''');
}
+ test_getter_classMember_instance() {
+ indexTestUnit(r'''
+class A {
+ int f;
+ int get result => f + 1;
+}
+main(A a) {
+ print(a.result);
+}
+''');
+ _createRefactoring('result =>');
+ // validate change
+ return _assertSuccessfulRefactoring(r'''
+class A {
+ int f;
+}
+main(A a) {
+ print(a.f + 1);
+}
+''');
+ }
+
+ test_getter_classMember_static() {
+ indexTestUnit(r'''
+class A {
+ static int get result => 1 + 2;
+}
+main() {
+ print(A.result);
+}
+''');
+ _createRefactoring('result =>');
+ // validate change
+ return _assertSuccessfulRefactoring(r'''
+class A {
+}
+main() {
+ print(1 + 2);
+}
+''');
+ }
+
+ test_getter_topLevel() {
+ indexTestUnit(r'''
+String get message => 'Hello, World!';
+main() {
+ print(message);
+}
+''');
+ _createRefactoring('message =>');
+ // validate change
+ return _assertSuccessfulRefactoring(r'''
+main() {
+ print('Hello, World!');
+}
+''');
+ }
+
test_initialMode_all() {
indexTestUnit(r'''
test(a, b) {
@@ -931,6 +998,22 @@ main() {
''');
}
+ test_reference_expressionBody() {
+ indexTestUnit(r'''
+String message() => 'Hello, World!';
+main() {
+ print(message);
+}
+''');
+ _createRefactoring('message()');
+ // validate change
+ return _assertSuccessfulRefactoring(r'''
+main() {
+ print(() => 'Hello, World!');
+}
+''');
+ }
+
test_reference_noStatement() {
indexTestUnit(r'''
test(a, b) {
@@ -999,18 +1082,44 @@ main() {
''');
}
- test_reference_expressionBody() {
+ test_setter_classMember_instance() {
indexTestUnit(r'''
-String message() => 'Hello, World!';
+class A {
+ int f;
+ void set result(x) {
+ f = x + 1;
+ }
+}
+main(A a) {
+ a.result = 5;
+}
+''');
+ _createRefactoring('result(x)');
+ // validate change
+ return _assertSuccessfulRefactoring(r'''
+class A {
+ int f;
+}
+main(A a) {
+ a.f = 5 + 1;
+}
+''');
+ }
+
+ test_setter_topLevel() {
+ indexTestUnit(r'''
+void set result(x) {
+ print(x + 1);
+}
main() {
- print(message);
+ result = 5;
}
''');
- _createRefactoring('message()');
+ _createRefactoring('result(x)');
// validate change
return _assertSuccessfulRefactoring(r'''
main() {
- print(() => 'Hello, World!');
+ print(5 + 1);
}
''');
}
@@ -1174,6 +1283,11 @@ main(bool p, bool p2, bool p3) {
});
}
+ Future _assertInvalidSelection() {
+ return _assertConditionsFatal(
+ 'Method declaration or reference must be selected to activate this refactoring.');
+ }
+
Future _assertSuccessfulRefactoring(String expectedCode) {
return refactoring.checkInitialConditions().then((status) {
assertRefactoringStatusOK(status);

Powered by Google App Engine
This is Rietveld 408576698