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

Unified Diff: pkg/analysis_server/test/services/correction/fix_test.dart

Issue 2862623002: Add default implementation when fixing missing required closures (flutter-intellij#975) (Closed)
Patch Set: Created 3 years, 8 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
« no previous file with comments | « pkg/analysis_server/lib/src/services/correction/fix_internal.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analysis_server/test/services/correction/fix_test.dart
diff --git a/pkg/analysis_server/test/services/correction/fix_test.dart b/pkg/analysis_server/test/services/correction/fix_test.dart
index f128f88fc1462b86c22ad632f9bbe9d25551e547..53b0d4a27b3441ad6ec587a641a4c74fe014488d 100644
--- a/pkg/analysis_server/test/services/correction/fix_test.dart
+++ b/pkg/analysis_server/test/services/correction/fix_test.dart
@@ -466,6 +466,179 @@ main() {
target: '/test.dart');
}
+ test_addMissingRequiredArg_cons_single_closure() async {
+ _addMetaPackageSource();
+
+ addSource(
+ '/libA.dart',
+ r'''
+library libA;
+import 'package:meta/meta.dart';
+
+typedef void VoidCallback();
+
+class A {
+ A({@required VoidCallback onPressed}) {}
+}
+''');
+
+ await resolveTestUnit('''
+import 'libA.dart';
+
+main() {
+ A a = new A();
+}
+''');
+ await assertHasFix(
+ DartFixKind.ADD_MISSING_REQUIRED_ARGUMENT,
+ '''
+import 'libA.dart';
+
+main() {
+ A a = new A(onPressed: () {});
+}
+''',
+ target: '/test.dart');
+ }
+
+ test_addMissingRequiredArg_cons_single_closure_2() async {
+ _addMetaPackageSource();
+
+ addSource(
+ '/libA.dart',
+ r'''
+library libA;
+import 'package:meta/meta.dart';
+
+typedef void Callback(e);
+
+class A {
+ A({@required Callback callback}) {}
+}
+''');
+
+ await resolveTestUnit('''
+import 'libA.dart';
+
+main() {
+ A a = new A();
+}
+''');
+ await assertHasFix(
+ DartFixKind.ADD_MISSING_REQUIRED_ARGUMENT,
+ '''
+import 'libA.dart';
+
+main() {
+ A a = new A(callback: (e) {});
+}
+''',
+ target: '/test.dart');
+ }
+
+ test_addMissingRequiredArg_cons_single_closure_3() async {
+ _addMetaPackageSource();
+
+ addSource(
+ '/libA.dart',
+ r'''
+library libA;
+import 'package:meta/meta.dart';
+
+typedef void Callback(a,b,c);
+
+class A {
+ A({@required Callback callback}) {}
+}
+''');
+
+ await resolveTestUnit('''
+import 'libA.dart';
+
+main() {
+ A a = new A();
+}
+''');
+ await assertHasFix(
+ DartFixKind.ADD_MISSING_REQUIRED_ARGUMENT,
+ '''
+import 'libA.dart';
+
+main() {
+ A a = new A(callback: (a, b, c) {});
+}
+''',
+ target: '/test.dart');
+ }
+
+ test_addMissingRequiredArg_cons_single_closure_4() async {
+ _addMetaPackageSource();
+
+ addSource(
+ '/libA.dart',
+ r'''
+library libA;
+import 'package:meta/meta.dart';
+
+typedef int Callback(a,b,c);
+
+class A {
+ A({@required Callback callback}) {}
+}
+''');
+
+ await resolveTestUnit('''
+import 'libA.dart';
+
+main() {
+ A a = new A();
+}
+''');
+ await assertHasFix(
+ DartFixKind.ADD_MISSING_REQUIRED_ARGUMENT,
+ '''
+import 'libA.dart';
+
+main() {
+ A a = new A(callback: (a, b, c) {});
+}
+''',
+ target: '/test.dart');
+ }
+
+ test_addMissingRequiredArg_cons_single_list() async {
+ _addMetaPackageSource();
+
+ addSource(
+ '/libA.dart',
+ r'''
+library libA;
+import 'package:meta/meta.dart';
+
+class A {
+ A({@required List<String> names}) {}
+}
+''');
+
+ await resolveTestUnit('''
+import 'libA.dart';
+
+main() {
+ A a = new A();
+}
+''');
+ await assertHasFix(
+ DartFixKind.ADD_MISSING_REQUIRED_ARGUMENT,
+ '''
+import 'libA.dart';
+
+main() {
+ A a = new A(names: <String>[]);
+}
+''',
+ target: '/test.dart');
+ }
+
test_addMissingRequiredArg_multiple() async {
_addMetaPackageSource();
« no previous file with comments | « pkg/analysis_server/lib/src/services/correction/fix_internal.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698