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

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

Issue 311653002: Extract analysis/notifications into a separate operation/file. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Tweak for the test method name. Created 6 years, 6 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.analysis_server; 5 library test.analysis_server;
6 6
7 import 'package:analyzer/src/generated/engine.dart'; 7 import 'package:analyzer/src/generated/engine.dart';
8 import 'package:analyzer/src/generated/error.dart'; 8 import 'package:analyzer/src/generated/error.dart';
9 import 'package:analyzer/src/generated/source.dart'; 9 import 'package:analyzer/src/generated/source.dart';
10 import 'package:analysis_server/src/analysis_server.dart'; 10 import 'package:analysis_server/src/analysis_server.dart';
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 AnalysisServerTestHelper helper = new AnalysisServerTestHelper(); 61 AnalysisServerTestHelper helper = new AnalysisServerTestHelper();
62 helper.server.handlers = [new EchoHandler()]; 62 helper.server.handlers = [new EchoHandler()];
63 var request = new Request('my22', 'echo'); 63 var request = new Request('my22', 'echo');
64 return helper.channel.sendRequest(request) 64 return helper.channel.sendRequest(request)
65 .then((Response response) { 65 .then((Response response) {
66 expect(response.id, equals('my22')); 66 expect(response.id, equals('my22'));
67 expect(response.error, isNull); 67 expect(response.error, isNull);
68 }); 68 });
69 }); 69 });
70 70
71 test('errorToJson_formattingApplied', () {
72 MockSource source = new MockSource();
73 source.when(callsTo('get encoding')).alwaysReturn('foo.dart');
74 CompileTimeErrorCode errorCode = CompileTimeErrorCode.AMBIGUOUS_EXPORT;
75 AnalysisError analysisError =
76 new AnalysisError.con1(source, errorCode, ['foo', 'bar', 'baz']);
77 Map<String, Object> json = AnalysisServer.errorToJson(analysisError);
78
79 expect(json['message'],
80 equals("The name 'foo' is defined in the libraries 'bar' and 'baz'"));
81 });
82
83 test('errorToJson_noCorrection', () {
84 MockSource source = new MockSource();
85 source.when(callsTo('get fullName')).alwaysReturn('foo.dart');
86 CompileTimeErrorCode errorCode =
87 CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_CONST_SUPER;
88 AnalysisError analysisError =
89 new AnalysisError.con2(source, 10, 5, errorCode, ['Foo']);
90 Map<String, Object> json = AnalysisServer.errorToJson(analysisError);
91 expect(json, hasLength(5));
92 expect(json['file'], equals('foo.dart'));
93 expect(json['errorCode'], 'CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON _CONST_SUPER');
94 expect(json['offset'], equals(analysisError.offset));
95 expect(json['length'], equals(analysisError.length));
96 expect(json['message'], equals(errorCode.message.replaceAll('%s', 'Foo'))) ;
97 });
98
99 test('errorToJson_withCorrection', () {
100 MockSource source = new MockSource();
101 source.when(callsTo('get encoding')).alwaysReturn('foo.dart');
102
103 // TODO(paulberry): in principle we should test an error or hint that uses
104 // %s formatting in its correction string. But no such errors or hints
105 // currently exist!
106 HintCode errorCode = HintCode.MISSING_RETURN;
107
108 AnalysisError analysisError =
109 new AnalysisError.con2(source, 10, 5, errorCode, ['int']);
110 Map<String, Object> json = AnalysisServer.errorToJson(analysisError);
111 expect(json['correction'], equals(errorCode.correction));
112 });
113
114 test('shutdown', () { 71 test('shutdown', () {
115 AnalysisServerTestHelper helper = new AnalysisServerTestHelper(); 72 AnalysisServerTestHelper helper = new AnalysisServerTestHelper();
116 helper.server.handlers = [new ServerDomainHandler(helper.server)]; 73 helper.server.handlers = [new ServerDomainHandler(helper.server)];
117 var request = new Request('my28', METHOD_SHUTDOWN); 74 var request = new Request('my28', METHOD_SHUTDOWN);
118 return helper.channel.sendRequest(request) 75 return helper.channel.sendRequest(request)
119 .then((Response response) { 76 .then((Response response) {
120 expect(response.id, equals('my28')); 77 expect(response.id, equals('my28'));
121 expect(response.error, isNull); 78 expect(response.error, isNull);
122 }); 79 });
123 }); 80 });
(...skipping 15 matching lines...) Expand all
139 @override 96 @override
140 Response handleRequest(Request request) { 97 Response handleRequest(Request request) {
141 if (request.method == 'echo') { 98 if (request.method == 'echo') {
142 var response = new Response(request.id); 99 var response = new Response(request.id);
143 response.setResult('echo', true); 100 response.setResult('echo', true);
144 return response; 101 return response;
145 } 102 }
146 return null; 103 return null;
147 } 104 }
148 } 105 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698