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