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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 void main() {
6 // Normal modifiable list.
7 var l1 = [0, 1, 2, 3, 4];
8
9 bool checkedMode = false;
10 assert(checkedMode = true);
11
12 // Index must be integer and in range.
13 Expect.throws(() { l1.insert(-1, 5); },
14 (e) => e is RangeError,
15 "negative");
16 Expect.throws(() { l1.insert(6, 5); },
17 (e) => e is RangeError,
18 "too large");
19 Expect.throws(() { l1.insert(null, 5); });
20 Expect.throws(() { l1.insert("1", 5); });
21 Expect.throws(() { l1.insert(1.5, 5); });
22
23 l1.insert(5, 5);
24 Expect.equals(6, l1.length);
25 Expect.equals(5, l1[5]);
26 Expect.equals("[0, 1, 2, 3, 4, 5]", l1.toString());
27
28 l1.insert(0, -1);
29 Expect.equals(7, l1.length);
30 Expect.equals(-1, l1[0]);
31 Expect.equals("[-1, 0, 1, 2, 3, 4, 5]", l1.toString());
32
33 // Fixed size list.
34 var l2 = new List(5);
35 for (var i = 0; i < 5; i++) l2[i] = i;
36 Expect.throws(() { l2.insert(2, 5); },
37 (e) => e is UnsupportedError,
38 "fixed-length");
39
40 // Unmodifiable list.
41 var l3 = const [0, 1, 2, 3, 4];
42 Expect.throws(() { l3.insert(2, 5); },
43 (e) => e is UnsupportedError,
44 "unmodifiable");
45
46 // Empty list is not special.
47 var l4 = [];
48 l4.insert(0, 499);
49 Expect.equals(1, l4.length);
50 Expect.equals(499, l4[0]);
51 }
OLDNEW
« 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