OLD | NEW |
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 Loading... |
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 } |
OLD | NEW |