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

Unified Diff: tests/corelib/list_removeat_test.dart

Issue 10970009: Add list.removeAt method. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 3 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
« runtime/lib/array.dart ('K') | « runtime/lib/growable_array.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/corelib/list_removeat_test.dart
diff --git a/tests/corelib/list_removeat_test.dart b/tests/corelib/list_removeat_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..a690f2a999b05e4021073b554b0bfebc90c5f6ac
--- /dev/null
+++ b/tests/corelib/list_removeat_test.dart
@@ -0,0 +1,54 @@
+// Copyright (c) 2011, 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];
+
+ // Index must be integer and in range.
+ Expect.throws(() { l1.removeAt(-1); },
+ (e) => e is IndexOutOfRangeException,
+ "negative");
+ Expect.throws(() { l1.removeAt(5); },
+ (e) => e is IndexOutOfRangeException,
+ "too large");
+ Expect.throws(() { l1.removeAt("1"); },
+ (e) => e is IllegalArgumentException,
+ "string");
+ Expect.throws(() { l1.removeAt(1.5); },
+ (e) => e is IllegalArgumentException,
+ "double");
+
+ Expect.equals(2, l1.removeAt(2), "l1-remove2");
+ Expect.equals(1, l1[1], "l1-1[1]");
+
+ Expect.equals(3, l1[2], "l1-1[2]");
+ Expect.equals(4, l1[3], "l1-1[3]");
+ Expect.equals(4, l1.length, "length-1");
+
+ Expect.equals(0, l1.removeAt(0), "l1-remove0");
+ Expect.equals(1, l1[0], "l1-2[0]");
+ Expect.equals(3, l1[1], "l1-2[1]");
+ Expect.equals(4, l1[2], "l1-2[2]");
+ Expect.equals(3, l1.length, "length-2");
+
+ // Fixed size list.
+ var l2 = new List(5);
+ for (var i = 0; i < 5; i++) l2[i] = i;
+ Expect.throws(() { l2.removeAt(2); },
+ (e) => e is UnsupportedOperationException,
+ "fixed-length");
+
+ // Unmodifiable list.
+ var l3 = const [0, 1, 2, 3, 4];
+ Expect.throws(() { l3.removeAt(2); },
+ (e) => e is UnsupportedOperationException,
+ "unmodifiable");
+
+ // Empty list is not special.
+ var l4 = [];
+ Expect.throws(() { l4.removeAt(0); },
+ (e) => e is IndexOutOfRangeException,
+ "empty");
+}
« runtime/lib/array.dart ('K') | « runtime/lib/growable_array.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698