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

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

Issue 677583002: 'Create Local Varaible' quick fix. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 1 month 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 | Annotate | Revision Log
« 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 'package:analysis_server/src/protocol.dart' hide AnalysisError; 7 import 'package:analysis_server/src/protocol.dart' hide AnalysisError;
8 import 'package:analysis_server/src/services/correction/fix.dart'; 8 import 'package:analysis_server/src/services/correction/fix.dart';
9 import 'package:analysis_server/src/services/index/index.dart'; 9 import 'package:analysis_server/src/services/index/index.dart';
10 import 'package:analysis_server/src/services/index/local_memory_index.dart'; 10 import 'package:analysis_server/src/services/index/local_memory_index.dart';
(...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 change = fix.change; 616 change = fix.change;
617 // validate change 617 // validate change
618 List<SourceFileEdit> fileEdits = change.edits; 618 List<SourceFileEdit> fileEdits = change.edits;
619 expect(fileEdits, hasLength(1)); 619 expect(fileEdits, hasLength(1));
620 SourceFileEdit fileEdit = change.edits[0]; 620 SourceFileEdit fileEdit = change.edits[0];
621 expect(fileEdit.file, '/my/project/bin/my_file.dart'); 621 expect(fileEdit.file, '/my/project/bin/my_file.dart');
622 expect(fileEdit.fileStamp, -1); 622 expect(fileEdit.fileStamp, -1);
623 expect(fileEdit.edits[0].replacement, contains('library my.file;')); 623 expect(fileEdit.edits[0].replacement, contains('library my.file;'));
624 } 624 }
625 625
626 void test_createLocalVariable_read_typeAssignment() {
627 _indexTestUnit('''
628 main() {
629 int a = test;
630 }
631 ''');
632 assertHasFix(FixKind.CREATE_LOCAL_VARIABLE, '''
633 main() {
634 int test;
635 int a = test;
636 }
637 ''');
638 }
639
640 void test_createLocalVariable_read_typeCondition() {
641 _indexTestUnit('''
642 main() {
643 if (!test) {
644 print(42);
645 }
646 }
647 ''');
648 assertHasFix(FixKind.CREATE_LOCAL_VARIABLE, '''
649 main() {
650 bool test;
651 if (!test) {
652 print(42);
653 }
654 }
655 ''');
656 }
657
658 void test_createLocalVariable_read_typeInvocationArgument() {
659 _indexTestUnit('''
660 main() {
661 f(test);
662 }
663 f(String p) {}
664 ''');
665 assertHasFix(FixKind.CREATE_LOCAL_VARIABLE, '''
666 main() {
667 String test;
668 f(test);
669 }
670 f(String p) {}
671 ''');
672 }
673
674 void test_createLocalVariable_write_assignment() {
675 _indexTestUnit('''
676 main() {
677 test = 42;
678 }
679 ''');
680 assertHasFix(FixKind.CREATE_LOCAL_VARIABLE, '''
681 main() {
682 var test = 42;
683 }
684 ''');
685 }
686
687 void test_createLocalVariable_write_assignment_compound() {
688 _indexTestUnit('''
689 main() {
690 test += 42;
691 }
692 ''');
693 assertHasFix(FixKind.CREATE_LOCAL_VARIABLE, '''
694 main() {
695 int test;
696 test += 42;
697 }
698 ''');
699 }
700
626 void test_createMissingOverrides_functionType() { 701 void test_createMissingOverrides_functionType() {
627 _indexTestUnit(''' 702 _indexTestUnit('''
628 abstract class A { 703 abstract class A {
629 forEach(int f(double p1, String p2)); 704 forEach(int f(double p1, String p2));
630 } 705 }
631 706
632 class B extends A { 707 class B extends A {
633 } 708 }
634 '''); 709 ''');
635 assertHasFix(FixKind.CREATE_MISSING_OVERRIDES, ''' 710 assertHasFix(FixKind.CREATE_MISSING_OVERRIDES, '''
(...skipping 1607 matching lines...) Expand 10 before | Expand all | Expand 10 after
2243 positions.add(new Position(testFile, offset)); 2318 positions.add(new Position(testFile, offset));
2244 } 2319 }
2245 return positions; 2320 return positions;
2246 } 2321 }
2247 2322
2248 void _indexTestUnit(String code) { 2323 void _indexTestUnit(String code) {
2249 resolveTestUnit(code); 2324 resolveTestUnit(code);
2250 index.indexUnit(context, testUnit); 2325 index.indexUnit(context, testUnit);
2251 } 2326 }
2252 } 2327 }
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