| 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; | 5 library test.domain.analysis; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analysis_server/src/computer/computer_highlights.dart'; | 9 import 'package:analysis_server/src/computer/computer_highlights.dart'; |
| 10 import 'package:analysis_server/src/analysis_server.dart'; | 10 import 'package:analysis_server/src/analysis_server.dart'; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 handler = new AnalysisDomainHandler(server); | 32 handler = new AnalysisDomainHandler(server); |
| 33 }); | 33 }); |
| 34 | 34 |
| 35 group('notification.errors', testNotificationErrors); | 35 group('notification.errors', testNotificationErrors); |
| 36 group('notification.highlights', testNotificationHighlights); | 36 group('notification.highlights', testNotificationHighlights); |
| 37 group('notification.navigation', testNotificationNavigation); | 37 group('notification.navigation', testNotificationNavigation); |
| 38 group('updateContent', testUpdateContent); | 38 group('updateContent', testUpdateContent); |
| 39 group('setSubscriptions', test_setSubscriptions); | 39 group('setSubscriptions', test_setSubscriptions); |
| 40 | 40 |
| 41 group('AnalysisDomainHandler', () { | 41 group('AnalysisDomainHandler', () { |
| 42 test('getFixes', () { | |
| 43 var request = new Request('0', METHOD_GET_FIXES); | |
| 44 request.setParameter(ERRORS, []); | |
| 45 var response = handler.handleRequest(request); | |
| 46 // TODO(scheglov) implement | |
| 47 expect(response, isNull); | |
| 48 }); | |
| 49 | |
| 50 test('getMinorRefactorings', () { | |
| 51 var request = new Request('0', METHOD_GET_MINOR_REFACTORINGS); | |
| 52 request.setParameter(FILE, 'test.dart'); | |
| 53 request.setParameter(OFFSET, 10); | |
| 54 request.setParameter(LENGTH, 20); | |
| 55 var response = handler.handleRequest(request); | |
| 56 // TODO(scheglov) implement | |
| 57 expect(response, isNull); | |
| 58 }); | |
| 59 | |
| 60 group('setAnalysisRoots', () { | 42 group('setAnalysisRoots', () { |
| 61 Request request; | 43 Request request; |
| 62 | 44 |
| 63 setUp(() { | 45 setUp(() { |
| 64 request = new Request('0', METHOD_SET_ANALYSIS_ROOTS); | 46 request = new Request('0', ANALYSIS_SET_ANALYSIS_ROOTS); |
| 65 request.setParameter(INCLUDED, []); | 47 request.setParameter(INCLUDED, []); |
| 66 request.setParameter(EXCLUDED, []); | 48 request.setParameter(EXCLUDED, []); |
| 67 }); | 49 }); |
| 68 | 50 |
| 69 test('excluded', () { | 51 test('excluded', () { |
| 70 request.setParameter(EXCLUDED, ['foo']); | 52 request.setParameter(EXCLUDED, ['foo']); |
| 71 // TODO(scheglov) implement | 53 // TODO(scheglov) implement |
| 72 var response = handler.handleRequest(request); | 54 var response = handler.handleRequest(request); |
| 73 expect(response, isResponseFailure('0')); | 55 expect(response, isResponseFailure('0')); |
| 74 }); | 56 }); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 87 // verify that unit is resolved eventually | 69 // verify that unit is resolved eventually |
| 88 return waitForServerOperationsPerformed(server).then((_) { | 70 return waitForServerOperationsPerformed(server).then((_) { |
| 89 var unit = serverRef.test_getResolvedCompilationUnit('/project/bin/t
est.dart'); | 71 var unit = serverRef.test_getResolvedCompilationUnit('/project/bin/t
est.dart'); |
| 90 expect(unit, isNotNull); | 72 expect(unit, isNotNull); |
| 91 }); | 73 }); |
| 92 }); | 74 }); |
| 93 }); | 75 }); |
| 94 }); | 76 }); |
| 95 | 77 |
| 96 test('setPriorityFiles', () { | 78 test('setPriorityFiles', () { |
| 97 var request = new Request('0', METHOD_SET_PRIORITY_FILES); | 79 var request = new Request('0', ANALYSIS_SET_PRIORITY_FILES); |
| 98 request.setParameter( | 80 request.setParameter( |
| 99 FILES, | 81 FILES, |
| 100 ['projectA/aa.dart', 'projectB/ba.dart']); | 82 ['projectA/aa.dart', 'projectB/ba.dart']); |
| 101 var response = handler.handleRequest(request); | 83 var response = handler.handleRequest(request); |
| 102 // TODO(scheglov) implement | 84 // TODO(scheglov) implement |
| 103 expect(response, isNull); | 85 expect(response, isNull); |
| 104 }); | 86 }); |
| 105 | 87 |
| 106 test('updateOptions', () { | 88 test('updateOptions', () { |
| 107 var request = new Request('0', METHOD_UPDATE_OPTIONS); | 89 var request = new Request('0', ANALYSIS_UPDATE_OPTIONS); |
| 108 request.setParameter( | 90 request.setParameter( |
| 109 OPTIONS, | 91 OPTIONS, |
| 110 { | 92 { |
| 111 'analyzeAngular' : true, | 93 'analyzeAngular' : true, |
| 112 'enableDeferredLoading': true, | 94 'enableDeferredLoading': true, |
| 113 'enableEnums': false | 95 'enableEnums': false |
| 114 }); | 96 }); |
| 115 var response = handler.handleRequest(request); | 97 var response = handler.handleRequest(request); |
| 116 // TODO(scheglov) implement | 98 // TODO(scheglov) implement |
| 117 expect(response, isNull); | 99 expect(response, isNull); |
| 118 }); | 100 }); |
| 119 | 101 |
| 120 test('updateSdks', () { | 102 test('updateSdks', () { |
| 121 var request = new Request('0', METHOD_UPDATE_SDKS); | 103 var request = new Request('0', ANALYSIS_UPDATE_SDKS); |
| 122 request.setParameter( | 104 request.setParameter( |
| 123 ADDED, | 105 ADDED, |
| 124 ['/dart/sdk-1.3', '/dart/sdk-1.4']); | 106 ['/dart/sdk-1.3', '/dart/sdk-1.4']); |
| 125 request.setParameter( | 107 request.setParameter( |
| 126 REMOVED, | 108 REMOVED, |
| 127 ['/dart/sdk-1.2']); | 109 ['/dart/sdk-1.2']); |
| 128 request.setParameter(DEFAULT, '/dart/sdk-1.4'); | 110 request.setParameter(DEFAULT, '/dart/sdk-1.4'); |
| 129 var response = handler.handleRequest(request); | 111 var response = handler.handleRequest(request); |
| 130 // TODO(scheglov) implement | 112 // TODO(scheglov) implement |
| 131 expect(response, isNull); | 113 expect(response, isNull); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 | 165 |
| 184 AnalysisTestHelper() { | 166 AnalysisTestHelper() { |
| 185 serverChannel = new MockServerChannel(); | 167 serverChannel = new MockServerChannel(); |
| 186 resourceProvider = new MemoryResourceProvider(); | 168 resourceProvider = new MemoryResourceProvider(); |
| 187 server = new AnalysisServer(serverChannel, resourceProvider); | 169 server = new AnalysisServer(serverChannel, resourceProvider); |
| 188 server.defaultSdk = new MockSdk(); | 170 server.defaultSdk = new MockSdk(); |
| 189 handler = new AnalysisDomainHandler(server); | 171 handler = new AnalysisDomainHandler(server); |
| 190 // listen for notifications | 172 // listen for notifications |
| 191 Stream<Notification> notificationStream = serverChannel.notificationControll
er.stream; | 173 Stream<Notification> notificationStream = serverChannel.notificationControll
er.stream; |
| 192 notificationStream.listen((Notification notification) { | 174 notificationStream.listen((Notification notification) { |
| 193 if (notification.event == NOTIFICATION_ERRORS) { | 175 if (notification.event == ANALYSIS_ERRORS) { |
| 194 String file = notification.getParameter(FILE); | 176 String file = notification.getParameter(FILE); |
| 195 List<Map<String, Object>> errorMaps = notification.getParameter(ERRORS); | 177 List<Map<String, Object>> errorMaps = notification.getParameter(ERRORS); |
| 196 filesErrors[file] = errorMaps.map(jsonToAnalysisError).toList(); | 178 filesErrors[file] = errorMaps.map(jsonToAnalysisError).toList(); |
| 197 } | 179 } |
| 198 if (notification.event == NOTIFICATION_HIGHLIGHTS) { | 180 if (notification.event == ANALYSIS_HIGHLIGHTS) { |
| 199 String file = notification.getParameter(FILE); | 181 String file = notification.getParameter(FILE); |
| 200 filesHighlights[file] = notification.getParameter(REGIONS); | 182 filesHighlights[file] = notification.getParameter(REGIONS); |
| 201 } | 183 } |
| 202 if (notification.event == NOTIFICATION_NAVIGATION) { | 184 if (notification.event == ANALYSIS_NAVIGATION) { |
| 203 String file = notification.getParameter(FILE); | 185 String file = notification.getParameter(FILE); |
| 204 filesNavigation[file] = notification.getParameter(REGIONS); | 186 filesNavigation[file] = notification.getParameter(REGIONS); |
| 205 } | 187 } |
| 206 }); | 188 }); |
| 207 } | 189 } |
| 208 | 190 |
| 209 void addAnalysisSubscriptionHighlights(String file) { | 191 void addAnalysisSubscriptionHighlights(String file) { |
| 210 addAnalysisSubscription(AnalysisService.HIGHLIGHTS, file); | 192 addAnalysisSubscription(AnalysisService.HIGHLIGHTS, file); |
| 211 } | 193 } |
| 212 | 194 |
| 213 void addAnalysisSubscriptionNavigation(String file) { | 195 void addAnalysisSubscriptionNavigation(String file) { |
| 214 addAnalysisSubscription(AnalysisService.NAVIGATION, file); | 196 addAnalysisSubscription(AnalysisService.NAVIGATION, file); |
| 215 } | 197 } |
| 216 | 198 |
| 217 void addAnalysisSubscription(AnalysisService service, String file) { | 199 void addAnalysisSubscription(AnalysisService service, String file) { |
| 218 // add file to subscription | 200 // add file to subscription |
| 219 var files = analysisSubscriptions[service.name]; | 201 var files = analysisSubscriptions[service.name]; |
| 220 if (files == null) { | 202 if (files == null) { |
| 221 files = <String>[]; | 203 files = <String>[]; |
| 222 analysisSubscriptions[service.name] = files; | 204 analysisSubscriptions[service.name] = files; |
| 223 } | 205 } |
| 224 files.add(file); | 206 files.add(file); |
| 225 // set subscriptions | 207 // set subscriptions |
| 226 Request request = new Request('0', METHOD_SET_ANALYSIS_SUBSCRIPTIONS); | 208 Request request = new Request('0', ANALYSIS_SET_SUBSCRIPTIONS); |
| 227 request.setParameter(SUBSCRIPTIONS, analysisSubscriptions); | 209 request.setParameter(SUBSCRIPTIONS, analysisSubscriptions); |
| 228 handleSuccessfulRequest(request); | 210 handleSuccessfulRequest(request); |
| 229 } | 211 } |
| 230 | 212 |
| 231 /** | 213 /** |
| 232 * Returns a [Future] that completes when this this helper finished all its | 214 * Returns a [Future] that completes when this this helper finished all its |
| 233 * scheduled tasks. | 215 * scheduled tasks. |
| 234 */ | 216 */ |
| 235 Future waitForOperationsFinished() { | 217 Future waitForOperationsFinished() { |
| 236 return waitForServerOperationsPerformed(server); | 218 return waitForServerOperationsPerformed(server); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 */ | 286 */ |
| 305 List<Map<String, Object>> getTestNavigation() { | 287 List<Map<String, Object>> getTestNavigation() { |
| 306 return getNavigation(testFile); | 288 return getNavigation(testFile); |
| 307 } | 289 } |
| 308 | 290 |
| 309 /** | 291 /** |
| 310 * Creates an empty project `/project`. | 292 * Creates an empty project `/project`. |
| 311 */ | 293 */ |
| 312 void createEmptyProject() { | 294 void createEmptyProject() { |
| 313 resourceProvider.newFolder('/project'); | 295 resourceProvider.newFolder('/project'); |
| 314 Request request = new Request('0', METHOD_SET_ANALYSIS_ROOTS); | 296 Request request = new Request('0', ANALYSIS_SET_ANALYSIS_ROOTS); |
| 315 request.setParameter(INCLUDED, ['/project']); | 297 request.setParameter(INCLUDED, ['/project']); |
| 316 request.setParameter(EXCLUDED, []); | 298 request.setParameter(EXCLUDED, []); |
| 317 handleSuccessfulRequest(request); | 299 handleSuccessfulRequest(request); |
| 318 } | 300 } |
| 319 | 301 |
| 320 /** | 302 /** |
| 321 * Creates a project with a single Dart file `/project/bin/test.dart` with | 303 * Creates a project with a single Dart file `/project/bin/test.dart` with |
| 322 * the given [code]. | 304 * the given [code]. |
| 323 */ | 305 */ |
| 324 void createSingleFileProject(code) { | 306 void createSingleFileProject(code) { |
| 325 this.testCode = _getCodeString(code); | 307 this.testCode = _getCodeString(code); |
| 326 resourceProvider.newFolder('/project'); | 308 resourceProvider.newFolder('/project'); |
| 327 resourceProvider.newFile(testFile, testCode); | 309 resourceProvider.newFile(testFile, testCode); |
| 328 Request request = new Request('0', METHOD_SET_ANALYSIS_ROOTS); | 310 Request request = new Request('0', ANALYSIS_SET_ANALYSIS_ROOTS); |
| 329 request.setParameter(INCLUDED, ['/project']); | 311 request.setParameter(INCLUDED, ['/project']); |
| 330 request.setParameter(EXCLUDED, []); | 312 request.setParameter(EXCLUDED, []); |
| 331 handleSuccessfulRequest(request); | 313 handleSuccessfulRequest(request); |
| 332 } | 314 } |
| 333 | 315 |
| 334 String setFileContent(String path, String content) { | 316 String setFileContent(String path, String content) { |
| 335 resourceProvider.newFile(path, content); | 317 resourceProvider.newFile(path, content); |
| 336 return path; | 318 return path; |
| 337 } | 319 } |
| 338 | 320 |
| 339 /** | 321 /** |
| 340 * Validates that the given [request] is handled successfully. | 322 * Validates that the given [request] is handled successfully. |
| 341 */ | 323 */ |
| 342 void handleSuccessfulRequest(Request request) { | 324 void handleSuccessfulRequest(Request request) { |
| 343 Response response = handler.handleRequest(request); | 325 Response response = handler.handleRequest(request); |
| 344 expect(response, isResponseSuccess('0')); | 326 expect(response, isResponseSuccess('0')); |
| 345 } | 327 } |
| 346 | 328 |
| 347 /** | 329 /** |
| 348 * Stops the associated server. | 330 * Stops the associated server. |
| 349 */ | 331 */ |
| 350 void stopServer() { | 332 void stopServer() { |
| 351 server.done(); | 333 server.done(); |
| 352 } | 334 } |
| 353 | 335 |
| 354 /** | 336 /** |
| 355 * Send an `updateContent` request for [testFile]. | 337 * Send an `updateContent` request for [testFile]. |
| 356 */ | 338 */ |
| 357 void sendContentChange(Map contentChange) { | 339 void sendContentChange(Map contentChange) { |
| 358 Request request = new Request('0', METHOD_UPDATE_CONTENT); | 340 Request request = new Request('0', ANALYSIS_UPDATE_CONTENT); |
| 359 request.setParameter('files', { | 341 request.setParameter('files', { |
| 360 testFile: contentChange | 342 testFile: contentChange |
| 361 }); | 343 }); |
| 362 handleSuccessfulRequest(request); | 344 handleSuccessfulRequest(request); |
| 363 } | 345 } |
| 364 | 346 |
| 365 static String _getCodeString(code) { | 347 static String _getCodeString(code) { |
| 366 if (code is List<String>) { | 348 if (code is List<String>) { |
| 367 code = code.join('\n'); | 349 code = code.join('\n'); |
| 368 } | 350 } |
| (...skipping 1291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1660 // subscribe | 1642 // subscribe |
| 1661 helper.addAnalysisSubscriptionHighlights(helper.testFile); | 1643 helper.addAnalysisSubscriptionHighlights(helper.testFile); |
| 1662 // wait, has regions | 1644 // wait, has regions |
| 1663 return helper.waitForOperationsFinished().then((_) { | 1645 return helper.waitForOperationsFinished().then((_) { |
| 1664 var highlights = helper.getHighlights(helper.testFile); | 1646 var highlights = helper.getHighlights(helper.testFile); |
| 1665 expect(highlights, isNot(isEmpty)); | 1647 expect(highlights, isNot(isEmpty)); |
| 1666 }); | 1648 }); |
| 1667 }); | 1649 }); |
| 1668 }); | 1650 }); |
| 1669 } | 1651 } |
| OLD | NEW |