| 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);
|
|
|