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

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

Issue 530583004: Rename Error to RequestError in analysis server API. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 3 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.protocol; 5 library test.protocol;
6 6
7 import 'dart:convert'; 7 import 'dart:convert';
8 8
9 import 'package:analysis_server/src/constants.dart';
9 import 'package:analysis_server/src/protocol.dart'; 10 import 'package:analysis_server/src/protocol.dart';
10 import 'package:analysis_testing/reflective_tests.dart'; 11 import 'package:analysis_testing/reflective_tests.dart';
11 import 'package:unittest/unittest.dart'; 12 import 'package:unittest/unittest.dart';
12 13
13 14
14 Matcher _throwsRequestFailure = throwsA(new isInstanceOf<RequestFailure>()); 15 Matcher _throwsRequestFailure = throwsA(new isInstanceOf<RequestFailure>());
15 16
16 17
17 main() { 18 main() {
18 groupSep = ' | '; 19 groupSep = ' | ';
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 } 92 }
92 93
93 94
94 @ReflectiveTestCase() 95 @ReflectiveTestCase()
95 class RequestErrorTest { 96 class RequestErrorTest {
96 void test_create() { 97 void test_create() {
97 RequestError error = new RequestError(RequestErrorCode.INVALID_REQUEST, 'msg '); 98 RequestError error = new RequestError(RequestErrorCode.INVALID_REQUEST, 'msg ');
98 expect(error.code, RequestErrorCode.INVALID_REQUEST); 99 expect(error.code, RequestErrorCode.INVALID_REQUEST);
99 expect(error.message, "msg"); 100 expect(error.message, "msg");
100 expect(error.toJson(), equals({ 101 expect(error.toJson(), equals({
101 RequestError.CODE: 'INVALID_REQUEST', 102 CODE: 'INVALID_REQUEST',
102 RequestError.MESSAGE: "msg" 103 MESSAGE: "msg"
103 })); 104 }));
104 } 105 }
105 106
106 void test_create_serverAlreadyStarted() {
107 RequestError error = new RequestError.serverAlreadyStarted();
108 expect(error.code, RequestErrorCode.SERVER_ALREADY_STARTED);
109 expect(error.message, "Server already started");
110 }
111
112 void test_fromJson() { 107 void test_fromJson() {
113 var json = { 108 var json = {
114 RequestError.CODE: RequestErrorCode.INVALID_PARAMETER.name, 109 CODE: RequestErrorCode.INVALID_PARAMETER.name,
115 RequestError.MESSAGE: 'foo', 110 MESSAGE: 'foo',
116 RequestError.DATA: { 111 DATA: {
117 'ints': [1, 2, 3] 112 'ints': [1, 2, 3]
118 } 113 }
119 }; 114 };
120 RequestError error = new RequestError.fromJson(json); 115 RequestError error = new RequestError.fromJson(new ResponseDecoder(), '',
116 json);
121 expect(error.code, RequestErrorCode.INVALID_PARAMETER); 117 expect(error.code, RequestErrorCode.INVALID_PARAMETER);
122 expect(error.message, "foo"); 118 expect(error.message, "foo");
123 expect(error.data['ints'], [1, 2, 3]); 119 expect(error.data['ints'], [1, 2, 3]);
124 expect(error.getData('ints'), [1, 2, 3]);
125 } 120 }
126 121
127 void test_toJson() { 122 void test_toJson() {
128 RequestError error = new RequestError(RequestErrorCode.UNKNOWN_REQUEST, 'msg '); 123 RequestError error = new RequestError(
129 error.setData('answer', 42); 124 RequestErrorCode.UNKNOWN_REQUEST, 'msg', data: {});
130 error.setData('question', 'unknown'); 125 error.data['answer'] = 42;
126 error.data['question'] = 'unknown';
131 expect(error.toJson(), { 127 expect(error.toJson(), {
132 RequestError.CODE: 'UNKNOWN_REQUEST', 128 CODE: 'UNKNOWN_REQUEST',
133 RequestError.MESSAGE: 'msg', 129 MESSAGE: 'msg',
134 RequestError.DATA: { 130 DATA: {
135 'answer': 42, 131 'answer': 42,
136 'question': 'unknown' 132 'question': 'unknown'
137 } 133 }
138 }); 134 });
139 } 135 }
140 } 136 }
141 137
142 138
143 @ReflectiveTestCase() 139 @ReflectiveTestCase()
144 class RequestTest { 140 class RequestTest {
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 256
261 void test_fromJson_withResult() { 257 void test_fromJson_withResult() {
262 Response original = new Response('myId', result: {'foo': 'bar'}); 258 Response original = new Response('myId', result: {'foo': 'bar'});
263 Response response = new Response.fromJson(original.toJson()); 259 Response response = new Response.fromJson(original.toJson());
264 expect(response.id, equals('myId')); 260 expect(response.id, equals('myId'));
265 Map<String, Object> result = response.toJson()['result']; 261 Map<String, Object> result = response.toJson()['result'];
266 expect(result.length, equals(1)); 262 expect(result.length, equals(1));
267 expect(result['foo'], equals('bar')); 263 expect(result['foo'], equals('bar'));
268 } 264 }
269 } 265 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/test/integration/protocol_matchers.dart ('k') | pkg/analysis_server/tool/spec/api.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698