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

Unified Diff: tests/corelib/list_test.dart

Issue 1318943005: Update range errors to agree on the numbers. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Tweak JS output. Created 5 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
« sdk/lib/core/errors.dart ('K') | « sdk/lib/core/errors.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_test.dart
diff --git a/tests/corelib/list_test.dart b/tests/corelib/list_test.dart
index 5187ee84ccce4cb210548b52923e1db406914798..b075cbd80d0c28b9f78e8b56c902aabdb7dbcd21 100644
--- a/tests/corelib/list_test.dart
+++ b/tests/corelib/list_test.dart
@@ -46,6 +46,65 @@ void main() {
testTypedGrowableList(new Int32List(0).toList());
testListConstructor();
+
+ // Regression for issue http://dartbug.com/24295
+ testIndex(list, name) {
+ try {
+ list[list.length];
sra1 2015/09/09 17:16:05 Could also test that an index outside the 2^32 ran
Lasse Reichstein Nielsen 2015/09/10 10:08:54 Good point.
+ } catch (err, s) {
+ Expect.isTrue(err is RangeError, name);
+ Expect.equals(list.length, err.invalidValue, "$name value");
+ Expect.equals(list.length - 1, err.end, "$name end");
+ Expect.equals(0, err.start, "$name start");
+ }
+ }
+ // Slices.
+ testSlice(list, name) {
+ try {
+ list.sublist(0, list.length + 1);
+ } catch (err) {
+ Expect.isTrue(err is RangeError, "$name[0:l+1] is-error: $err");
+ Expect.equals("end", err.name, "$name[0:l+1] name");
+ Expect.equals(list.length + 1, err.invalidValue, "$name[0:l+1] value");
+ Expect.equals(0, err.start, "$name[0:l+1] start");
+ Expect.equals(list.length, err.end, "$name[0:l+1] end");
+ }
+ try {
+ list.sublist(list.length + 1, list.length + 1);
+ } catch (err) {
+ Expect.isTrue(err is RangeError, "$name[l+1:l+1] is-error: $err");
+ Expect.equals("start", err.name, "$name[l+1:l+1] name");
+ Expect.equals(list.length + 1, err.invalidValue, "$name[l+1:l+1] value");
+ Expect.equals(0, err.start, "$name[l+1:l+1] start");
+ Expect.equals(list.length, err.end, "$name[l+1:l+1] end");
+ }
+ if (list.length == 0) return;
+ try {
+ list.sublist(1, list.length + 1);
+ } catch (err) {
+ Expect.isTrue(err is RangeError, "$name[1:l+1] is-error: $err");
+ Expect.equals("end", err.name, "$name[1:l+1] name");
+ Expect.equals(list.length + 1, err.invalidValue, "$name[1:l+1] value");
+ Expect.equals(1, err.start, "$name[1:l+1] start");
+ Expect.equals(list.length, err.end, "$name[1:l+1] end");
+ }
+ }
+ testRangeErrors(list, name) {
+ testIndex(list, "$name#${list.length} index");
+ testSlice(list, "$name#${list.length} slice");
+ }
+ // Empty lists.
+ testRangeErrors([], "list");
+ testRangeErrors(new List(0), "fixed-list");
+ testRangeErrors(const [], "const-list");
sra1 2015/09/09 17:16:05 Also new List.unmodifiable([])
Lasse Reichstein Nielsen 2015/09/10 10:08:54 Good idea. Done.
+ testRangeErrors(new Uint8List(0), "typed-list");
+ testRangeErrors([1, 2, 3].sublist(1, 1), "sub-list");
+ // Non-empty lists.
+ testRangeErrors([1, 2, 3], "list");
+ testRangeErrors(new List(3), "fixed-list");
+ testRangeErrors(const [1, 2, 3], "const-list");
+ testRangeErrors(new Uint8List(3), "typed-list");
+ testRangeErrors([1, 2, 3, 4, 5].sublist(1, 3), "sub-list");
}
void testLength(int length, List list) {
@@ -475,6 +534,7 @@ void testGrowableListOperations(List list) {
class Yes {
operator ==(var other) => true;
+ int get hashCode => 0;
}
class MyList<E> extends ListBase<E> {
« sdk/lib/core/errors.dart ('K') | « sdk/lib/core/errors.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698