OLD | NEW |
---|---|
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 'package:analysis_server/src/protocol.dart'; | 7 import 'package:analysis_server/src/protocol.dart'; |
8 import 'package:unittest/matcher.dart'; | 8 import 'package:unittest/matcher.dart'; |
9 import 'package:unittest/unittest.dart'; | 9 import 'package:unittest/unittest.dart'; |
10 import 'dart:convert'; | 10 import 'dart:convert'; |
11 | 11 |
12 main() { | 12 main() { |
13 group('Notification', () { | 13 group('Notification', () { |
14 test('getParameter_defined', NotificationTest.getParameter_defined); | 14 test('getParameter_defined', NotificationTest.getParameter_defined); |
15 test('getParameter_undefined', NotificationTest.getParameter_undefined); | 15 test('getParameter_undefined', NotificationTest.getParameter_undefined); |
16 test('fromJson', NotificationTest.fromJson); | 16 test('fromJson', NotificationTest.fromJson); |
17 test('fromJson_withParams', NotificationTest.fromJson_withParams); | 17 test('fromJson_withParams', NotificationTest.fromJson_withParams); |
18 }); | 18 }); |
19 group('Request', () { | 19 group('Request', () { |
20 test('getParameter_defined', RequestTest.getParameter_defined); | 20 test('getParameter_defined', RequestTest.getParameter_defined); |
21 test('getParameter_undefined', RequestTest.getParameter_undefined); | 21 test('getParameter_undefined', RequestTest.getParameter_undefined); |
22 test('getRequiredParameter_defined', RequestTest.getRequiredParameter_define d); | 22 test('getRequiredParameter_defined', RequestTest.getRequiredParameter_define d); |
23 test('getRequiredParameter_undefined', RequestTest.getRequiredParameter_unde fined); | 23 test('getRequiredParameter_undefined', RequestTest.getRequiredParameter_unde fined); |
24 test('fromJson', RequestTest.fromJson); | 24 test('fromJson', RequestTest.fromJson); |
25 test('fromJson_invalidId', RequestTest.fromJson_invalidId); | |
26 test('fromJson_invalidMethod', RequestTest.fromJson_invalidMethod); | |
25 test('fromJson_withParams', RequestTest.fromJson_withParams); | 27 test('fromJson_withParams', RequestTest.fromJson_withParams); |
26 test('toJson', RequestTest.toJson); | 28 test('toJson', RequestTest.toJson); |
27 test('toJson_withParams', RequestTest.toJson_withParams); | 29 test('toJson_withParams', RequestTest.toJson_withParams); |
28 }); | 30 }); |
29 group('Response', () { | 31 group('Response', () { |
30 test('create_contextDoesNotExist', ResponseTest.create_contextDoesNotExist); | 32 test('create_contextDoesNotExist', ResponseTest.create_contextDoesNotExist); |
31 test('create_invalidRequestFormat', ResponseTest.create_invalidRequestFormat ); | 33 test('create_invalidRequestFormat', ResponseTest.create_invalidRequestFormat ); |
32 test('create_missingRequiredParameter', ResponseTest.create_missingRequiredP arameter); | 34 test('create_missingRequiredParameter', ResponseTest.create_missingRequiredP arameter); |
33 test('create_unknownRequest', ResponseTest.create_unknownRequest); | 35 test('create_unknownRequest', ResponseTest.create_unknownRequest); |
34 test('setResult', ResponseTest.setResult); | 36 test('setResult', ResponseTest.setResult); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
109 } | 111 } |
110 | 112 |
111 static void fromJson() { | 113 static void fromJson() { |
112 Request original = new Request('one', 'aMethod'); | 114 Request original = new Request('one', 'aMethod'); |
113 String json = new JsonEncoder(null).convert(original.toJson()); | 115 String json = new JsonEncoder(null).convert(original.toJson()); |
114 Request request = new Request.fromString(json); | 116 Request request = new Request.fromString(json); |
115 expect(request.id, equals('one')); | 117 expect(request.id, equals('one')); |
116 expect(request.method, equals('aMethod')); | 118 expect(request.method, equals('aMethod')); |
117 } | 119 } |
118 | 120 |
121 static void fromJson_invalidId() { | |
122 String json = '{"id":{"one":"two"},"method":"aMethod","params":{"foo":"bar"} }'; | |
123 Request request = new Request.fromString(json); | |
124 expect(request, isNull); | |
125 } | |
126 | |
127 static void fromJson_invalidMethod() { | |
Brian Wilkerson
2014/03/05 16:15:16
It would be good to have a test "fromJson_invalidP
danrubel
2014/03/05 18:39:07
Done.
| |
128 String json = '{"id":"one","method":{"boo":"aMethod"},"params":{"foo":"bar"} }'; | |
129 Request request = new Request.fromString(json); | |
130 expect(request, isNull); | |
131 } | |
132 | |
119 static void fromJson_withParams() { | 133 static void fromJson_withParams() { |
120 Request original = new Request('one', 'aMethod'); | 134 Request original = new Request('one', 'aMethod'); |
121 original.setParameter('foo', 'bar'); | 135 original.setParameter('foo', 'bar'); |
122 String json = new JsonEncoder(null).convert(original.toJson()); | 136 String json = new JsonEncoder(null).convert(original.toJson()); |
123 Request request = new Request.fromString(json); | 137 Request request = new Request.fromString(json); |
124 expect(request.id, equals('one')); | 138 expect(request.id, equals('one')); |
125 expect(request.method, equals('aMethod')); | 139 expect(request.method, equals('aMethod')); |
126 expect(request.getParameter('foo'), equals('bar')); | 140 expect(request.getParameter('foo'), equals('bar')); |
127 } | 141 } |
128 | 142 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
219 static void fromJson_withResult() { | 233 static void fromJson_withResult() { |
220 Response original = new Response('myId'); | 234 Response original = new Response('myId'); |
221 original.setResult('foo', 'bar'); | 235 original.setResult('foo', 'bar'); |
222 Response response = new Response.fromJson(original.toJson()); | 236 Response response = new Response.fromJson(original.toJson()); |
223 expect(response.id, equals('myId')); | 237 expect(response.id, equals('myId')); |
224 Map<String, Object> result = response.result; | 238 Map<String, Object> result = response.result; |
225 expect(result.length, equals(1)); | 239 expect(result.length, equals(1)); |
226 expect(result['foo'], equals('bar')); | 240 expect(result['foo'], equals('bar')); |
227 } | 241 } |
228 } | 242 } |
OLD | NEW |