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

Side by Side Diff: pkg/analysis_server/test/domain_analysis_test.dart

Issue 402333006: Implementation of the 'edit.getFixes' API in server. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 5 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.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/element.dart'; 10 import 'package:analysis_server/src/computer/error.dart';
11 import 'package:analysis_server/src/constants.dart'; 11 import 'package:analysis_server/src/constants.dart';
12 import 'package:analysis_server/src/domain_analysis.dart'; 12 import 'package:analysis_server/src/domain_analysis.dart';
13 import 'package:analysis_server/src/protocol.dart'; 13 import 'package:analysis_server/src/protocol.dart';
14 import 'package:analysis_services/constants.dart'; 14 import 'package:analysis_services/constants.dart';
15 import 'package:analysis_testing/mock_sdk.dart'; 15 import 'package:analysis_testing/mock_sdk.dart';
16 import 'package:analysis_testing/reflective_tests.dart'; 16 import 'package:analysis_testing/reflective_tests.dart';
17 import 'package:analyzer/file_system/memory_file_system.dart'; 17 import 'package:analyzer/file_system/memory_file_system.dart';
18 import 'package:analyzer/src/generated/engine.dart'; 18 import 'package:analyzer/src/generated/engine.dart';
19 import 'package:path/path.dart'; 19 import 'package:path/path.dart';
20 import 'package:unittest/unittest.dart'; 20 import 'package:unittest/unittest.dart';
21 21
22 import 'analysis_abstract.dart'; 22 import 'analysis_abstract.dart';
23 import 'mocks.dart'; 23 import 'mocks.dart';
24 24
25 25
26 AnalysisError jsonToAnalysisError(Map<String, Object> json) {
27 Map<String, Object> jsonLocation = json[LOCATION];
28 Location location = new Location(jsonLocation[FILE], _getSafeInt(jsonLocation,
29 OFFSET, -1), _getSafeInt(jsonLocation, LENGTH, -1), _getSafeInt(jsonLocati on,
30 START_LINE, -1), _getSafeInt(jsonLocation, START_COLUMN, -1));
31 return new AnalysisError('unknown error code', json[SEVERITY], json[TYPE], loc ation,
32 json['message'], json['correction']);
33 }
34
35
36 main() { 26 main() {
37 groupSep = ' | '; 27 groupSep = ' | ';
38 28
39 runReflectiveTests(AnalysisDomainTest); 29 runReflectiveTests(AnalysisDomainTest);
40 30
41 MockServerChannel serverChannel; 31 MockServerChannel serverChannel;
42 MemoryResourceProvider resourceProvider; 32 MemoryResourceProvider resourceProvider;
43 AnalysisServer server; 33 AnalysisServer server;
44 AnalysisDomainHandler handler; 34 AnalysisDomainHandler handler;
45 35
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 341
352 342
353 @ReflectiveTestCase() 343 @ReflectiveTestCase()
354 class AnalysisDomainTest extends AbstractAnalysisTest { 344 class AnalysisDomainTest extends AbstractAnalysisTest {
355 Map<String, List<AnalysisError>> filesErrors = {}; 345 Map<String, List<AnalysisError>> filesErrors = {};
356 346
357 void processNotification(Notification notification) { 347 void processNotification(Notification notification) {
358 if (notification.event == ANALYSIS_ERRORS) { 348 if (notification.event == ANALYSIS_ERRORS) {
359 String file = notification.getParameter(FILE); 349 String file = notification.getParameter(FILE);
360 List<Map<String, Object>> errorMaps = notification.getParameter(ERRORS); 350 List<Map<String, Object>> errorMaps = notification.getParameter(ERRORS);
361 filesErrors[file] = errorMaps.map(jsonToAnalysisError).toList(); 351 filesErrors[file] = errorMaps.map(AnalysisError.fromJson).toList();
362 } 352 }
363 } 353 }
364 354
365 test_packageMapDependencies() { 355 test_packageMapDependencies() {
366 // Prepare a source file that has errors because it refers to an unknown 356 // Prepare a source file that has errors because it refers to an unknown
367 // package. 357 // package.
368 String pkgFile = '/packages/pkgA/libA.dart'; 358 String pkgFile = '/packages/pkgA/libA.dart';
369 resourceProvider.newFile(pkgFile, ''' 359 resourceProvider.newFile(pkgFile, '''
370 library lib_a; 360 library lib_a;
371 class A {} 361 class A {}
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 createProject(); 403 createProject();
414 return waitForTasksFinished().then((_) { 404 return waitForTasksFinished().then((_) {
415 // if 'package:pkgA/libA.dart' was resolved, then there are no errors 405 // if 'package:pkgA/libA.dart' was resolved, then there are no errors
416 expect(filesErrors[testFile], isEmpty); 406 expect(filesErrors[testFile], isEmpty);
417 // packages file also was resolved 407 // packages file also was resolved
418 expect(filesErrors[pkgFile], isEmpty); 408 expect(filesErrors[pkgFile], isEmpty);
419 }); 409 });
420 } 410 }
421 } 411 }
422 412
423 class AnalysisError {
424 final String errorCode;
425 final String severity;
426 final String type;
427 final Location location;
428 final String message;
429 final String correction;
430 AnalysisError(this.errorCode, this.severity, this.type, this.location,
431 this.message, this.correction);
432
433 @override
434 String toString() {
435 return 'AnalysisError(location=$location message=$message); '
436 'errorCode=$errorCode; severity=$separator type=$type';
437 }
438 }
439
440 413
441 /** 414 /**
442 * A helper to test 'analysis.*' requests. 415 * A helper to test 'analysis.*' requests.
443 */ 416 */
444 class AnalysisTestHelper { 417 class AnalysisTestHelper {
445 MockServerChannel serverChannel; 418 MockServerChannel serverChannel;
446 MemoryResourceProvider resourceProvider; 419 MemoryResourceProvider resourceProvider;
447 AnalysisServer server; 420 AnalysisServer server;
448 AnalysisDomainHandler handler; 421 AnalysisDomainHandler handler;
449 422
(...skipping 12 matching lines...) Expand all
462 server = new AnalysisServer(serverChannel, resourceProvider, 435 server = new AnalysisServer(serverChannel, resourceProvider,
463 new MockPackageMapProvider(), null, new MockSdk()); 436 new MockPackageMapProvider(), null, new MockSdk());
464 handler = new AnalysisDomainHandler(server); 437 handler = new AnalysisDomainHandler(server);
465 // listen for notifications 438 // listen for notifications
466 Stream<Notification> notificationStream = 439 Stream<Notification> notificationStream =
467 serverChannel.notificationController.stream; 440 serverChannel.notificationController.stream;
468 notificationStream.listen((Notification notification) { 441 notificationStream.listen((Notification notification) {
469 if (notification.event == ANALYSIS_ERRORS) { 442 if (notification.event == ANALYSIS_ERRORS) {
470 String file = notification.getParameter(FILE); 443 String file = notification.getParameter(FILE);
471 List<Map<String, Object>> errorMaps = notification.getParameter(ERRORS); 444 List<Map<String, Object>> errorMaps = notification.getParameter(ERRORS);
472 filesErrors[file] = errorMaps.map(jsonToAnalysisError).toList(); 445 filesErrors[file] = errorMaps.map(AnalysisError.fromJson).toList();
473 } 446 }
474 if (notification.event == ANALYSIS_HIGHLIGHTS) { 447 if (notification.event == ANALYSIS_HIGHLIGHTS) {
475 String file = notification.getParameter(FILE); 448 String file = notification.getParameter(FILE);
476 filesHighlights[file] = notification.getParameter(REGIONS); 449 filesHighlights[file] = notification.getParameter(REGIONS);
477 } 450 }
478 if (notification.event == ANALYSIS_NAVIGATION) { 451 if (notification.event == ANALYSIS_NAVIGATION) {
479 String file = notification.getParameter(FILE); 452 String file = notification.getParameter(FILE);
480 filesNavigation[file] = notification.getParameter(REGIONS); 453 filesNavigation[file] = notification.getParameter(REGIONS);
481 } 454 }
482 }); 455 });
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 return waitForServerOperationsPerformed(server); 615 return waitForServerOperationsPerformed(server);
643 } 616 }
644 617
645 static String _getCodeString(code) { 618 static String _getCodeString(code) {
646 if (code is List<String>) { 619 if (code is List<String>) {
647 code = code.join('\n'); 620 code = code.join('\n');
648 } 621 }
649 return code as String; 622 return code as String;
650 } 623 }
651 } 624 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698