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

Side by Side Diff: pkg/analysis_server/test/services/correction/fix_test.dart

Issue 2692983003: Add fix for missing @required params. (Closed)
Patch Set: Added test. Created 3 years, 10 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library test.services.correction.fix; 5 library test.services.correction.fix;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analysis_server/plugin/edit/fix/fix_core.dart'; 9 import 'package:analysis_server/plugin/edit/fix/fix_core.dart';
10 import 'package:analysis_server/plugin/edit/fix/fix_dart.dart'; 10 import 'package:analysis_server/plugin/edit/fix/fix_dart.dart';
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 ''' 420 '''
421 class A { 421 class A {
422 test(int i) {} 422 test(int i) {}
423 main() { 423 main() {
424 test(1); 424 test(1);
425 } 425 }
426 } 426 }
427 '''); 427 ''');
428 } 428 }
429 429
430 test_addMissingRequiredArg_cons_single() async {
431 _addMetaPackageSource();
432
433 await resolveTestUnit('''
434 import 'package:meta/meta.dart';
435
436 class A {
437 A({@required int a}) {}
438 }
439 main() {
440 A a = new A();
441 }
442 ''');
443 await assertHasFix(
444 DartFixKind.ADD_MISSING_REQUIRED_ARGUMENT,
445 '''
446 import 'package:meta/meta.dart';
447
448 class A {
449 A({@required int a}) {}
450 }
451 main() {
452 A a = new A(a: null);
453 }
454 ''');
455 }
456
457 test_addMissingRequiredArg_multiple() async {
458 _addMetaPackageSource();
459
460 await resolveTestUnit('''
461 import 'package:meta/meta.dart';
462
463 test({@required int a, @required int bcd}) {}
464 main() {
465 test(a: 3);
466 }
467 ''');
468 await assertHasFix(
469 DartFixKind.ADD_MISSING_REQUIRED_ARGUMENT,
470 '''
471 import 'package:meta/meta.dart';
472
473 test({@required int a, @required int bcd}) {}
474 main() {
475 test(a: 3, bcd: null);
476 }
477 ''');
478 }
479
480 test_addMissingRequiredArg_single() async {
481 _addMetaPackageSource();
482
483 await resolveTestUnit('''
484 import 'package:meta/meta.dart';
485
486 test({@required int abc}) {}
487 main() {
488 test();
489 }
490 ''');
491 await assertHasFix(
492 DartFixKind.ADD_MISSING_REQUIRED_ARGUMENT,
493 '''
494 import 'package:meta/meta.dart';
495
496 test({@required int abc}) {}
497 main() {
498 test(abc: null);
499 }
500 ''');
501 }
502
503 test_addMissingRequiredArg_single_normal() async {
504 _addMetaPackageSource();
505
506 await resolveTestUnit('''
507 import 'package:meta/meta.dart';
508
509 test(String x, {@required int abc}) {}
510 main() {
511 test("foo");
512 }
513 ''');
514 await assertHasFix(
515 DartFixKind.ADD_MISSING_REQUIRED_ARGUMENT,
516 '''
517 import 'package:meta/meta.dart';
518
519 test(String x, {@required int abc}) {}
520 main() {
521 test("foo", abc: null);
522 }
523 ''');
524 }
525
430 test_addSync_asyncFor() async { 526 test_addSync_asyncFor() async {
431 await resolveTestUnit(''' 527 await resolveTestUnit('''
432 import 'dart:async'; 528 import 'dart:async';
433 void main(Stream<String> names) { 529 void main(Stream<String> names) {
434 await for (String name in names) { 530 await for (String name in names) {
435 print(name); 531 print(name);
436 } 532 }
437 } 533 }
438 '''); 534 ''');
439 await assertHasFix( 535 await assertHasFix(
(...skipping 4889 matching lines...) Expand 10 before | Expand all | Expand 10 after
5329 await assertHasFix( 5425 await assertHasFix(
5330 DartFixKind.IMPORT_LIBRARY_PREFIX, 5426 DartFixKind.IMPORT_LIBRARY_PREFIX,
5331 ''' 5427 '''
5332 import 'dart:math' as pref; 5428 import 'dart:math' as pref;
5333 main() { 5429 main() {
5334 print(pref.E); 5430 print(pref.E);
5335 print(pref.PI); 5431 print(pref.PI);
5336 } 5432 }
5337 '''); 5433 ''');
5338 } 5434 }
5435
5436 void _addMetaPackageSource() {
5437 addPackageSource('meta', 'meta.dart', r'''
5438 library meta;
5439
5440 const Required required = const Required();
5441
5442 class Required {
5443 final String reason;
5444 const Required([this.reason]);
5445 }
5446 ''');
5447 }
5339 } 5448 }
5340 5449
5341 @reflectiveTest 5450 @reflectiveTest
5342 class FixProcessorTest_Driver extends FixProcessorTest { 5451 class FixProcessorTest_Driver extends FixProcessorTest {
5343 @override 5452 @override
5344 bool get enableNewAnalysisDriver => true; 5453 bool get enableNewAnalysisDriver => true;
5345 5454
5346 @failingTest 5455 @failingTest
5347 @override 5456 @override
5348 test_importLibrarySdk_withClass_AsExpression() { 5457 test_importLibrarySdk_withClass_AsExpression() {
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
5654 5763
5655 @override 5764 @override
5656 final CompilationUnit unit; 5765 final CompilationUnit unit;
5657 5766
5658 @override 5767 @override
5659 final AnalysisError error; 5768 final AnalysisError error;
5660 5769
5661 _DartFixContextImpl(this.resourceProvider, this.getTopLevelDeclarations, 5770 _DartFixContextImpl(this.resourceProvider, this.getTopLevelDeclarations,
5662 this.analysisContext, this.astProvider, this.unit, this.error); 5771 this.analysisContext, this.astProvider, this.unit, this.error);
5663 } 5772 }
OLDNEW
« 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