| 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); |
| 27 test('fromJson_invalidParams', RequestTest.fromJson_invalidParams); |
| 25 test('fromJson_withParams', RequestTest.fromJson_withParams); | 28 test('fromJson_withParams', RequestTest.fromJson_withParams); |
| 26 test('toJson', RequestTest.toJson); | 29 test('toJson', RequestTest.toJson); |
| 27 test('toJson_withParams', RequestTest.toJson_withParams); | 30 test('toJson_withParams', RequestTest.toJson_withParams); |
| 28 }); | 31 }); |
| 29 group('Response', () { | 32 group('Response', () { |
| 30 test('create_contextDoesNotExist', ResponseTest.create_contextDoesNotExist); | 33 test('create_contextDoesNotExist', ResponseTest.create_contextDoesNotExist); |
| 31 test('create_invalidRequestFormat', ResponseTest.create_invalidRequestFormat
); | 34 test('create_invalidRequestFormat', ResponseTest.create_invalidRequestFormat
); |
| 32 test('create_missingRequiredParameter', ResponseTest.create_missingRequiredP
arameter); | 35 test('create_missingRequiredParameter', ResponseTest.create_missingRequiredP
arameter); |
| 33 test('create_unknownRequest', ResponseTest.create_unknownRequest); | 36 test('create_unknownRequest', ResponseTest.create_unknownRequest); |
| 34 test('setResult', ResponseTest.setResult); | 37 test('setResult', ResponseTest.setResult); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 } | 112 } |
| 110 | 113 |
| 111 static void fromJson() { | 114 static void fromJson() { |
| 112 Request original = new Request('one', 'aMethod'); | 115 Request original = new Request('one', 'aMethod'); |
| 113 String json = new JsonEncoder(null).convert(original.toJson()); | 116 String json = new JsonEncoder(null).convert(original.toJson()); |
| 114 Request request = new Request.fromString(json); | 117 Request request = new Request.fromString(json); |
| 115 expect(request.id, equals('one')); | 118 expect(request.id, equals('one')); |
| 116 expect(request.method, equals('aMethod')); | 119 expect(request.method, equals('aMethod')); |
| 117 } | 120 } |
| 118 | 121 |
| 122 static void fromJson_invalidId() { |
| 123 String json = '{"id":{"one":"two"},"method":"aMethod","params":{"foo":"bar"}
}'; |
| 124 Request request = new Request.fromString(json); |
| 125 expect(request, isNull); |
| 126 } |
| 127 |
| 128 static void fromJson_invalidMethod() { |
| 129 String json = '{"id":"one","method":{"boo":"aMethod"},"params":{"foo":"bar"}
}'; |
| 130 Request request = new Request.fromString(json); |
| 131 expect(request, isNull); |
| 132 } |
| 133 |
| 134 static void fromJson_invalidParams() { |
| 135 String json = '{"id":"one","method":"aMethod","params":"foobar"}'; |
| 136 Request request = new Request.fromString(json); |
| 137 expect(request, isNull); |
| 138 } |
| 139 |
| 119 static void fromJson_withParams() { | 140 static void fromJson_withParams() { |
| 120 Request original = new Request('one', 'aMethod'); | 141 Request original = new Request('one', 'aMethod'); |
| 121 original.setParameter('foo', 'bar'); | 142 original.setParameter('foo', 'bar'); |
| 122 String json = new JsonEncoder(null).convert(original.toJson()); | 143 String json = new JsonEncoder(null).convert(original.toJson()); |
| 123 Request request = new Request.fromString(json); | 144 Request request = new Request.fromString(json); |
| 124 expect(request.id, equals('one')); | 145 expect(request.id, equals('one')); |
| 125 expect(request.method, equals('aMethod')); | 146 expect(request.method, equals('aMethod')); |
| 126 expect(request.getParameter('foo'), equals('bar')); | 147 expect(request.getParameter('foo'), equals('bar')); |
| 127 } | 148 } |
| 128 | 149 |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 static void fromJson_withResult() { | 240 static void fromJson_withResult() { |
| 220 Response original = new Response('myId'); | 241 Response original = new Response('myId'); |
| 221 original.setResult('foo', 'bar'); | 242 original.setResult('foo', 'bar'); |
| 222 Response response = new Response.fromJson(original.toJson()); | 243 Response response = new Response.fromJson(original.toJson()); |
| 223 expect(response.id, equals('myId')); | 244 expect(response.id, equals('myId')); |
| 224 Map<String, Object> result = response.result; | 245 Map<String, Object> result = response.result; |
| 225 expect(result.length, equals(1)); | 246 expect(result.length, equals(1)); |
| 226 expect(result['foo'], equals('bar')); | 247 expect(result['foo'], equals('bar')); |
| 227 } | 248 } |
| 228 } | 249 } |
| OLD | NEW |