| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2013, 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:convert'; |
| 6 |
| 7 import 'package:expect/expect.dart'; |
| 8 |
| 9 // Test that the String and ByteConversionSinks make a copy when they need to |
| 10 // adapt. |
| 11 |
| 12 class MyByteSink extends ByteConversionSinkBase { |
| 13 var accumulator = []; |
| 14 add(List<int> bytes) { |
| 15 accumulator.add(bytes); |
| 16 } |
| 17 close() {} |
| 18 } |
| 19 |
| 20 void testBase() { |
| 21 var byteSink = new MyByteSink(); |
| 22 var bytes = [1]; |
| 23 byteSink.addSlice(bytes, 0, 1, false); |
| 24 bytes[0] = 2; |
| 25 byteSink.addSlice(bytes, 0, 1, true); |
| 26 Expect.equals(1, byteSink.accumulator[0][0]); |
| 27 Expect.equals(2, byteSink.accumulator[1][0]); |
| 28 } |
| 29 |
| 30 class MyChunkedSink extends ChunkedConversionSink { |
| 31 var accumulator = []; |
| 32 add(List<int> bytes) { |
| 33 accumulator.add(bytes); |
| 34 } |
| 35 close() {} |
| 36 } |
| 37 |
| 38 void testAdapter() { |
| 39 var chunkedSink = new MyChunkedSink(); |
| 40 var byteSink = new ByteConversionSink.from(chunkedSink); |
| 41 var bytes = [1]; |
| 42 byteSink.addSlice(bytes, 0, 1, false); |
| 43 bytes[0] = 2; |
| 44 byteSink.addSlice(bytes, 0, 1, true); |
| 45 Expect.equals(1, chunkedSink.accumulator[0][0]); |
| 46 Expect.equals(2, chunkedSink.accumulator[1][0]); |
| 47 } |
| 48 |
| 49 void main() { |
| 50 testBase(); |
| 51 testAdapter(); |
| 52 } |
| OLD | NEW |