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.domain.analysis.abstract; | 5 library test.domain.analysis.abstract; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 import 'package:analysis_server/src/analysis_server.dart'; | 9 import 'package:analysis_server/src/analysis_server.dart'; |
10 import 'package:analysis_server/src/domain_analysis.dart'; | 10 import 'package:analysis_server/src/domain_analysis.dart'; |
11 import 'package:analysis_server/src/protocol.dart'; | 11 import 'package:analysis_server/src/protocol.dart'; |
12 import 'package:analysis_server/src/services/index/index.dart'; | 12 import 'package:analysis_server/src/services/index/index.dart'; |
13 import 'mock_sdk.dart'; | |
14 import 'package:analyzer/file_system/file_system.dart'; | 13 import 'package:analyzer/file_system/file_system.dart'; |
15 import 'package:analyzer/file_system/memory_file_system.dart'; | 14 import 'package:analyzer/file_system/memory_file_system.dart'; |
16 import 'package:unittest/unittest.dart'; | 15 import 'package:unittest/unittest.dart'; |
17 | 16 |
| 17 import 'mock_sdk.dart'; |
18 import 'mocks.dart'; | 18 import 'mocks.dart'; |
19 | 19 |
20 | 20 |
21 int findIdentifierLength(String search) { | 21 int findIdentifierLength(String search) { |
22 int length = 0; | 22 int length = 0; |
23 while (length < search.length) { | 23 while (length < search.length) { |
24 int c = search.codeUnitAt(length); | 24 int c = search.codeUnitAt(length); |
25 if (!(c >= 'a'.codeUnitAt(0) && c <= 'z'.codeUnitAt(0) || | 25 if (!(c >= 'a'.codeUnitAt(0) && c <= 'z'.codeUnitAt(0) || |
26 c >= 'A'.codeUnitAt(0) && c <= 'Z'.codeUnitAt(0) || | 26 c >= 'A'.codeUnitAt(0) && c <= 'Z'.codeUnitAt(0) || |
27 c >= '0'.codeUnitAt(0) && c <= '9'.codeUnitAt(0))) { | 27 c >= '0'.codeUnitAt(0) && c <= '9'.codeUnitAt(0))) { |
28 break; | 28 break; |
29 } | 29 } |
30 length++; | 30 length++; |
31 } | 31 } |
32 return length; | 32 return length; |
33 } | 33 } |
34 | 34 |
35 | 35 |
36 | 36 |
37 /** | 37 /** |
(...skipping 11 matching lines...) Expand all Loading... |
49 String projectPath = '/project'; | 49 String projectPath = '/project'; |
50 String testFolder = '/project/bin/'; | 50 String testFolder = '/project/bin/'; |
51 String testFile = '/project/bin/test.dart'; | 51 String testFile = '/project/bin/test.dart'; |
52 String testCode; | 52 String testCode; |
53 | 53 |
54 // Map<String, List<AnalysisError>> filesErrors = {}; | 54 // Map<String, List<AnalysisError>> filesErrors = {}; |
55 // Map<String, List<Map<String, Object>>> filesHighlights = {}; | 55 // Map<String, List<Map<String, Object>>> filesHighlights = {}; |
56 // Map<String, List<Map<String, Object>>> filesNavigation = {}; | 56 // Map<String, List<Map<String, Object>>> filesNavigation = {}; |
57 | 57 |
58 | 58 |
59 AbstractAnalysisTest() { | 59 AbstractAnalysisTest(); |
60 } | |
61 | |
62 void addAnalysisSubscription(AnalysisService service, String file) { | 60 void addAnalysisSubscription(AnalysisService service, String file) { |
63 // add file to subscription | 61 // add file to subscription |
64 var files = analysisSubscriptions[service]; | 62 var files = analysisSubscriptions[service]; |
65 if (files == null) { | 63 if (files == null) { |
66 files = <String>[]; | 64 files = <String>[]; |
67 analysisSubscriptions[service] = files; | 65 analysisSubscriptions[service] = files; |
68 } | 66 } |
69 files.add(file); | 67 files.add(file); |
70 // set subscriptions | 68 // set subscriptions |
71 Request request = new AnalysisSetSubscriptionsParams( | 69 Request request = |
72 analysisSubscriptions).toRequest('0'); | 70 new AnalysisSetSubscriptionsParams(analysisSubscriptions).toRequest('0')
; |
73 handleSuccessfulRequest(request); | 71 handleSuccessfulRequest(request); |
74 } | 72 } |
75 | 73 |
76 String addFile(String path, String content) { | 74 String addFile(String path, String content) { |
77 resourceProvider.newFile(path, content); | 75 resourceProvider.newFile(path, content); |
78 return path; | 76 return path; |
79 } | 77 } |
80 | 78 |
81 String addTestFile(String content) { | 79 String addTestFile(String content) { |
82 addFile(testFile, content); | 80 addFile(testFile, content); |
83 this.testCode = content; | 81 this.testCode = content; |
84 return testFile; | 82 return testFile; |
85 } | 83 } |
86 | 84 |
87 String modifyTestFile(String content) { | |
88 addFile(testFile, content); | |
89 this.testCode = content; | |
90 return testFile; | |
91 } | |
92 | |
93 Index createIndex() { | 85 Index createIndex() { |
94 return null; | 86 return null; |
95 } | 87 } |
96 | 88 |
97 /** | 89 /** |
98 * Creates a project `/project`. | 90 * Creates a project `/project`. |
99 */ | 91 */ |
100 void createProject() { | 92 void createProject() { |
101 resourceProvider.newFolder(projectPath); | 93 resourceProvider.newFolder(projectPath); |
102 Request request = new AnalysisSetAnalysisRootsParams([projectPath], | 94 Request request = |
103 []).toRequest('0'); | 95 new AnalysisSetAnalysisRootsParams([projectPath], []).toRequest('0'); |
104 handleSuccessfulRequest(request); | 96 handleSuccessfulRequest(request); |
105 } | 97 } |
106 | 98 |
107 /** | 99 /** |
108 * Returns the offset of [search] in [testCode]. | 100 * Returns the offset of [search] in [testCode]. |
109 * Fails if not found. | 101 * Fails if not found. |
110 */ | 102 */ |
111 int findFileOffset(String path, String search) { | 103 int findFileOffset(String path, String search) { |
112 File file = resourceProvider.getResource(path) as File; | 104 File file = resourceProvider.getResource(path) as File; |
113 String code = file.createSource().contents.data; | 105 String code = file.createSource().contents.data; |
(...skipping 14 matching lines...) Expand all Loading... |
128 | 120 |
129 /** | 121 /** |
130 * Validates that the given [request] is handled successfully. | 122 * Validates that the given [request] is handled successfully. |
131 */ | 123 */ |
132 Response handleSuccessfulRequest(Request request) { | 124 Response handleSuccessfulRequest(Request request) { |
133 Response response = handler.handleRequest(request); | 125 Response response = handler.handleRequest(request); |
134 expect(response, isResponseSuccess('0')); | 126 expect(response, isResponseSuccess('0')); |
135 return response; | 127 return response; |
136 } | 128 } |
137 | 129 |
| 130 String modifyTestFile(String content) { |
| 131 addFile(testFile, content); |
| 132 this.testCode = content; |
| 133 return testFile; |
| 134 } |
| 135 |
138 // /** | 136 // /** |
139 // * Returns [AnalysisError]s recorded for the given [file]. | 137 // * Returns [AnalysisError]s recorded for the given [file]. |
140 // * May be empty, but not `null`. | 138 // * May be empty, but not `null`. |
141 // */ | 139 // */ |
142 // List<AnalysisError> getErrors(String file) { | 140 // List<AnalysisError> getErrors(String file) { |
143 // List<AnalysisError> errors = filesErrors[file]; | 141 // List<AnalysisError> errors = filesErrors[file]; |
144 // if (errors != null) { | 142 // if (errors != null) { |
145 // return errors; | 143 // return errors; |
146 // } | 144 // } |
147 // return <AnalysisError>[]; | 145 // return <AnalysisError>[]; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 // []).toRequest('0'); | 221 // []).toRequest('0'); |
224 // handleSuccessfulRequest(request); | 222 // handleSuccessfulRequest(request); |
225 // } | 223 // } |
226 | 224 |
227 void setUp() { | 225 void setUp() { |
228 serverChannel = new MockServerChannel(); | 226 serverChannel = new MockServerChannel(); |
229 resourceProvider = new MemoryResourceProvider(); | 227 resourceProvider = new MemoryResourceProvider(); |
230 packageMapProvider = new MockPackageMapProvider(); | 228 packageMapProvider = new MockPackageMapProvider(); |
231 Index index = createIndex(); | 229 Index index = createIndex(); |
232 server = new AnalysisServer( | 230 server = new AnalysisServer( |
233 serverChannel, resourceProvider, packageMapProvider, index, | 231 serverChannel, |
| 232 resourceProvider, |
| 233 packageMapProvider, |
| 234 index, |
234 new MockSdk()); | 235 new MockSdk()); |
235 server.contextDirectoryManager.defaultOptions.enableAsync = true; | 236 server.contextDirectoryManager.defaultOptions.enableAsync = true; |
236 server.contextDirectoryManager.defaultOptions.enableEnum = true; | 237 server.contextDirectoryManager.defaultOptions.enableEnum = true; |
237 handler = new AnalysisDomainHandler(server); | 238 handler = new AnalysisDomainHandler(server); |
238 // listen for notifications | 239 // listen for notifications |
239 Stream<Notification> notificationStream = serverChannel.notificationControll
er.stream; | 240 Stream<Notification> notificationStream = |
| 241 serverChannel.notificationController.stream; |
240 notificationStream.listen((Notification notification) { | 242 notificationStream.listen((Notification notification) { |
241 processNotification(notification); | 243 processNotification(notification); |
242 }); | 244 }); |
243 } | 245 } |
244 | 246 |
245 void tearDown() { | 247 void tearDown() { |
246 server.done(); | 248 server.done(); |
247 handler = null; | 249 handler = null; |
248 server = null; | 250 server = null; |
249 resourceProvider = null; | 251 resourceProvider = null; |
250 serverChannel = null; | 252 serverChannel = null; |
251 } | 253 } |
252 | 254 |
253 /** | 255 /** |
254 * Returns a [Future] that completes when the [AnalysisServer] finishes | 256 * Returns a [Future] that completes when the [AnalysisServer] finishes |
255 * all its scheduled tasks. | 257 * all its scheduled tasks. |
256 */ | 258 */ |
257 Future waitForTasksFinished() { | 259 Future waitForTasksFinished() { |
258 return waitForServerOperationsPerformed(server); | 260 return waitForServerOperationsPerformed(server); |
259 } | 261 } |
260 } | 262 } |
OLD | NEW |