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

Unified Diff: pkg/json_rpc_2/test/server/parameters_test.dart

Issue 205713007: Add helper getters for URIs and date/times to json_rpc_2. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: bump the version 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/json_rpc_2/pubspec.yaml ('k') | sdk/lib/_internal/pub/lib/src/barback/web_socket_api.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/json_rpc_2/test/server/parameters_test.dart
diff --git a/pkg/json_rpc_2/test/server/parameters_test.dart b/pkg/json_rpc_2/test/server/parameters_test.dart
index 92194756c1b91477663c7cfdd4942f0a1ca2e9f0..8bd126ab14169dadbca8222e9c6d08ffae3ce7bb 100644
--- a/pkg/json_rpc_2/test/server/parameters_test.dart
+++ b/pkg/json_rpc_2/test/server/parameters_test.dart
@@ -20,6 +20,9 @@ void main() {
"bool": true,
"string": "zap",
"list": [1, 2, 3],
+ "date-time": "1990-01-01 00:00:00.000",
+ "uri": "http://dartlang.org",
+ "invalid-uri": "http://[::1",
"map": {
"num": 4.2,
"bool": false
@@ -34,6 +37,9 @@ void main() {
"bool": true,
"string": "zap",
"list": [1, 2, 3],
+ "date-time": "1990-01-01 00:00:00.000",
+ "uri": "http://dartlang.org",
+ "invalid-uri": "http://[::1",
"map": {
"num": 4.2,
"bool": false
@@ -195,6 +201,71 @@ void main() {
expect(parameters['fblthp'].asMapOr({}), equals({}));
});
+ test("[].asDateTime returns date/time parameters", () {
+ expect(parameters['date-time'].asDateTime, equals(new DateTime(1990)));
+ });
+
+ test("[].asDateTimeOr returns date/time parameters", () {
+ expect(parameters['date-time'].asDateTimeOr(new DateTime(2014)),
+ equals(new DateTime(1990)));
+ });
+
+ test("[].asDateTime fails for non-date/time parameters", () {
+ expect(() => parameters['int'].asDateTime,
+ throwsInvalidParams('Parameter "int" for method "foo" must be a '
+ 'string, but was 1.'));
+ });
+
+ test("[].asDateTimeOr succeeds for absent parameters", () {
+ expect(parameters['fblthp'].asDateTimeOr(new DateTime(2014)),
+ equals(new DateTime(2014)));
+ });
+
+ test("[].asDateTime fails for non-date/time parameters", () {
+ expect(() => parameters['int'].asDateTime,
+ throwsInvalidParams('Parameter "int" for method "foo" must be a '
+ 'string, but was 1.'));
+ });
+
+ test("[].asDateTime fails for invalid date/times", () {
+ expect(() => parameters['string'].asDateTime,
+ throwsInvalidParams('Parameter "string" for method "foo" must be a '
+ 'valid date/time, but was "zap".'));
+ });
+
+ test("[].asUri returns URI parameters", () {
+ expect(parameters['uri'].asUri, equals(Uri.parse('http://dartlang.org')));
+ });
+
+ test("[].asUriOr returns URI parameters", () {
+ expect(parameters['uri'].asUriOr(Uri.parse('http://google.com')),
+ equals(Uri.parse('http://dartlang.org')));
+ });
+
+ test("[].asUri fails for non-URI parameters", () {
+ expect(() => parameters['int'].asUri,
+ throwsInvalidParams('Parameter "int" for method "foo" must be a '
+ 'string, but was 1.'));
+ });
+
+ test("[].asUriOr succeeds for absent parameters", () {
+ expect(parameters['fblthp'].asUriOr(Uri.parse('http://google.com')),
+ equals(Uri.parse('http://google.com')));
+ });
+
+ test("[].asUri fails for non-URI parameters", () {
+ expect(() => parameters['int'].asUri,
+ throwsInvalidParams('Parameter "int" for method "foo" must be a '
+ 'string, but was 1.'));
+ });
+
+ test("[].asUri fails for invalid URIs", () {
+ expect(() => parameters['invalid-uri'].asUri,
+ throwsInvalidParams('Parameter "invalid-uri" for method "foo" must '
+ 'be a valid URI, but was "http://[::1".\n'
+ 'Bad end of IPv6 host'));
+ });
+
group("with a nested parameter map", () {
var nested;
setUp(() => nested = parameters['map']);
« no previous file with comments | « pkg/json_rpc_2/pubspec.yaml ('k') | sdk/lib/_internal/pub/lib/src/barback/web_socket_api.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698