OLD | NEW |
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 'package:analyzer/file_system/file_system.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'; | 20 import '../../abstract_single_unit.dart'; |
21 | 21 |
22 | |
23 int findIdentifierLength(String search) { | 22 int findIdentifierLength(String search) { |
24 int length = 0; | 23 int length = 0; |
25 while (length < search.length) { | 24 while (length < search.length) { |
26 int c = search.codeUnitAt(length); | 25 int c = search.codeUnitAt(length); |
27 if (!(c >= 'a'.codeUnitAt(0) && c <= 'z'.codeUnitAt(0) || | 26 if (!(c >= 'a'.codeUnitAt(0) && c <= 'z'.codeUnitAt(0) || |
28 c >= 'A'.codeUnitAt(0) && c <= 'Z'.codeUnitAt(0) || | 27 c >= 'A'.codeUnitAt(0) && c <= 'Z'.codeUnitAt(0) || |
29 c >= '0'.codeUnitAt(0) && c <= '9'.codeUnitAt(0))) { | 28 c >= '0'.codeUnitAt(0) && c <= '9'.codeUnitAt(0))) { |
30 break; | 29 break; |
31 } | 30 } |
32 length++; | 31 length++; |
33 } | 32 } |
34 return length; | 33 return length; |
35 } | 34 } |
36 | 35 |
37 | |
38 /** | 36 /** |
39 * The base class for all [Refactoring] tests. | 37 * The base class for all [Refactoring] tests. |
40 */ | 38 */ |
41 abstract class RefactoringTest extends AbstractSingleUnitTest { | 39 abstract class RefactoringTest extends AbstractSingleUnitTest { |
42 Index index; | 40 Index index; |
43 SearchEngineImpl searchEngine; | 41 SearchEngineImpl searchEngine; |
44 | 42 |
45 SourceChange refactoringChange; | 43 SourceChange refactoringChange; |
46 | 44 |
47 Refactoring get refactoring; | 45 Refactoring get refactoring; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 * Asserts that [refactoring] final conditions status is OK. | 83 * Asserts that [refactoring] final conditions status is OK. |
86 */ | 84 */ |
87 Future assertRefactoringFinalConditionsOK() async { | 85 Future assertRefactoringFinalConditionsOK() async { |
88 RefactoringStatus status = await refactoring.checkFinalConditions(); | 86 RefactoringStatus status = await refactoring.checkFinalConditions(); |
89 assertRefactoringStatusOK(status); | 87 assertRefactoringStatusOK(status); |
90 } | 88 } |
91 | 89 |
92 /** | 90 /** |
93 * Asserts that [status] has expected severity and message. | 91 * Asserts that [status] has expected severity and message. |
94 */ | 92 */ |
95 void assertRefactoringStatus(RefactoringStatus status, | 93 void assertRefactoringStatus( |
96 RefactoringProblemSeverity expectedSeverity, {String expectedMessage, | 94 RefactoringStatus status, RefactoringProblemSeverity expectedSeverity, |
97 SourceRange expectedContextRange, String expectedContextSearch}) { | 95 {String expectedMessage, SourceRange expectedContextRange, |
| 96 String expectedContextSearch}) { |
98 expect(status.severity, expectedSeverity, reason: status.toString()); | 97 expect(status.severity, expectedSeverity, reason: status.toString()); |
99 if (expectedSeverity != null) { | 98 if (expectedSeverity != null) { |
100 RefactoringProblem problem = status.problem; | 99 RefactoringProblem problem = status.problem; |
101 expect(problem.severity, expectedSeverity); | 100 expect(problem.severity, expectedSeverity); |
102 if (expectedMessage != null) { | 101 if (expectedMessage != null) { |
103 expect(problem.message, expectedMessage); | 102 expect(problem.message, expectedMessage); |
104 } | 103 } |
105 if (expectedContextRange != null) { | 104 if (expectedContextRange != null) { |
106 expect(problem.location.offset, expectedContextRange.offset); | 105 expect(problem.location.offset, expectedContextRange.offset); |
107 expect(problem.location.length, expectedContextRange.length); | 106 expect(problem.location.length, expectedContextRange.length); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 CompilationUnit unit = resolveLibraryUnit(source); | 155 CompilationUnit unit = resolveLibraryUnit(source); |
157 index.indexUnit(context, unit); | 156 index.indexUnit(context, unit); |
158 } | 157 } |
159 | 158 |
160 void setUp() { | 159 void setUp() { |
161 super.setUp(); | 160 super.setUp(); |
162 index = createLocalMemoryIndex(); | 161 index = createLocalMemoryIndex(); |
163 searchEngine = new SearchEngineImpl(index); | 162 searchEngine = new SearchEngineImpl(index); |
164 } | 163 } |
165 } | 164 } |
OLD | NEW |