| 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:convert/convert.dart'; |
| 6 import 'package:test/test.dart'; |
| 7 |
| 8 void main() { |
| 9 var sink; |
| 10 setUp(() { |
| 11 sink = new ByteAccumulatorSink(); |
| 12 }); |
| 13 |
| 14 test("provides access to the concatenated bytes", () { |
| 15 expect(sink.bytes, isEmpty); |
| 16 |
| 17 sink.add([1, 2, 3]); |
| 18 expect(sink.bytes, equals([1, 2, 3])); |
| 19 |
| 20 sink.addSlice([4, 5, 6, 7, 8], 1, 4, false); |
| 21 expect(sink.bytes, equals([1, 2, 3, 5, 6, 7])); |
| 22 }); |
| 23 |
| 24 test("clear() clears the bytes", () { |
| 25 sink.add([1, 2, 3]); |
| 26 expect(sink.bytes, equals([1, 2, 3])); |
| 27 |
| 28 sink.clear(); |
| 29 expect(sink.bytes, isEmpty); |
| 30 |
| 31 sink.add([4, 5, 6]); |
| 32 expect(sink.bytes, equals([4, 5, 6])); |
| 33 }); |
| 34 |
| 35 test("indicates whether the sink is closed", () { |
| 36 expect(sink.isClosed, isFalse); |
| 37 sink.close(); |
| 38 expect(sink.isClosed, isTrue); |
| 39 }); |
| 40 |
| 41 test("indicates whether the sink is closed via addSlice", () { |
| 42 expect(sink.isClosed, isFalse); |
| 43 sink.addSlice([], 0, 0, true); |
| 44 expect(sink.isClosed, isTrue); |
| 45 }); |
| 46 |
| 47 test("doesn't allow add() to be called after close()", () { |
| 48 sink.close(); |
| 49 expect(() => sink.add([1]), throwsStateError); |
| 50 }); |
| 51 |
| 52 test("doesn't allow addSlice() to be called after close()", () { |
| 53 sink.close(); |
| 54 expect(() => sink.addSlice([], 0, 0, false), throwsStateError); |
| 55 }); |
| 56 } |
| OLD | NEW |