| 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/analysis_server.dart'; | 9 import 'package:analysis_server/src/analysis_server.dart'; |
| 10 import 'package:analysis_server/src/computer/error.dart'; | 10 import 'package:analysis_server/src/computer/error.dart'; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 AnalysisDomainHandler handler; | 34 AnalysisDomainHandler handler; |
| 35 | 35 |
| 36 setUp(() { | 36 setUp(() { |
| 37 serverChannel = new MockServerChannel(); | 37 serverChannel = new MockServerChannel(); |
| 38 resourceProvider = new MemoryResourceProvider(); | 38 resourceProvider = new MemoryResourceProvider(); |
| 39 server = new AnalysisServer(serverChannel, resourceProvider, | 39 server = new AnalysisServer(serverChannel, resourceProvider, |
| 40 new MockPackageMapProvider(), null, new MockSdk()); | 40 new MockPackageMapProvider(), null, new MockSdk()); |
| 41 handler = new AnalysisDomainHandler(server); | 41 handler = new AnalysisDomainHandler(server); |
| 42 }); | 42 }); |
| 43 | 43 |
| 44 group('notification.errors', testNotificationErrors); | |
| 45 group('updateContent', testUpdateContent); | 44 group('updateContent', testUpdateContent); |
| 46 group('setSubscriptions', test_setSubscriptions); | 45 group('setSubscriptions', test_setSubscriptions); |
| 47 | 46 |
| 48 group('AnalysisDomainHandler', () { | 47 group('AnalysisDomainHandler', () { |
| 49 group('setAnalysisRoots', () { | 48 group('setAnalysisRoots', () { |
| 50 Request request; | 49 Request request; |
| 51 | 50 |
| 52 setUp(() { | 51 setUp(() { |
| 53 request = new Request('0', ANALYSIS_SET_ANALYSIS_ROOTS); | 52 request = new Request('0', ANALYSIS_SET_ANALYSIS_ROOTS); |
| 54 request.setParameter(INCLUDED, []); | 53 request.setParameter(INCLUDED, []); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 var response = handler.handleRequest(request); | 140 var response = handler.handleRequest(request); |
| 142 expect(response, isResponseSuccess('0')); | 141 expect(response, isResponseSuccess('0')); |
| 143 expect(options.analyzeAngular, equals(analyzeAngular)); | 142 expect(options.analyzeAngular, equals(analyzeAngular)); |
| 144 expect(options.enableDeferredLoading, equals(enableDeferredLoading)); | 143 expect(options.enableDeferredLoading, equals(enableDeferredLoading)); |
| 145 }); | 144 }); |
| 146 }); | 145 }); |
| 147 }); | 146 }); |
| 148 } | 147 } |
| 149 | 148 |
| 150 | 149 |
| 151 testNotificationErrors() { | |
| 152 AnalysisTestHelper helper; | |
| 153 | |
| 154 setUp(() { | |
| 155 helper = new AnalysisTestHelper(); | |
| 156 }); | |
| 157 | |
| 158 test('ParserError', () { | |
| 159 helper.createSingleFileProject('library lib'); | |
| 160 return helper.waitForOperationsFinished().then((_) { | |
| 161 List<AnalysisError> errors = helper.getTestErrors(); | |
| 162 expect(errors, hasLength(1)); | |
| 163 AnalysisError error = errors[0]; | |
| 164 expect(error.location.file, '/project/bin/test.dart'); | |
| 165 expect(error.location.offset, isPositive); | |
| 166 expect(error.location.length, isNonNegative); | |
| 167 expect(error.severity, 'ERROR'); | |
| 168 expect(error.type, 'SYNTACTIC_ERROR'); | |
| 169 expect(error.message, isNotNull); | |
| 170 }); | |
| 171 }); | |
| 172 | |
| 173 test('StaticWarning', () { | |
| 174 helper.createSingleFileProject(['main() {', ' print(unknown);', '}']); | |
| 175 return helper.waitForOperationsFinished().then((_) { | |
| 176 List<AnalysisError> errors = helper.getTestErrors(); | |
| 177 expect(errors, hasLength(1)); | |
| 178 AnalysisError error = errors[0]; | |
| 179 expect(error.severity, 'WARNING'); | |
| 180 expect(error.type, 'STATIC_WARNING'); | |
| 181 }); | |
| 182 }); | |
| 183 } | |
| 184 | |
| 185 | |
| 186 testUpdateContent() { | 150 testUpdateContent() { |
| 187 test('full content', () { | 151 test('full content', () { |
| 188 AnalysisTestHelper helper = new AnalysisTestHelper(); | 152 AnalysisTestHelper helper = new AnalysisTestHelper(); |
| 189 helper.createSingleFileProject('// empty'); | 153 helper.createSingleFileProject('// empty'); |
| 190 return helper.waitForOperationsFinished().then((_) { | 154 return helper.waitForOperationsFinished().then((_) { |
| 191 // no errors initially | 155 // no errors initially |
| 192 List<AnalysisError> errors = helper.getTestErrors(); | 156 List<AnalysisError> errors = helper.getTestErrors(); |
| 193 expect(errors, isEmpty); | 157 expect(errors, isEmpty); |
| 194 // update code | 158 // update code |
| 195 helper.sendContentChange({ | 159 helper.sendContentChange({ |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 var highlights = helper.getHighlights(helper.testFile); | 267 var highlights = helper.getHighlights(helper.testFile); |
| 304 expect(highlights, isNot(isEmpty)); | 268 expect(highlights, isNot(isEmpty)); |
| 305 }); | 269 }); |
| 306 }); | 270 }); |
| 307 }); | 271 }); |
| 308 | 272 |
| 309 test('after analysis, no such file', () { | 273 test('after analysis, no such file', () { |
| 310 AnalysisTestHelper helper = new AnalysisTestHelper(); | 274 AnalysisTestHelper helper = new AnalysisTestHelper(); |
| 311 helper.createSingleFileProject('int V = 42;'); | 275 helper.createSingleFileProject('int V = 42;'); |
| 312 return helper.waitForOperationsFinished().then((_) { | 276 return helper.waitForOperationsFinished().then((_) { |
| 313 String noFile = '/no-such.file.dart'; | 277 String noFile = '/no-such-file.dart'; |
| 314 helper.addAnalysisSubscriptionErrors(noFile); | 278 helper.addAnalysisSubscriptionHighlights(noFile); |
| 315 return helper.waitForOperationsFinished().then((_) { | 279 return helper.waitForOperationsFinished().then((_) { |
| 316 var errors = helper.getErrors(noFile); | 280 var highlights = helper.getHighlights(noFile); |
| 317 expect(errors, isEmpty); | 281 expect(highlights, isEmpty); |
| 318 }); | 282 }); |
| 319 }); | 283 }); |
| 320 }); | 284 }); |
| 321 } | 285 } |
| 322 | 286 |
| 323 | 287 |
| 324 int _getSafeInt(Map<String, Object> json, String key, int defaultValue) { | 288 int _getSafeInt(Map<String, Object> json, String key, int defaultValue) { |
| 325 Object value = json[key]; | 289 Object value = json[key]; |
| 326 if (value is int) { | 290 if (value is int) { |
| 327 return value; | 291 return value; |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 files = <String>[]; | 416 files = <String>[]; |
| 453 analysisSubscriptions[service.name] = files; | 417 analysisSubscriptions[service.name] = files; |
| 454 } | 418 } |
| 455 files.add(file); | 419 files.add(file); |
| 456 // set subscriptions | 420 // set subscriptions |
| 457 Request request = new Request('0', ANALYSIS_SET_SUBSCRIPTIONS); | 421 Request request = new Request('0', ANALYSIS_SET_SUBSCRIPTIONS); |
| 458 request.setParameter(SUBSCRIPTIONS, analysisSubscriptions); | 422 request.setParameter(SUBSCRIPTIONS, analysisSubscriptions); |
| 459 handleSuccessfulRequest(request); | 423 handleSuccessfulRequest(request); |
| 460 } | 424 } |
| 461 | 425 |
| 462 void addAnalysisSubscriptionErrors(String file) { | |
| 463 addAnalysisSubscription(AnalysisService.ERRORS, file); | |
| 464 } | |
| 465 | |
| 466 void addAnalysisSubscriptionHighlights(String file) { | 426 void addAnalysisSubscriptionHighlights(String file) { |
| 467 addAnalysisSubscription(AnalysisService.HIGHLIGHTS, file); | 427 addAnalysisSubscription(AnalysisService.HIGHLIGHTS, file); |
| 468 } | 428 } |
| 469 | 429 |
| 470 void addAnalysisSubscriptionNavigation(String file) { | 430 void addAnalysisSubscriptionNavigation(String file) { |
| 471 addAnalysisSubscription(AnalysisService.NAVIGATION, file); | 431 addAnalysisSubscription(AnalysisService.NAVIGATION, file); |
| 472 } | 432 } |
| 473 | 433 |
| 474 /** | 434 /** |
| 475 * Creates an empty project `/project`. | 435 * Creates an empty project `/project`. |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 605 return waitForServerOperationsPerformed(server); | 565 return waitForServerOperationsPerformed(server); |
| 606 } | 566 } |
| 607 | 567 |
| 608 static String _getCodeString(code) { | 568 static String _getCodeString(code) { |
| 609 if (code is List<String>) { | 569 if (code is List<String>) { |
| 610 code = code.join('\n'); | 570 code = code.join('\n'); |
| 611 } | 571 } |
| 612 return code as String; | 572 return code as String; |
| 613 } | 573 } |
| 614 } | 574 } |
| OLD | NEW |