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

Unified Diff: test/json_document_transformer_test.dart

Issue 1643843002: Add a document-by-document JSON transformer. (Closed) Base URL: git@github.com:dart-lang/stream_channel.git@master
Patch Set: Created 4 years, 11 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 | « lib/stream_channel.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/json_document_transformer_test.dart
diff --git a/test/json_document_transformer_test.dart b/test/json_document_transformer_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..fec3d2ac115aba52f3f452edaed1dbfe24bfab4f
--- /dev/null
+++ b/test/json_document_transformer_test.dart
@@ -0,0 +1,50 @@
+// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+import 'dart:async';
+import 'dart:convert';
+
+import 'package:stream_channel/stream_channel.dart';
+import 'package:test/test.dart';
+
+import 'utils.dart';
+
+void main() {
+ var streamController;
+ var sinkController;
+ var channel;
+ setUp(() {
+ streamController = new StreamController();
+ sinkController = new StreamController();
+ channel = new StreamChannel(
+ streamController.stream, sinkController.sink);
+ });
+
+ test("decodes JSON emitted by the channel", () {
+ var transformed = channel.transform(jsonDocument);
+ streamController.add('{"foo": "bar"}');
+ expect(transformed.stream.first, completion(equals({"foo": "bar"})));
+ });
+
+ test("encodes objects added to the channel", () {
+ var transformed = channel.transform(jsonDocument);
+ transformed.sink.add({"foo": "bar"});
+ expect(sinkController.stream.first,
+ completion(equals(JSON.encode({"foo": "bar"}))));
+ });
+
+ test("supports the reviver function", () {
+ var transformed = channel.transform(
+ new JsonDocumentTransformer(reviver: (key, value) => "decoded"));
+ streamController.add('{"foo": "bar"}');
+ expect(transformed.stream.first, completion(equals("decoded")));
+ });
+
+ test("supports the toEncodable function", () {
+ var transformed = channel.transform(
+ new JsonDocumentTransformer(toEncodable: (object) => "encoded"));
+ transformed.sink.add(new Object());
+ expect(sinkController.stream.first, completion(equals('"encoded"')));
+ });
+}
« no previous file with comments | « lib/stream_channel.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698