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

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

Issue 497393002: Make more use of generated code in analysis server. (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/protocol.dart'; 9 import 'package:analysis_server/src/protocol.dart';
10 import 'package:analysis_server/src/services/json.dart'; 10 import 'package:analysis_server/src/services/json.dart';
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 } 52 }
53 } 53 }
54 54
55 55
56 @ReflectiveTestCase() 56 @ReflectiveTestCase()
57 class NotificationTest { 57 class NotificationTest {
58 void test_fromJson() { 58 void test_fromJson() {
59 Notification original = new Notification('foo'); 59 Notification original = new Notification('foo');
60 Notification notification = new Notification.fromJson(original.toJson()); 60 Notification notification = new Notification.fromJson(original.toJson());
61 expect(notification.event, equals('foo')); 61 expect(notification.event, equals('foo'));
62 expect(notification.params.length, equals(0)); 62 expect(notification.params, isNull);
63 expect(notification.getParameter('x'), isNull);
64 } 63 }
65 64
66 void test_fromJson_withParams() { 65 void test_fromJson_withParams() {
67 Notification original = new Notification('foo'); 66 Notification original = new Notification('foo');
68 original.setParameter('x', 'y'); 67 original.setParameter('x', 'y');
69 Notification notification = new Notification.fromJson(original.toJson()); 68 Notification notification = new Notification.fromJson(original.toJson());
70 expect(notification.event, equals('foo')); 69 expect(notification.event, equals('foo'));
71 expect(notification.params.length, equals(1)); 70 expect(notification.params, equals({'x': 'y'}));
72 expect(notification.getParameter('x'), equals('y'));
73 } 71 }
74 72
75 void test_getParameter_defined() { 73 void test_toJson_withParams() {
76 Notification notification = new Notification('foo'); 74 Notification notification = new Notification('foo');
77 notification.setParameter('x', 'y'); 75 notification.setParameter('x', 'y');
78 expect(notification.event, equals('foo')); 76 expect(notification.event, equals('foo'));
79 expect(notification.params.length, equals(1)); 77 expect(notification.params, equals({'x': 'y'}));
80 expect(notification.getParameter('x'), equals('y'));
81 expect(notification.toJson(), equals({ 78 expect(notification.toJson(), equals({
82 'event': 'foo', 79 'event': 'foo',
83 'params': { 80 'params': {
84 'x': 'y' 81 'x': 'y'
85 } 82 }
86 })); 83 }));
87 } 84 }
88 85
89 void test_getParameter_undefined() { 86 void test_toJson_noParams() {
90 Notification notification = new Notification('foo'); 87 Notification notification = new Notification('foo');
91 expect(notification.event, equals('foo')); 88 expect(notification.event, equals('foo'));
92 expect(notification.params.length, equals(0)); 89 expect(notification.params, isNull);
93 expect(notification.getParameter('x'), isNull);
94 expect(notification.toJson(), equals({ 90 expect(notification.toJson(), equals({
95 'event': 'foo' 91 'event': 'foo'
96 })); 92 }));
97 } 93 }
98 94
99 void test_setParameter_HasToJson() { 95 void test_setParameter_HasToJson() {
100 Notification notification = new Notification('foo'); 96 Notification notification = new Notification('foo');
101 notification.setParameter('my', new _MyHasToJsonObject(42)); 97 notification.setParameter('my', new _MyHasToJsonObject(42));
102 expect(notification.toJson(), equals({ 98 expect(notification.toJson(), equals({
103 'event': 'foo', 99 'event': 'foo',
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 Response original = new Response.invalidRequestFormat(); 360 Response original = new Response.invalidRequestFormat();
365 Response response = new Response.fromJson(original.toJson()); 361 Response response = new Response.fromJson(original.toJson());
366 expect(response.id, equals('')); 362 expect(response.id, equals(''));
367 expect(response.error, isNotNull); 363 expect(response.error, isNotNull);
368 RequestError error = response.error; 364 RequestError error = response.error;
369 expect(error.code, equals('INVALID_REQUEST')); 365 expect(error.code, equals('INVALID_REQUEST'));
370 expect(error.message, equals('Invalid request')); 366 expect(error.message, equals('Invalid request'));
371 } 367 }
372 368
373 void test_fromJson_withResult() { 369 void test_fromJson_withResult() {
374 Response original = new Response('myId'); 370 Response original = new Response('myId', result: {'foo': 'bar'});
375 original.setResult('foo', 'bar');
376 Response response = new Response.fromJson(original.toJson()); 371 Response response = new Response.fromJson(original.toJson());
377 expect(response.id, equals('myId')); 372 expect(response.id, equals('myId'));
378 Map<String, Object> result = response.result; 373 Map<String, Object> result = response.result;
379 expect(result.length, equals(1)); 374 expect(result.length, equals(1));
380 expect(result['foo'], equals('bar')); 375 expect(result['foo'], equals('bar'));
381 } 376 }
382
383 void test_setResult() {
384 String resultName = 'name';
385 String resultValue = 'value';
386 Response response = new Response('0');
387 response.setResult(resultName, resultValue);
388 expect(response.result[resultName], same(resultValue));
389 expect(response.toJson(), equals({
390 Response.ID: '0',
391 Response.RESULT: {
392 resultName: resultValue
393 }
394 }));
395 }
396 } 377 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698