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

Side by Side Diff: pkg/json_rpc_2/test/server/server_test.dart

Issue 207323004: Make the json_rpc_2 server test dart2js-compatible. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 9 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 json_rpc_2.test.server.server_test; 5 library json_rpc_2.test.server.server_test;
6 6
7 import 'dart:convert'; 7 import 'dart:convert';
8 8
9 import 'package:unittest/unittest.dart'; 9 import 'package:unittest/unittest.dart';
10 import 'package:json_rpc_2/error_code.dart' as error_code; 10 import 'package:json_rpc_2/error_code.dart' as error_code;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 'id': 1234 69 'id': 1234
70 }), completion({ 70 }), completion({
71 'jsonrpc': '2.0', 71 'jsonrpc': '2.0',
72 'id': 1234, 72 'id': 1234,
73 'error': { 73 'error': {
74 'code': error_code.SERVER_ERROR, 74 'code': error_code.SERVER_ERROR,
75 'message': 'bad format', 75 'message': 'bad format',
76 'data': { 76 'data': {
77 'request': {'jsonrpc': '2.0', 'method': 'foo', 'id': 1234}, 77 'request': {'jsonrpc': '2.0', 'method': 'foo', 'id': 1234},
78 'full': 'FormatException: bad format', 78 'full': 'FormatException: bad format',
79 'stack': contains('server_test.dart') 79 'stack': new isInstanceOf<String>()
80 } 80 }
81 } 81 }
82 })); 82 }));
83 }); 83 });
84 84
85 test("doesn't return a result for a notification", () { 85 test("doesn't return a result for a notification", () {
86 server.registerMethod('foo', (args) => 'result'); 86 server.registerMethod('foo', (args) => 'result');
87 87
88 expect(server.handleRequest({ 88 expect(server.handleRequest({
89 'jsonrpc': '2.0', 89 'jsonrpc': '2.0',
(...skipping 26 matching lines...) Expand all
116 }); 116 });
117 117
118 expect(server.parseRequest(JSON.encode({ 118 expect(server.parseRequest(JSON.encode({
119 'jsonrpc': '2.0', 119 'jsonrpc': '2.0',
120 'method': 'foo', 120 'method': 'foo',
121 'params': {'param': 'value'} 121 'params': {'param': 'value'}
122 })), completion(isNull)); 122 })), completion(isNull));
123 }); 123 });
124 124
125 test("a JSON parse error is rejected", () { 125 test("a JSON parse error is rejected", () {
126 expect(server.parseRequest('invalid json {'), 126 return server.parseRequest('invalid json {').then((result) {
127 completion(equals(JSON.encode({ 127 expect(JSON.decode(result), {
128 'jsonrpc': '2.0', 128 'jsonrpc': '2.0',
129 'error': { 129 'error': {
130 'code': error_code.PARSE_ERROR, 130 'code': error_code.PARSE_ERROR,
131 'message': "Invalid JSON: Unexpected character at 0: 'invalid json " 131 'message': startsWith("Invalid JSON: "),
132 "{'", 132 'data': {'request': 'invalid json {'}
133 'data': {'request': 'invalid json {'} 133 },
134 }, 134 'id': null
135 'id': null 135 });
136 })))); 136 });
137 }); 137 });
138 }); 138 });
139 139
140 group("fallbacks", () { 140 group("fallbacks", () {
141 test("calls a fallback if no method matches", () { 141 test("calls a fallback if no method matches", () {
142 server.registerMethod('foo', () => 'foo'); 142 server.registerMethod('foo', () => 'foo');
143 server.registerMethod('bar', () => 'foo'); 143 server.registerMethod('bar', () => 'foo');
144 server.registerFallback((params) => {'fallback': params.value}); 144 server.registerFallback((params) => {'fallback': params.value});
145 145
146 expect(server.handleRequest({ 146 expect(server.handleRequest({
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 'id': 1234 182 'id': 1234
183 }), completion({ 183 }), completion({
184 'jsonrpc': '2.0', 184 'jsonrpc': '2.0',
185 'id': 1234, 185 'id': 1234,
186 'error': { 186 'error': {
187 'code': error_code.SERVER_ERROR, 187 'code': error_code.SERVER_ERROR,
188 'message': 'bad format', 188 'message': 'bad format',
189 'data': { 189 'data': {
190 'request': {'jsonrpc': '2.0', 'method': 'foo', 'id': 1234}, 190 'request': {'jsonrpc': '2.0', 'method': 'foo', 'id': 1234},
191 'full': 'FormatException: bad format', 191 'full': 'FormatException: bad format',
192 'stack': contains('server_test.dart') 192 'stack': new isInstanceOf<String>()
193 } 193 }
194 } 194 }
195 })); 195 }));
196 }); 196 });
197 }); 197 });
198 198
199 test("disallows multiple methods with the same name", () { 199 test("disallows multiple methods with the same name", () {
200 server.registerMethod('foo', () => null); 200 server.registerMethod('foo', () => null);
201 expect(() => server.registerMethod('foo', () => null), throwsArgumentError); 201 expect(() => server.registerMethod('foo', () => null), throwsArgumentError);
202 }); 202 });
203 } 203 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698