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

Side by Side Diff: pkg/analysis_server/test/services/refactoring/abstract_refactoring.dart

Issue 585803002: Move file refactoring implementation. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 3 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 | Annotate | Revision Log
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.refactoring; 5 library test.services.refactoring;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analysis_server/src/protocol.dart'; 9 import 'package:analysis_server/src/protocol.dart';
10 import 'package:analysis_server/src/services/correction/status.dart'; 10 import 'package:analysis_server/src/services/correction/status.dart';
11 import 'package:analysis_server/src/services/index/index.dart'; 11 import 'package:analysis_server/src/services/index/index.dart';
12 import 'package:analysis_server/src/services/index/local_memory_index.dart'; 12 import 'package:analysis_server/src/services/index/local_memory_index.dart';
13 import 'package:analysis_server/src/services/refactoring/refactoring.dart'; 13 import 'package:analysis_server/src/services/refactoring/refactoring.dart';
14 import 'package:analysis_server/src/services/search/search_engine_internal.dart' ; 14 import 'package:analysis_server/src/services/search/search_engine_internal.dart' ;
15 import '../../abstract_single_unit.dart'; 15 import 'package:analyzer/file_system/file_system.dart';
16 import 'package:analyzer/src/generated/ast.dart'; 16 import 'package:analyzer/src/generated/ast.dart';
17 import 'package:analyzer/src/generated/source.dart'; 17 import 'package:analyzer/src/generated/source.dart';
18 import 'package:unittest/unittest.dart'; 18 import 'package:unittest/unittest.dart';
19 19
20 import '../../abstract_single_unit.dart';
21
20 22
21 int findIdentifierLength(String search) { 23 int findIdentifierLength(String search) {
22 int length = 0; 24 int length = 0;
23 while (length < search.length) { 25 while (length < search.length) {
24 int c = search.codeUnitAt(length); 26 int c = search.codeUnitAt(length);
25 if (!(c >= 'a'.codeUnitAt(0) && c <= 'z'.codeUnitAt(0) || 27 if (!(c >= 'a'.codeUnitAt(0) && c <= 'z'.codeUnitAt(0) ||
26 c >= 'A'.codeUnitAt(0) && c <= 'Z'.codeUnitAt(0) || 28 c >= 'A'.codeUnitAt(0) && c <= 'Z'.codeUnitAt(0) ||
27 c >= '0'.codeUnitAt(0) && c <= '9'.codeUnitAt(0))) { 29 c >= '0'.codeUnitAt(0) && c <= '9'.codeUnitAt(0))) {
28 break; 30 break;
29 } 31 }
30 length++; 32 length++;
31 } 33 }
32 return length; 34 return length;
33 } 35 }
34 36
35 37
36 /** 38 /**
37 * The base class for all [Refactoring] tests. 39 * The base class for all [Refactoring] tests.
38 */ 40 */
39 abstract class RefactoringTest extends AbstractSingleUnitTest { 41 abstract class RefactoringTest extends AbstractSingleUnitTest {
40 Index index; 42 Index index;
41 SearchEngineImpl searchEngine; 43 SearchEngineImpl searchEngine;
42 44
43 SourceChange refactoringChange; 45 SourceChange refactoringChange;
44 46
45 Refactoring get refactoring; 47 Refactoring get refactoring;
46 48
47 /** 49 /**
50 * Asserts that [refactoringChange] contains a [FileEdit] for the file
51 * with the given [path], and it results the [expectedCode].
52 */
53 void assertFileChangeResult(String path, String expectedCode) {
54 // prepare FileEdit
55 SourceFileEdit fileEdit = refactoringChange.getFileEdit(path);
56 expect(fileEdit, isNotNull, reason: 'No file edit for $path');
57 // validate resulting code
58 File file = provider.getResource(path);
59 Source source = file.createSource();
60 String ini = context.getContents(source).data;
61 String actualCode = SourceEdit.applySequence(ini, fileEdit.edits);
62 expect(actualCode, expectedCode);
63 }
64
65 /**
66 * Asserts that [refactoringChange] does not contain a [FileEdit] for the file
67 * with the given [path].
68 */
69 void assertNoFileChange(String path) {
70 SourceFileEdit fileEdit = refactoringChange.getFileEdit(path);
71 expect(fileEdit, isNull);
72 }
73
74 /**
48 * Asserts that [refactoring] initial/final conditions status is OK. 75 * Asserts that [refactoring] initial/final conditions status is OK.
49 */ 76 */
50 Future assertRefactoringConditionsOK() { 77 Future assertRefactoringConditionsOK() {
51 return refactoring.checkInitialConditions().then((status) { 78 return refactoring.checkInitialConditions().then((status) {
52 assertRefactoringStatusOK(status); 79 assertRefactoringStatusOK(status);
53 return refactoring.checkFinalConditions().then((status) { 80 return refactoring.checkFinalConditions().then((status) {
54 assertRefactoringStatusOK(status); 81 assertRefactoringStatusOK(status);
55 }); 82 });
56 }); 83 });
57 } 84 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 } 119 }
93 120
94 /** 121 /**
95 * Asserts that [refactoring] status is OK. 122 * Asserts that [refactoring] status is OK.
96 */ 123 */
97 void assertRefactoringStatusOK(RefactoringStatus status) { 124 void assertRefactoringStatusOK(RefactoringStatus status) {
98 assertRefactoringStatus(status, null); 125 assertRefactoringStatus(status, null);
99 } 126 }
100 127
101 /** 128 /**
102 * Asserts that [refactoringChange] contains a [FileEdit] for [testFile], and
103 * it results the [expectedCode].
104 */
105 void assertTestChangeResult(String expectedCode) {
106 // prepare FileEdit
107 SourceFileEdit fileEdit = refactoringChange.getFileEdit(testFile);
108 expect(fileEdit, isNotNull);
109 // validate resulting code
110 String actualCode = SourceEdit.applySequence(testCode, fileEdit.edits);
111 expect(actualCode, expectedCode);
112 }
113
114 /**
115 * Checks that all conditions of [refactoring] are OK and the result of 129 * Checks that all conditions of [refactoring] are OK and the result of
116 * applying the [Change] to [testUnit] is [expectedCode]. 130 * applying the [Change] to [testUnit] is [expectedCode].
117 */ 131 */
118 Future assertSuccessfulRefactoring(String expectedCode) { 132 Future assertSuccessfulRefactoring(String expectedCode) {
119 return assertRefactoringConditionsOK().then((_) { 133 return assertRefactoringConditionsOK().then((_) {
120 return refactoring.createChange().then((SourceChange change) { 134 return refactoring.createChange().then((SourceChange change) {
121 this.refactoringChange = change; 135 this.refactoringChange = change;
122 assertTestChangeResult(expectedCode); 136 assertTestChangeResult(expectedCode);
123 }); 137 });
124 }); 138 });
125 } 139 }
126 140
141 /**
142 * Asserts that [refactoringChange] contains a [FileEdit] for [testFile], and
143 * it results the [expectedCode].
144 */
145 void assertTestChangeResult(String expectedCode) {
146 // prepare FileEdit
147 SourceFileEdit fileEdit = refactoringChange.getFileEdit(testFile);
148 expect(fileEdit, isNotNull);
149 // validate resulting code
150 String actualCode = SourceEdit.applySequence(testCode, fileEdit.edits);
151 expect(actualCode, expectedCode);
152 }
153
127 void indexTestUnit(String code) { 154 void indexTestUnit(String code) {
128 resolveTestUnit(code); 155 resolveTestUnit(code);
129 index.indexUnit(context, testUnit); 156 index.indexUnit(context, testUnit);
130 } 157 }
131 158
132 void indexUnit(String file, String code) { 159 void indexUnit(String file, String code) {
133 Source source = addSource(file, code); 160 Source source = addSource(file, code);
134 CompilationUnit unit = resolveLibraryUnit(source); 161 CompilationUnit unit = resolveLibraryUnit(source);
135 index.indexUnit(context, unit); 162 index.indexUnit(context, unit);
136 } 163 }
137 164
138 void setUp() { 165 void setUp() {
139 super.setUp(); 166 super.setUp();
140 index = createLocalMemoryIndex(); 167 index = createLocalMemoryIndex();
141 searchEngine = new SearchEngineImpl(index); 168 searchEngine = new SearchEngineImpl(index);
142 } 169 }
143 } 170 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/test/abstract_single_unit.dart ('k') | pkg/analysis_server/test/services/refactoring/abstract_rename.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698