| Index: pkg/analysis_server/test/services/correction/assist_test.dart
|
| diff --git a/pkg/analysis_server/test/services/correction/assist_test.dart b/pkg/analysis_server/test/services/correction/assist_test.dart
|
| index 767cfedb6fe09470b3c31729162a11f13bebfc93..80a79399923bd100a464fc8866a8a6aeecb15649 100644
|
| --- a/pkg/analysis_server/test/services/correction/assist_test.dart
|
| +++ b/pkg/analysis_server/test/services/correction/assist_test.dart
|
| @@ -44,6 +44,21 @@ class AssistProcessorTest extends AbstractSingleUnitTest {
|
| String resultCode;
|
| LinkedEditGroup linkedPositionGroup;
|
|
|
| + String flutterPkgLibPath = '/packages/flutter/lib';
|
| +
|
| + String get _flutter_framework_code => '''
|
| +class Widget {}
|
| +class RenderObjectWidget extends Widget {}
|
| +class StatelessWidget extends Widget {}
|
| +class SingleChildRenderObjectWidget extends RenderObjectWidget {}
|
| +class Transform extends SingleChildRenderObjectWidget {}
|
| +class ClipRect extends SingleChildRenderObjectWidget { ClipRect.rect(){} }
|
| +class AspectRatio extends SingleChildRenderObjectWidget {}
|
| +class Container extends StatelessWidget { Container({child: null}){}}
|
| +class DefaultTextStyle extends StatelessWidget { DefaultTextStyle({child: null}){}}
|
| +class Row extends Widget { Row({children: null}){}}
|
| +''';
|
| +
|
| /**
|
| * Asserts that there is an [Assist] of the given [kind] at [offset] which
|
| * produces the [expected] code when applied to [testCode].
|
| @@ -3605,64 +3620,105 @@ final V = 1;
|
| ''');
|
| }
|
|
|
| - test_reparentFlutterWidget_OK_singleLine1() async {
|
| + test_reparentFlutterList_BAD_multiLine() async {
|
| _configureFlutterPkg({
|
| 'src/widgets/framework.dart': _flutter_framework_code,
|
| });
|
| await resolveTestUnit('''
|
| import 'package:flutter/src/widgets/framework.dart';
|
| -class FakeFlutter {
|
| - main() {
|
| +build() {
|
| + return new Container(
|
| + child: new Row(
|
| + children: [/*caret*/
|
| // start
|
| - return /*caret*/new Container();
|
| + new Transform(),
|
| + new Object(),
|
| + new AspectRatio(),
|
| // end
|
| - }
|
| + ],
|
| + ),
|
| + );
|
| }
|
| ''');
|
| _setCaretLocation();
|
| - await assertHasAssist(
|
| - DartAssistKind.REPARENT_FLUTTER_WIDGET,
|
| - '''
|
| + await assertNoAssist(DartAssistKind.REPARENT_FLUTTER_LIST);
|
| + }
|
| +
|
| + test_reparentFlutterList_BAD_singleLine() async {
|
| + _configureFlutterPkg({
|
| + 'src/widgets/framework.dart': _flutter_framework_code,
|
| + });
|
| + await resolveTestUnit('''
|
| import 'package:flutter/src/widgets/framework.dart';
|
| class FakeFlutter {
|
| main() {
|
| + var obj;
|
| // start
|
| - return /*caret*/new widget(child: new Container());
|
| + return new Row(children: [/*caret*/ new Transform()]);
|
| // end
|
| }
|
| }
|
| ''');
|
| + _setCaretLocation();
|
| + await assertNoAssist(DartAssistKind.REPARENT_FLUTTER_LIST);
|
| }
|
|
|
| - test_reparentFlutterWidget_OK_singleLine2() async {
|
| + test_reparentFlutterList_OK_multiLine() async {
|
| _configureFlutterPkg({
|
| 'src/widgets/framework.dart': _flutter_framework_code,
|
| });
|
| await resolveTestUnit('''
|
| import 'package:flutter/src/widgets/framework.dart';
|
| -class FakeFlutter {
|
| - main() {
|
| +build() {
|
| + return new Container(
|
| + child: new Row(
|
| // start
|
| - return new ClipRect./*caret*/rect();
|
| + children: [/*caret*/
|
| + new Transform(),
|
| + new Transform(),
|
| + new AspectRatio(),
|
| + ],
|
| // end
|
| - }
|
| + ),
|
| + );
|
| }
|
| ''');
|
| _setCaretLocation();
|
| await assertHasAssist(
|
| - DartAssistKind.REPARENT_FLUTTER_WIDGET,
|
| + DartAssistKind.REPARENT_FLUTTER_LIST,
|
| '''
|
| import 'package:flutter/src/widgets/framework.dart';
|
| -class FakeFlutter {
|
| - main() {
|
| +build() {
|
| + return new Container(
|
| + child: new Row(
|
| // start
|
| - return new widget(child: new ClipRect./*caret*/rect());
|
| + children: [
|
| + new widget(
|
| + children: [/*caret*/
|
| + new Transform(),
|
| + new Transform(),
|
| + new AspectRatio(),
|
| + ],
|
| + ),
|
| + ],
|
| // end
|
| - }
|
| + ),
|
| + );
|
| }
|
| ''');
|
| }
|
|
|
| + test_reparentFlutterWidget_BAD_minimal() async {
|
| + _configureFlutterPkg({
|
| + 'src/widgets/framework.dart': _flutter_framework_code,
|
| + });
|
| + await resolveTestUnit('''
|
| +/*caret*/x(){}
|
| +''');
|
| + _setCaretLocation();
|
| + await assertNoAssist(DartAssistKind.REPARENT_FLUTTER_WIDGET);
|
| + }
|
| +
|
| test_reparentFlutterWidget_BAD_singleLine() async {
|
| _configureFlutterPkg({
|
| 'src/widgets/framework.dart': _flutter_framework_code,
|
| @@ -3682,7 +3738,7 @@ class FakeFlutter {
|
| await assertNoAssist(DartAssistKind.REPARENT_FLUTTER_WIDGET);
|
| }
|
|
|
| - test_reparentFlutterWidget_OK_multiLines1() async {
|
| + test_reparentFlutterWidget_OK_multiLines() async {
|
| _configureFlutterPkg({
|
| 'src/widgets/framework.dart': _flutter_framework_code,
|
| });
|
| @@ -3731,6 +3787,64 @@ class FakeFlutter {
|
| ''');
|
| }
|
|
|
| + test_reparentFlutterWidget_OK_singleLine1() async {
|
| + _configureFlutterPkg({
|
| + 'src/widgets/framework.dart': _flutter_framework_code,
|
| + });
|
| + await resolveTestUnit('''
|
| +import 'package:flutter/src/widgets/framework.dart';
|
| +class FakeFlutter {
|
| + main() {
|
| +// start
|
| + return /*caret*/new Container();
|
| +// end
|
| + }
|
| +}
|
| +''');
|
| + _setCaretLocation();
|
| + await assertHasAssist(
|
| + DartAssistKind.REPARENT_FLUTTER_WIDGET,
|
| + '''
|
| +import 'package:flutter/src/widgets/framework.dart';
|
| +class FakeFlutter {
|
| + main() {
|
| +// start
|
| + return /*caret*/new widget(child: new Container());
|
| +// end
|
| + }
|
| +}
|
| +''');
|
| + }
|
| +
|
| + test_reparentFlutterWidget_OK_singleLine2() async {
|
| + _configureFlutterPkg({
|
| + 'src/widgets/framework.dart': _flutter_framework_code,
|
| + });
|
| + await resolveTestUnit('''
|
| +import 'package:flutter/src/widgets/framework.dart';
|
| +class FakeFlutter {
|
| + main() {
|
| +// start
|
| + return new ClipRect./*caret*/rect();
|
| +// end
|
| + }
|
| +}
|
| +''');
|
| + _setCaretLocation();
|
| + await assertHasAssist(
|
| + DartAssistKind.REPARENT_FLUTTER_WIDGET,
|
| + '''
|
| +import 'package:flutter/src/widgets/framework.dart';
|
| +class FakeFlutter {
|
| + main() {
|
| +// start
|
| + return new widget(child: new ClipRect./*caret*/rect());
|
| +// end
|
| + }
|
| +}
|
| +''');
|
| + }
|
| +
|
| test_replaceConditionalWithIfElse_BAD_noEnclosingStatement() async {
|
| await resolveTestUnit('''
|
| var v = true ? 111 : 222;
|
| @@ -4336,17 +4450,6 @@ main() {
|
| return await processor.compute();
|
| }
|
|
|
| - List<Position> _findResultPositions(List<String> searchStrings) {
|
| - List<Position> positions = <Position>[];
|
| - for (String search in searchStrings) {
|
| - int offset = resultCode.indexOf(search);
|
| - positions.add(new Position(testFile, offset));
|
| - }
|
| - return positions;
|
| - }
|
| -
|
| - String flutterPkgLibPath = '/packages/flutter/lib';
|
| -
|
| /**
|
| * Configures the [SourceFactory] to have the `flutter` package in
|
| * `/packages/flutter/lib` folder.
|
| @@ -4375,28 +4478,24 @@ main() {
|
| .join('\n'));
|
| }
|
|
|
| - String get _flutter_framework_code => '''
|
| -class Widget {}
|
| -class RenderObjectWidget extends Widget {}
|
| -class StatelessWidget extends Widget {}
|
| -class SingleChildRenderObjectWidget extends RenderObjectWidget {}
|
| -class Transform extends SingleChildRenderObjectWidget {}
|
| -class ClipRect extends SingleChildRenderObjectWidget { ClipRect.rect(){} }
|
| -class AspectRatio extends SingleChildRenderObjectWidget {}
|
| -class Container extends StatelessWidget { Container({child: null}){}}
|
| -class DefaultTextStyle extends StatelessWidget { DefaultTextStyle({child: null}){}}
|
| -class Row extends Widget { Row({children: null}){}}
|
| -''';
|
| -
|
| - void _setStartEndSelection() {
|
| - offset = findOffset('// start\n') + '// start\n'.length;
|
| - length = findOffset('// end') - offset;
|
| + List<Position> _findResultPositions(List<String> searchStrings) {
|
| + List<Position> positions = <Position>[];
|
| + for (String search in searchStrings) {
|
| + int offset = resultCode.indexOf(search);
|
| + positions.add(new Position(testFile, offset));
|
| + }
|
| + return positions;
|
| }
|
|
|
| void _setCaretLocation() {
|
| offset = findOffset('/*caret*/') + '/*caret*/'.length;
|
| length = 0;
|
| }
|
| +
|
| + void _setStartEndSelection() {
|
| + offset = findOffset('// start\n') + '// start\n'.length;
|
| + length = findOffset('// end') - offset;
|
| + }
|
| }
|
|
|
| @reflectiveTest
|
|
|