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

Side by Side Diff: tests/corelib/list_set_range_test.dart

Issue 13863012: Refactor List.setRange function. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebase Created 7 years, 8 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
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import "package:expect/expect.dart"; 5 import "package:expect/expect.dart";
6 6
7 main() { 7 main() {
8 var list = []; 8 var list = [];
9 list.setRange(0, 0, const []); 9 list.setRange(0, 0, const []);
10 list.setRange(0, 0, []); 10 list.setRange(0, 0, []);
11 list.setRange(0, 0, const [], 1); 11 expectIOORE(() { list.setRange(0, 0, const [], 1); });
12 list.setRange(0, 0, [], 1); 12 expectIOORE(() { list.setRange(0, 0, [], 1); });
13 Expect.equals(0, list.length); 13 Expect.equals(0, list.length);
14 expectIOORE(() { list.setRange(0, 1, []); }); 14 expectIOORE(() { list.setRange(0, 1, []); });
15 expectIOORE(() { list.setRange(0, 1, [], 1); }); 15 expectIOORE(() { list.setRange(0, 1, [], 1); });
16 expectIOORE(() { list.setRange(0, 1, [1], 0); }); 16 expectIOORE(() { list.setRange(0, 1, [1], 0); });
17 17
18 list.add(1); 18 list.add(1);
19 list.setRange(0, 0, [], 0); 19 list.setRange(0, 0, [], 0);
20 Expect.equals(1, list.length); 20 Expect.equals(1, list.length);
21 Expect.equals(1, list[0]); 21 Expect.equals(1, list[0]);
22 list.setRange(0, 0, const [], 0); 22 list.setRange(0, 0, const [], 0);
(...skipping 14 matching lines...) Expand all
37 37
38 list.setRange(0, 1, const [3], 0); 38 list.setRange(0, 1, const [3], 0);
39 Expect.equals(1, list.length); 39 Expect.equals(1, list.length);
40 Expect.equals(3, list[0]); 40 Expect.equals(3, list[0]);
41 41
42 list.addAll([4, 5, 6]); 42 list.addAll([4, 5, 6]);
43 Expect.equals(4, list.length); 43 Expect.equals(4, list.length);
44 list.setRange(0, 4, [1, 2, 3, 4]); 44 list.setRange(0, 4, [1, 2, 3, 4]);
45 Expect.listEquals([1, 2, 3, 4], list); 45 Expect.listEquals([1, 2, 3, 4], list);
46 46
47 list.setRange(2, 2, [5, 6, 7, 8]); 47 list.setRange(2, 4, [5, 6, 7, 8]);
48 Expect.listEquals([1, 2, 5, 6], list); 48 Expect.listEquals([1, 2, 5, 6], list);
49 49
50 expectIOORE(() { list.setRange(4, 1, [5, 6, 7, 8]); }); 50 expectIOORE(() { list.setRange(4, 5, [5, 6, 7, 8]); });
51 Expect.listEquals([1, 2, 5, 6], list); 51 Expect.listEquals([1, 2, 5, 6], list);
52 52
53 list.setRange(1, 2, [9, 10, 11, 12]); 53 list.setRange(1, 3, [9, 10, 11, 12]);
54 Expect.listEquals([1, 9, 10, 6], list); 54 Expect.listEquals([1, 9, 10, 6], list);
55 55
56 testNegativeIndices(); 56 testNegativeIndices();
57 57
58 testNonExtendableList(); 58 testNonExtendableList();
59 } 59 }
60 60
61 void expectIOORE(Function f) { 61 void expectIOORE(Function f) {
62 Expect.throws(f, (e) => e is RangeError); 62 Expect.throws(f, (e) => e is RangeError);
63 } 63 }
64 64
65 void testNegativeIndices() { 65 void testNegativeIndices() {
66 var list = [1, 2]; 66 var list = [1, 2];
67 expectIOORE(() { list.setRange(-1, 1, [1]); }); 67 expectIOORE(() { list.setRange(-1, 1, [1]); });
68 expectIOORE(() { list.setRange(0, 1, [1], -1); }); 68 expectIOORE(() { list.setRange(0, 1, [1], -1); });
69 69
70 // A negative length throws an ArgumentError. 70 // A negative length throws an ArgumentError.
71 Expect.throws(() { list.setRange(0, -1, [1]); }, 71 expectIOORE(() { list.setRange(0, -1, [1]); });
72 (e) => e is ArgumentError);
73 72
74 Expect.throws(() { list.setRange(-1, -1, [1], -1); }, 73 expectIOORE(() { list.setRange(-1, -2, [1], -1); });
75 (e) => e is ArgumentError);
76 Expect.listEquals([1, 2], list); 74 Expect.listEquals([1, 2], list);
77 75
78 // A zero length prevails, and does not throw an exception. 76 expectIOORE(() { list.setRange(-1, -1, [1]); });
79 list.setRange(-1, 0, [1]);
80 Expect.listEquals([1, 2], list); 77 Expect.listEquals([1, 2], list);
81 78
82 list.setRange(0, 0, [1], -1); 79 expectIOORE(() { list.setRange(0, 0, [1], -1); });
83 Expect.listEquals([1, 2], list); 80 Expect.listEquals([1, 2], list);
84 } 81 }
85 82
86 void testNonExtendableList() { 83 void testNonExtendableList() {
87 var list = new List<int>(6); 84 var list = new List<int>(6);
88 Expect.listEquals([null, null, null, null, null, null], list); 85 Expect.listEquals([null, null, null, null, null, null], list);
89 list.setRange(0, 3, [1, 2, 3, 4]); 86 list.setRange(0, 3, [1, 2, 3, 4]);
90 list.setRange(3, 3, [1, 2, 3, 4]); 87 list.setRange(3, 6, [1, 2, 3, 4]);
91 Expect.listEquals([1, 2, 3, 1, 2, 3], list); 88 Expect.listEquals([1, 2, 3, 1, 2, 3], list);
92 } 89 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698