Index: tests/lib/typed_data/constructor_checks_test.dart |
diff --git a/tests/lib/typed_data/constructor_checks_test.dart b/tests/lib/typed_data/constructor_checks_test.dart |
new file mode 100644 |
index 0000000000000000000000000000000000000000..3842ac196d4389a4673799ca0fcc34e71f357d42 |
--- /dev/null |
+++ b/tests/lib/typed_data/constructor_checks_test.dart |
@@ -0,0 +1,71 @@ |
+// Copyright (c) 2014, 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 'package:expect/expect.dart'; |
+import 'dart:typed_data'; |
+ |
+checkLengthConstructors() { |
+ check(creator) { |
+ Expect.throws(() => creator(null)); |
+ Expect.throws(() => creator(8.5)); |
+ Expect.throws(() => creator('10')); |
+ var a = creator(10); |
+ Expect.equals(10, a.length); |
+ } |
+ |
+ check((a) => new Float32List(a)); |
+ check((a) => new Float64List(a)); |
+ check((a) => new Int8List(a)); |
+ check((a) => new Int8List(a)); |
+ check((a) => new Int16List(a)); |
+ check((a) => new Int32List(a)); |
+ check((a) => new Uint8List(a)); |
+ check((a) => new Uint16List(a)); |
+ check((a) => new Uint32List(a)); |
+} |
+ |
+checkViewConstructors() { |
+ var buffer = new Int8List(256).buffer; |
+ |
+ check1(creator) { |
+ Expect.throws(() => creator(10)); |
+ Expect.throws(() => creator(null)); |
+ var a = creator(buffer); |
+ Expect.equals(buffer, a.buffer); |
+ } |
+ |
+ check2(creator) { |
+ Expect.throws(() => creator(10, 0)); |
+ Expect.throws(() => creator(null, 0)); |
+ Expect.throws(() => creator(buffer, null)); |
+ Expect.throws(() => creator(buffer, '8')); |
+ var a = creator(buffer, 8); |
+ Expect.equals(buffer, a.buffer); |
+ } |
+ |
+ check1((a) => new Float32List.view(a)); |
+ check1((a) => new Float64List.view(a)); |
+ check1((a) => new Int8List.view(a)); |
+ check1((a) => new Int8List.view(a)); |
+ check1((a) => new Int16List.view(a)); |
+ check1((a) => new Int32List.view(a)); |
+ check1((a) => new Uint8List.view(a)); |
+ check1((a) => new Uint16List.view(a)); |
+ check1((a) => new Uint32List.view(a)); |
+ |
+ check2((a, b) => new Float32List.view(a, b)); |
+ check2((a, b) => new Float64List.view(a, b)); |
+ check2((a, b) => new Int8List.view(a, b)); |
+ check2((a, b) => new Int8List.view(a, b)); |
+ check2((a, b) => new Int16List.view(a, b)); |
+ check2((a, b) => new Int32List.view(a, b)); |
+ check2((a, b) => new Uint8List.view(a, b)); |
+ check2((a, b) => new Uint16List.view(a, b)); |
+ check2((a, b) => new Uint32List.view(a, b)); |
+} |
+ |
+main() { |
+ checkLengthConstructors(); |
+ checkViewConstructors(); |
+} |