| // Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file |
| // for details. All rights reserved. Use of this source code is governed by a |
| // BSD-style license that can be found in the LICENSE file. |
| |
| import 'package:analysis_server/src/services/correction/assist.dart'; |
| import 'package:analyzer_plugin/utilities/assist/assist.dart'; |
| import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| |
| import 'assist_processor.dart'; |
| |
| main() { |
| defineReflectiveSuite(() { |
| defineReflectiveTests(ConvertToFieldParameterTest); |
| }); |
| } |
| |
| @reflectiveTest |
| class ConvertToFieldParameterTest extends AssistProcessorTest { |
| @override |
| AssistKind get kind => DartAssistKind.CONVERT_TO_FIELD_PARAMETER; |
| |
| test_additionalUse() async { |
| await resolveTestUnit(''' |
| class A { |
| int aaa2; |
| int bbb2; |
| A(int aaa) : aaa2 = aaa, bbb2 = aaa; |
| } |
| '''); |
| await assertNoAssistAt('aaa)'); |
| } |
| |
| test_firstInitializer() async { |
| await resolveTestUnit(''' |
| class A { |
| int aaa2; |
| int bbb2; |
| A(int aaa, int bbb) : aaa2 = aaa, bbb2 = bbb; |
| } |
| '''); |
| await assertHasAssistAt('aaa, ', ''' |
| class A { |
| int aaa2; |
| int bbb2; |
| A(this.aaa2, int bbb) : bbb2 = bbb; |
| } |
| '''); |
| } |
| |
| test_notPureAssignment() async { |
| await resolveTestUnit(''' |
| class A { |
| int aaa2; |
| A(int aaa) : aaa2 = aaa * 2; |
| } |
| '''); |
| await assertNoAssistAt('aaa)'); |
| } |
| |
| test_onParameterName_inInitializer() async { |
| await resolveTestUnit(''' |
| class A { |
| int test2; |
| A(int test) : test2 = test { |
| } |
| } |
| '''); |
| await assertHasAssistAt('test {', ''' |
| class A { |
| int test2; |
| A(this.test2) { |
| } |
| } |
| '''); |
| } |
| |
| test_onParameterName_inParameters() async { |
| await resolveTestUnit(''' |
| class A { |
| int test; |
| A(int test) : test = test { |
| } |
| } |
| '''); |
| await assertHasAssistAt('test)', ''' |
| class A { |
| int test; |
| A(this.test) { |
| } |
| } |
| '''); |
| } |
| |
| test_secondInitializer() async { |
| await resolveTestUnit(''' |
| class A { |
| int aaa2; |
| int bbb2; |
| A(int aaa, int bbb) : aaa2 = aaa, bbb2 = bbb; |
| } |
| '''); |
| await assertHasAssistAt('bbb)', ''' |
| class A { |
| int aaa2; |
| int bbb2; |
| A(int aaa, this.bbb2) : aaa2 = aaa; |
| } |
| '''); |
| } |
| } |