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

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

Issue 506433002: Finish modifying analysis server to make use of code generation. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 4 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/protocol.dart'; 9 import 'package:analysis_server/src/protocol.dart';
10 import 'package:analysis_server/src/services/json.dart';
11 import 'package:analysis_testing/reflective_tests.dart'; 10 import 'package:analysis_testing/reflective_tests.dart';
12 import 'package:unittest/unittest.dart'; 11 import 'package:unittest/unittest.dart';
13 12
14 13
15 Matcher _throwsRequestFailure = throwsA(new isInstanceOf<RequestFailure>()); 14 Matcher _throwsRequestFailure = throwsA(new isInstanceOf<RequestFailure>());
16 15
17 16
18 main() { 17 main() {
19 groupSep = ' | '; 18 groupSep = ' | ';
20 runReflectiveTests(NotificationTest); 19 runReflectiveTests(NotificationTest);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 } 51 }
53 } 52 }
54 53
55 54
56 @ReflectiveTestCase() 55 @ReflectiveTestCase()
57 class NotificationTest { 56 class NotificationTest {
58 void test_fromJson() { 57 void test_fromJson() {
59 Notification original = new Notification('foo'); 58 Notification original = new Notification('foo');
60 Notification notification = new Notification.fromJson(original.toJson()); 59 Notification notification = new Notification.fromJson(original.toJson());
61 expect(notification.event, equals('foo')); 60 expect(notification.event, equals('foo'));
62 expect(notification.params, isNull); 61 expect(notification.toJson().keys, isNot(contains('params')));
63 } 62 }
64 63
65 void test_fromJson_withParams() { 64 void test_fromJson_withParams() {
66 Notification original = new Notification('foo'); 65 Notification original = new Notification('foo', {'x': 'y'});
67 original.setParameter('x', 'y');
68 Notification notification = new Notification.fromJson(original.toJson()); 66 Notification notification = new Notification.fromJson(original.toJson());
69 expect(notification.event, equals('foo')); 67 expect(notification.event, equals('foo'));
70 expect(notification.params, equals({'x': 'y'})); 68 expect(notification.toJson()['params'], equals({'x': 'y'}));
71 } 69 }
72 70
73 void test_toJson_withParams() { 71 void test_toJson_withParams() {
74 Notification notification = new Notification('foo'); 72 Notification notification = new Notification('foo', {'x': 'y'});
75 notification.setParameter('x', 'y');
76 expect(notification.event, equals('foo')); 73 expect(notification.event, equals('foo'));
77 expect(notification.params, equals({'x': 'y'})); 74 expect(notification.toJson()['params'], equals({'x': 'y'}));
78 expect(notification.toJson(), equals({ 75 expect(notification.toJson(), equals({
79 'event': 'foo', 76 'event': 'foo',
80 'params': { 77 'params': {
81 'x': 'y' 78 'x': 'y'
82 } 79 }
83 })); 80 }));
84 } 81 }
85 82
86 void test_toJson_noParams() { 83 void test_toJson_noParams() {
87 Notification notification = new Notification('foo'); 84 Notification notification = new Notification('foo');
88 expect(notification.event, equals('foo')); 85 expect(notification.event, equals('foo'));
89 expect(notification.params, isNull); 86 expect(notification.toJson().keys, isNot(contains('params')));
90 expect(notification.toJson(), equals({ 87 expect(notification.toJson(), equals({
91 'event': 'foo' 88 'event': 'foo'
92 })); 89 }));
93 } 90 }
94
95 void test_setParameter_HasToJson() {
96 Notification notification = new Notification('foo');
97 notification.setParameter('my', new _MyHasToJsonObject(42));
98 expect(notification.toJson(), equals({
99 'event': 'foo',
100 'params': {
101 'my': {
102 'offset': 42
103 }
104 }
105 }));
106 }
107
108 void test_setParameter_Iterable_HasToJson() {
109 Notification notification = new Notification('foo');
110 notification.setParameter('my', [
111 new _MyHasToJsonObject(1),
112 new _MyHasToJsonObject(2),
113 new _MyHasToJsonObject(3)]);
114 expect(notification.toJson(), equals({
115 'event': 'foo',
116 'params': {
117 'my': [{'offset': 1}, {'offset': 2}, {'offset': 3}]
118 }
119 }));
120 }
121 } 91 }
122 92
123 93
124 class _MyHasToJsonObject implements HasToJson {
125 int offset;
126 _MyHasToJsonObject(this.offset);
127 Map<String, Object> toJson() => {'offset': offset};
128 }
129
130
131 @ReflectiveTestCase() 94 @ReflectiveTestCase()
132 class RequestErrorTest { 95 class RequestErrorTest {
133 void test_create() { 96 void test_create() {
134 RequestError error = new RequestError('ERROR_CODE', 'msg'); 97 RequestError error = new RequestError('ERROR_CODE', 'msg');
135 expect(error.code, 'ERROR_CODE'); 98 expect(error.code, 'ERROR_CODE');
136 expect(error.message, "msg"); 99 expect(error.message, "msg");
137 expect(error.toJson(), equals({ 100 expect(error.toJson(), equals({
138 RequestError.CODE: 'ERROR_CODE', 101 RequestError.CODE: 'ERROR_CODE',
139 RequestError.MESSAGE: "msg" 102 RequestError.MESSAGE: "msg"
140 })); 103 }));
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 Request request = new Request.fromString(json); 199 Request request = new Request.fromString(json);
237 expect(request, isNull); 200 expect(request, isNull);
238 } 201 }
239 202
240 void test_fromJson_withParams() { 203 void test_fromJson_withParams() {
241 Request original = new Request('one', 'aMethod', {'foo': 'bar'}); 204 Request original = new Request('one', 'aMethod', {'foo': 'bar'});
242 String json = JSON.encode(original.toJson()); 205 String json = JSON.encode(original.toJson());
243 Request request = new Request.fromString(json); 206 Request request = new Request.fromString(json);
244 expect(request.id, equals('one')); 207 expect(request.id, equals('one'));
245 expect(request.method, equals('aMethod')); 208 expect(request.method, equals('aMethod'));
246 expect(request.params, equals({'foo': 'bar'})); 209 expect(request.toJson()['params'], equals({'foo': 'bar'}));
247 } 210 }
248 211
249 void test_toJson() { 212 void test_toJson() {
250 Request request = new Request('one', 'aMethod'); 213 Request request = new Request('one', 'aMethod');
251 expect(request.toJson(), equals({ 214 expect(request.toJson(), equals({
252 Request.ID: 'one', 215 Request.ID: 'one',
253 Request.METHOD: 'aMethod' 216 Request.METHOD: 'aMethod'
254 })); 217 }));
255 } 218 }
256 219
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 expect(response.error, isNotNull); 326 expect(response.error, isNotNull);
364 RequestError error = response.error; 327 RequestError error = response.error;
365 expect(error.code, equals('INVALID_REQUEST')); 328 expect(error.code, equals('INVALID_REQUEST'));
366 expect(error.message, equals('Invalid request')); 329 expect(error.message, equals('Invalid request'));
367 } 330 }
368 331
369 void test_fromJson_withResult() { 332 void test_fromJson_withResult() {
370 Response original = new Response('myId', result: {'foo': 'bar'}); 333 Response original = new Response('myId', result: {'foo': 'bar'});
371 Response response = new Response.fromJson(original.toJson()); 334 Response response = new Response.fromJson(original.toJson());
372 expect(response.id, equals('myId')); 335 expect(response.id, equals('myId'));
373 Map<String, Object> result = response.result; 336 Map<String, Object> result = response.toJson()['result'];
374 expect(result.length, equals(1)); 337 expect(result.length, equals(1));
375 expect(result['foo'], equals('bar')); 338 expect(result['foo'], equals('bar'));
376 } 339 }
377 } 340 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/test/edit/refactoring_test.dart ('k') | pkg/analysis_server/test/search/abstract_search_domain.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698