Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2307)

Unified Diff: tests/standalone/io/bytes_builder_test.dart

Issue 2100103002: Fix bug in BytesBuilder. Add tests. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sdk/lib/io/bytes_builder.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/standalone/io/bytes_builder_test.dart
diff --git a/tests/standalone/io/bytes_builder_test.dart b/tests/standalone/io/bytes_builder_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..7dd49094d9676fe6fc446b56152ac9796eb82eaa
--- /dev/null
+++ b/tests/standalone/io/bytes_builder_test.dart
@@ -0,0 +1,64 @@
+// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+import "dart:io";
+import "dart:typed_data";
+import "package:expect/expect.dart";
+
+main() {
+ for (var copying in [true, false]) {
+ var b;
+ testLength(n) {
+ Expect.equals(n, b.length);
+ if (n == 0) {
+ Expect.isTrue(b.isEmpty, "isEmpty: #${b.length}");
+ Expect.isFalse(b.isNotEmpty, "isNotEmpty: #${b.length}");
+ } else {
+ Expect.isTrue(b.isNotEmpty, "isNotEmpty: #${b.length}");
+ Expect.isFalse(b.isEmpty, "isEmpty: #${b.length}");
+ }
+ }
+
+ b = new BytesBuilder(copy: copying);
+ testLength(0);
+
+ b.addByte(0);
+ testLength(1);
+
+ b.add([1, 2, 3]);
+ testLength(4);
+
+ b.add(<int>[4, 5, 6]);
+ testLength(7);
+
+ b.add(new Uint8List.fromList([7, 8, 9]));
+ testLength(10);
+
+ b.add(new Uint16List.fromList([10, 11, 12]));
+ testLength(13);
+
+ var bytes = b.toBytes();
+ Expect.isTrue(bytes is Uint8List);
+ Expect.listEquals([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12], bytes);
+ testLength(13);
+
+ b.add("\x0d\x0e\x0f".codeUnits);
+ testLength(16);
+
+ bytes = b.takeBytes();
+ testLength(0);
+ Expect.isTrue(bytes is Uint8List);
+ Expect.listEquals([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
+ bytes);
+
+ b.addByte(0);
+ testLength(1);
+
+ b.clear();
+ testLength(0);
+
+ b.addByte(0);
+ testLength(1);
+ }
+}
« no previous file with comments | « sdk/lib/io/bytes_builder.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698