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