| 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 json_rpc_2.test.server.parameters_test; | 5 library json_rpc_2.test.server.parameters_test; |
| 6 | 6 |
| 7 import 'package:unittest/unittest.dart'; | 7 import 'package:unittest/unittest.dart'; |
| 8 import 'package:json_rpc_2/json_rpc_2.dart' as json_rpc; | 8 import 'package:json_rpc_2/json_rpc_2.dart' as json_rpc; |
| 9 | 9 |
| 10 import 'utils.dart'; | 10 import 'utils.dart'; |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 | 222 |
| 223 test("[].asDateTime fails for non-date/time parameters", () { | 223 test("[].asDateTime fails for non-date/time parameters", () { |
| 224 expect(() => parameters['int'].asDateTime, | 224 expect(() => parameters['int'].asDateTime, |
| 225 throwsInvalidParams('Parameter "int" for method "foo" must be a ' | 225 throwsInvalidParams('Parameter "int" for method "foo" must be a ' |
| 226 'string, but was 1.')); | 226 'string, but was 1.')); |
| 227 }); | 227 }); |
| 228 | 228 |
| 229 test("[].asDateTime fails for invalid date/times", () { | 229 test("[].asDateTime fails for invalid date/times", () { |
| 230 expect(() => parameters['string'].asDateTime, | 230 expect(() => parameters['string'].asDateTime, |
| 231 throwsInvalidParams('Parameter "string" for method "foo" must be a ' | 231 throwsInvalidParams('Parameter "string" for method "foo" must be a ' |
| 232 'valid date/time, but was "zap".')); | 232 'valid date/time, but was "zap".\n' |
| 233 'Invalid date format')); |
| 233 }); | 234 }); |
| 234 | 235 |
| 235 test("[].asUri returns URI parameters", () { | 236 test("[].asUri returns URI parameters", () { |
| 236 expect(parameters['uri'].asUri, equals(Uri.parse('http://dartlang.org'))); | 237 expect(parameters['uri'].asUri, equals(Uri.parse('http://dartlang.org'))); |
| 237 }); | 238 }); |
| 238 | 239 |
| 239 test("[].asUriOr returns URI parameters", () { | 240 test("[].asUriOr returns URI parameters", () { |
| 240 expect(parameters['uri'].asUriOr(Uri.parse('http://google.com')), | 241 expect(parameters['uri'].asUriOr(Uri.parse('http://google.com')), |
| 241 equals(Uri.parse('http://dartlang.org'))); | 242 equals(Uri.parse('http://dartlang.org'))); |
| 242 }); | 243 }); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 255 test("[].asUri fails for non-URI parameters", () { | 256 test("[].asUri fails for non-URI parameters", () { |
| 256 expect(() => parameters['int'].asUri, | 257 expect(() => parameters['int'].asUri, |
| 257 throwsInvalidParams('Parameter "int" for method "foo" must be a ' | 258 throwsInvalidParams('Parameter "int" for method "foo" must be a ' |
| 258 'string, but was 1.')); | 259 'string, but was 1.')); |
| 259 }); | 260 }); |
| 260 | 261 |
| 261 test("[].asUri fails for invalid URIs", () { | 262 test("[].asUri fails for invalid URIs", () { |
| 262 expect(() => parameters['invalid-uri'].asUri, | 263 expect(() => parameters['invalid-uri'].asUri, |
| 263 throwsInvalidParams('Parameter "invalid-uri" for method "foo" must ' | 264 throwsInvalidParams('Parameter "invalid-uri" for method "foo" must ' |
| 264 'be a valid URI, but was "http://[::1".\n' | 265 'be a valid URI, but was "http://[::1".\n' |
| 265 'Missing end `]` to match `[` in host at position 7.\n' | 266 'Missing end `]` to match `[` in host')); |
| 266 'http://[::1\n' | |
| 267 ' ^')); | |
| 268 }); | 267 }); |
| 269 | 268 |
| 270 group("with a nested parameter map", () { | 269 group("with a nested parameter map", () { |
| 271 var nested; | 270 var nested; |
| 272 setUp(() => nested = parameters['map']); | 271 setUp(() => nested = parameters['map']); |
| 273 | 272 |
| 274 test("[int] fails with a type error", () { | 273 test("[int] fails with a type error", () { |
| 275 expect(() => nested[0], | 274 expect(() => nested[0], |
| 276 throwsInvalidParams('Parameter "map" for method "foo" must be an ' | 275 throwsInvalidParams('Parameter "map" for method "foo" must be an ' |
| 277 'Array, but was {"num":4.2,"bool":false}.')); | 276 'Array, but was {"num":4.2,"bool":false}.')); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 test("with a complex parameter path", () { | 367 test("with a complex parameter path", () { |
| 369 var parameters = new json_rpc.Parameters("foo", { | 368 var parameters = new json_rpc.Parameters("foo", { |
| 370 'bar baz': [0, 1, 2, {'bang.zap': {'\n': 'qux'}}] | 369 'bar baz': [0, 1, 2, {'bang.zap': {'\n': 'qux'}}] |
| 371 }); | 370 }); |
| 372 | 371 |
| 373 expect(() => parameters['bar baz'][3]['bang.zap']['\n']['bip'], | 372 expect(() => parameters['bar baz'][3]['bang.zap']['\n']['bip'], |
| 374 throwsInvalidParams('Parameter "bar baz"[3]."bang.zap"."\\n" for ' | 373 throwsInvalidParams('Parameter "bar baz"[3]."bang.zap"."\\n" for ' |
| 375 'method "foo" must be an Object, but was "qux".')); | 374 'method "foo" must be an Object, but was "qux".')); |
| 376 }); | 375 }); |
| 377 } | 376 } |
| OLD | NEW |