| 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]);
|
| +}
|
|
|