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

Side by Side Diff: test/json_document_transformer_test.dart

Issue 1658833002: Be more explicit about JSON error handling. (Closed) Base URL: git@github.com:dart-lang/stream_channel.git@master
Patch Set: Code review changes 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 | « pubspec.yaml ('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
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 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 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 import 'dart:async'; 5 import 'dart:async';
6 import 'dart:convert'; 6 import 'dart:convert';
7 7
8 import 'package:stream_channel/stream_channel.dart'; 8 import 'package:stream_channel/stream_channel.dart';
9 import 'package:test/test.dart'; 9 import 'package:test/test.dart';
10 10
(...skipping 29 matching lines...) Expand all
40 streamController.add('{"foo": "bar"}'); 40 streamController.add('{"foo": "bar"}');
41 expect(transformed.stream.first, completion(equals("decoded"))); 41 expect(transformed.stream.first, completion(equals("decoded")));
42 }); 42 });
43 43
44 test("supports the toEncodable function", () { 44 test("supports the toEncodable function", () {
45 var transformed = channel.transform( 45 var transformed = channel.transform(
46 new JsonDocumentTransformer(toEncodable: (object) => "encoded")); 46 new JsonDocumentTransformer(toEncodable: (object) => "encoded"));
47 transformed.sink.add(new Object()); 47 transformed.sink.add(new Object());
48 expect(sinkController.stream.first, completion(equals('"encoded"'))); 48 expect(sinkController.stream.first, completion(equals('"encoded"')));
49 }); 49 });
50
51 test("emits a stream error when incoming JSON is malformed", () {
52 var transformed = channel.transform(jsonDocument);
53 streamController.add("{invalid");
54 expect(transformed.stream.first, throwsFormatException);
55 });
56
57 test("synchronously throws if an unencodable object is added", () {
58 var transformed = channel.transform(jsonDocument);
59 expect(() => transformed.sink.add(new Object()),
60 throwsA(new isInstanceOf<JsonUnsupportedObjectError>()));
61 });
50 } 62 }
OLDNEW
« no previous file with comments | « pubspec.yaml ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698