OLD | NEW |
(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 "package:expect/expect.dart"; |
| 6 import "dart:convert"; |
| 7 |
| 8 class MySink implements Sink<List<int>> { |
| 9 List<int> accumulated = <int>[]; |
| 10 bool isClosed = false; |
| 11 |
| 12 add(List<int> list) { |
| 13 accumulated.addAll(list); |
| 14 return list.length; |
| 15 } |
| 16 |
| 17 close() { |
| 18 isClosed = true; |
| 19 // Returning a value here triggered a bug, where the caller was trying to |
| 20 // pass the value through its 'void' return type. |
| 21 // Example: void close() => _sink.close(); |
| 22 return "done"; |
| 23 } |
| 24 } |
| 25 |
| 26 main() { |
| 27 var mySink = new MySink(); |
| 28 var byteSink = new ByteConversionSink.from(mySink); |
| 29 byteSink.add([1, 2, 3]); |
| 30 byteSink.close(); |
| 31 Expect.listEquals([1, 2, 3], mySink.accumulated); |
| 32 Expect.isTrue(mySink.isClosed); |
| 33 } |
OLD | NEW |