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

Unified Diff: tests/lib/typed_data/constructor_checks_test.dart

Issue 127313002: dart2js typed data constructor argument validation (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 11 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/typed_data/dart2js/typed_data_dart2js.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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();
+}
« no previous file with comments | « sdk/lib/typed_data/dart2js/typed_data_dart2js.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698