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

Unified Diff: test/codegen/corelib/list_insert_test.dart

Issue 1945153002: Add corelib tests (Closed) Base URL: https://github.com/dart-lang/dev_compiler@master
Patch Set: error_test and range_error_test now pass Created 4 years, 7 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 | « test/codegen/corelib/list_insert_all_test.dart ('k') | test/codegen/corelib/list_iterators_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/codegen/corelib/list_insert_test.dart
diff --git a/test/codegen/corelib/list_insert_test.dart b/test/codegen/corelib/list_insert_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..50d088fc277a660ead3e40937fd96ec8f7bd5341
--- /dev/null
+++ b/test/codegen/corelib/list_insert_test.dart
@@ -0,0 +1,71 @@
+// 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.
+
+import 'package:expect/expect.dart';
+import 'dart:collection';
+
+class MyList extends ListBase {
+ List list;
+ MyList(this.list);
+
+ get length => list.length;
+ set length(val) { list.length = val; }
+
+ operator [](index) => list[index];
+ operator []=(index, val) => list[index] = val;
+
+ String toString() => "[" + join(", ") + "]";
+}
+
+// l1 must be a modifiable list with 5 elements from 0 to 4.
+void testModifiableList(l1) {
+ 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());
+}
+
+void main() {
+ // Normal modifiable list.
+ testModifiableList([0, 1, 2, 3, 4]);
+ testModifiableList(new MyList([0, 1, 2, 3, 4]));
+
+ // 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 | « test/codegen/corelib/list_insert_all_test.dart ('k') | test/codegen/corelib/list_iterators_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698