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'; |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 } | 106 } |
107 | 107 |
108 static void getRequiredParameter_undefined() { | 108 static void getRequiredParameter_undefined() { |
109 String name = 'name'; | 109 String name = 'name'; |
110 Request request = new Request('0', ''); | 110 Request request = new Request('0', ''); |
111 expect(() => request.getRequiredParameter(name), throwsA(new isInstanceOf<Re
questFailure>())); | 111 expect(() => request.getRequiredParameter(name), throwsA(new isInstanceOf<Re
questFailure>())); |
112 } | 112 } |
113 | 113 |
114 static void fromJson() { | 114 static void fromJson() { |
115 Request original = new Request('one', 'aMethod'); | 115 Request original = new Request('one', 'aMethod'); |
116 String json = new JsonEncoder(null).convert(original.toJson()); | 116 String json = JSON.encode(original.toJson()); |
117 Request request = new Request.fromString(json); | 117 Request request = new Request.fromString(json); |
118 expect(request.id, equals('one')); | 118 expect(request.id, equals('one')); |
119 expect(request.method, equals('aMethod')); | 119 expect(request.method, equals('aMethod')); |
120 } | 120 } |
121 | 121 |
122 static void fromJson_invalidId() { | 122 static void fromJson_invalidId() { |
123 String json = '{"id":{"one":"two"},"method":"aMethod","params":{"foo":"bar"}
}'; | 123 String json = '{"id":{"one":"two"},"method":"aMethod","params":{"foo":"bar"}
}'; |
124 Request request = new Request.fromString(json); | 124 Request request = new Request.fromString(json); |
125 expect(request, isNull); | 125 expect(request, isNull); |
126 } | 126 } |
127 | 127 |
128 static void fromJson_invalidMethod() { | 128 static void fromJson_invalidMethod() { |
129 String json = '{"id":"one","method":{"boo":"aMethod"},"params":{"foo":"bar"}
}'; | 129 String json = '{"id":"one","method":{"boo":"aMethod"},"params":{"foo":"bar"}
}'; |
130 Request request = new Request.fromString(json); | 130 Request request = new Request.fromString(json); |
131 expect(request, isNull); | 131 expect(request, isNull); |
132 } | 132 } |
133 | 133 |
134 static void fromJson_invalidParams() { | 134 static void fromJson_invalidParams() { |
135 String json = '{"id":"one","method":"aMethod","params":"foobar"}'; | 135 String json = '{"id":"one","method":"aMethod","params":"foobar"}'; |
136 Request request = new Request.fromString(json); | 136 Request request = new Request.fromString(json); |
137 expect(request, isNull); | 137 expect(request, isNull); |
138 } | 138 } |
139 | 139 |
140 static void fromJson_withParams() { | 140 static void fromJson_withParams() { |
141 Request original = new Request('one', 'aMethod'); | 141 Request original = new Request('one', 'aMethod'); |
142 original.setParameter('foo', 'bar'); | 142 original.setParameter('foo', 'bar'); |
143 String json = new JsonEncoder(null).convert(original.toJson()); | 143 String json = JSON.encode(original.toJson()); |
144 Request request = new Request.fromString(json); | 144 Request request = new Request.fromString(json); |
145 expect(request.id, equals('one')); | 145 expect(request.id, equals('one')); |
146 expect(request.method, equals('aMethod')); | 146 expect(request.method, equals('aMethod')); |
147 expect(request.getParameter('foo'), equals('bar')); | 147 expect(request.getParameter('foo'), equals('bar')); |
148 } | 148 } |
149 | 149 |
150 static void toJson() { | 150 static void toJson() { |
151 Request request = new Request('one', 'aMethod'); | 151 Request request = new Request('one', 'aMethod'); |
152 expect(request.toJson(), equals({ | 152 expect(request.toJson(), equals({ |
153 Request.ID : 'one', | 153 Request.ID : 'one', |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 static void fromJson_withResult() { | 240 static void fromJson_withResult() { |
241 Response original = new Response('myId'); | 241 Response original = new Response('myId'); |
242 original.setResult('foo', 'bar'); | 242 original.setResult('foo', 'bar'); |
243 Response response = new Response.fromJson(original.toJson()); | 243 Response response = new Response.fromJson(original.toJson()); |
244 expect(response.id, equals('myId')); | 244 expect(response.id, equals('myId')); |
245 Map<String, Object> result = response.result; | 245 Map<String, Object> result = response.result; |
246 expect(result.length, equals(1)); | 246 expect(result.length, equals(1)); |
247 expect(result['foo'], equals('bar')); | 247 expect(result['foo'], equals('bar')); |
248 } | 248 } |
249 } | 249 } |
OLD | NEW |