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

Side by Side 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, 10 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
« no previous file with comments | « lib/stream_channel.dart ('k') | 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
(Empty)
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
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.
4
5 import 'dart:async';
6 import 'dart:convert';
7
8 import 'package:stream_channel/stream_channel.dart';
9 import 'package:test/test.dart';
10
11 import 'utils.dart';
12
13 void main() {
14 var streamController;
15 var sinkController;
16 var channel;
17 setUp(() {
18 streamController = new StreamController();
19 sinkController = new StreamController();
20 channel = new StreamChannel(
21 streamController.stream, sinkController.sink);
22 });
23
24 test("decodes JSON emitted by the channel", () {
25 var transformed = channel.transform(jsonDocument);
26 streamController.add('{"foo": "bar"}');
27 expect(transformed.stream.first, completion(equals({"foo": "bar"})));
28 });
29
30 test("encodes objects added to the channel", () {
31 var transformed = channel.transform(jsonDocument);
32 transformed.sink.add({"foo": "bar"});
33 expect(sinkController.stream.first,
34 completion(equals(JSON.encode({"foo": "bar"}))));
35 });
36
37 test("supports the reviver function", () {
38 var transformed = channel.transform(
39 new JsonDocumentTransformer(reviver: (key, value) => "decoded"));
40 streamController.add('{"foo": "bar"}');
41 expect(transformed.stream.first, completion(equals("decoded")));
42 });
43
44 test("supports the toEncodable function", () {
45 var transformed = channel.transform(
46 new JsonDocumentTransformer(toEncodable: (object) => "encoded"));
47 transformed.sink.add(new Object());
48 expect(sinkController.stream.first, completion(equals('"encoded"')));
49 });
50 }
OLDNEW
« 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