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

Unified Diff: tests/corelib/list_insert_test.dart

Issue 12383073: Add List.insert. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Use insertBefore and add is-check. Created 7 years, 9 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/web_sql/dartium/web_sql_dartium.dart ('k') | tools/dom/src/WrappedList.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/corelib/list_insert_test.dart
diff --git a/tests/corelib/list_insert_test.dart b/tests/corelib/list_insert_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..7d3a72271a3cc865c57fa4af044b6e01cdad9b44
--- /dev/null
+++ b/tests/corelib/list_insert_test.dart
@@ -0,0 +1,51 @@
+// Copyright (c) 2013, 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.
+
+void main() {
+ // Normal modifiable list.
+ var l1 = [0, 1, 2, 3, 4];
+
+ bool checkedMode = false;
+ assert(checkedMode = true);
+
+ // Index must be integer and in range.
+ Expect.throws(() { l1.insert(-1, 5); },
+ (e) => e is RangeError,
+ "negative");
+ Expect.throws(() { l1.insert(6, 5); },
+ (e) => e is RangeError,
+ "too large");
+ Expect.throws(() { l1.insert(null, 5); });
+ Expect.throws(() { l1.insert("1", 5); });
+ Expect.throws(() { l1.insert(1.5, 5); });
+
+ l1.insert(5, 5);
+ Expect.equals(6, l1.length);
+ Expect.equals(5, l1[5]);
+ Expect.equals("[0, 1, 2, 3, 4, 5]", l1.toString());
+
+ l1.insert(0, -1);
+ Expect.equals(7, l1.length);
+ Expect.equals(-1, l1[0]);
+ Expect.equals("[-1, 0, 1, 2, 3, 4, 5]", l1.toString());
+
+ // Fixed size list.
+ var l2 = new List(5);
+ for (var i = 0; i < 5; i++) l2[i] = i;
+ Expect.throws(() { l2.insert(2, 5); },
+ (e) => e is UnsupportedError,
+ "fixed-length");
+
+ // Unmodifiable list.
+ var l3 = const [0, 1, 2, 3, 4];
+ Expect.throws(() { l3.insert(2, 5); },
+ (e) => e is UnsupportedError,
+ "unmodifiable");
+
+ // Empty list is not special.
+ var l4 = [];
+ l4.insert(0, 499);
+ Expect.equals(1, l4.length);
+ Expect.equals(499, l4[0]);
+}
« no previous file with comments | « sdk/lib/web_sql/dartium/web_sql_dartium.dart ('k') | tools/dom/src/WrappedList.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698