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

Side by Side Diff: client/tests/client/html/ListsTests.dart

Issue 9537001: Generate dart:html bindings for Dartium as well as Frog. All unittests now pass (or are disabled fo… (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 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
OLDNEW
(Empty)
1 // Copyright (c) 2012, 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
6 void testLists() {
7 group('setRange', () {
8 test('one element', () {
9 var list = ["A", "B", "C"];
10 Lists.setRange(list, 1, 1, ["D"], 0);
11 Expect.listEquals(["A", "D", "C"], list);
12 });
13
14 test('several elements', () {
15 var list = ["A", "B", "C"];
16 Lists.setRange(list, 1, 2, ["D", "E"], 0);
17 Expect.listEquals(["A", "D", "E"], list);
18 });
19
20 test('fewer than all source elements', () {
21 var list = ["A", "B", "C"];
22 Lists.setRange(list, 1, 1, ["D", "E"], 0);
23 Expect.listEquals(["A", "D", "C"], list);
24 });
25
26 test('startFrom', () {
27 var list = ["A", "B", "C"];
28 Lists.setRange(list, 1, 1, ["D", "E"], 1);
29 Expect.listEquals(["A", "E", "C"], list);
30 });
31
32 test('negative length', () {
33 var list = ["A", "B", "C"];
34 Expect.throws(
35 () => Lists.setRange(list, 1, -1, ["D"], 0),
36 (e) => e is IllegalArgumentException);
37 });
38
39 test('off the end of dest', () {
40 var list = ["A", "B", "C"];
41 Expect.throws(() {
42 Lists.setRange(list, 2, 2, ["D", "E"], 0);
43 }, (e) => e is IndexOutOfRangeException);
44 });
45
46 test('off the beginning of dest', () {
47 var list = ["A", "B", "C"];
48 Expect.throws(
49 () => Lists.setRange(list, -1, 1, ["D"], 0),
50 (e) => e is IndexOutOfRangeException);
51 });
52
53 test('off the end of source', () {
54 var list = ["A", "B", "C"];
55 Expect.throws(
56 () => Lists.setRange(list, 1, 2, ["D"], 0),
57 (e) => e is IndexOutOfRangeException);
58 });
59
60 test('off the beginning of source', () {
61 var list = ["A", "B", "C"];
62 Expect.throws(
63 () => Lists.setRange(list, 1, 1, ["D"], -1),
64 (e) => e is IndexOutOfRangeException);
65 });
66 });
67
68 group('removeRange', () {
69 void removeRange(list, start, length) =>
70 Lists.removeRange(list, start, length, (i) => list.removeRange(i, 1));
71
72 test('one element', () {
73 var list = ["A", "B", "C"];
74 removeRange(list, 1, 1);
75 Expect.listEquals(["A", "C"], list);
76 });
77
78 test('two elements', () {
79 var list = ["A", "B", "C"];
80 removeRange(list, 1, 2);
81 Expect.listEquals(["A"], list);
82 });
83
84 test('all elements', () {
85 var list = ["A", "B", "C"];
86 removeRange(list, 0, 3);
87 Expect.isTrue(list.isEmpty());
88 });
89
90 test('negative length', () {
91 var list = ["A", "B", "C"];
92 Expect.throws(
93 () => removeRange(list, 2, -1),
94 (e) => e is IllegalArgumentException);
95 });
96
97 test('off the end', () {
98 var list = ["A", "B", "C"];
99 Expect.throws(
100 () => removeRange(list, 2, 3),
101 (e) => e is IndexOutOfRangeException);
102 });
103
104 test('off the beginning', () {
105 var list = ["A", "B", "C"];
106 Expect.throws(
107 () => removeRange(list, -1, 1),
108 (e) => e is IndexOutOfRangeException);
109 });
110 });
111
112 group('getRange', () {
113 test('one element', () {
114 Expect.listEquals(["C"], Lists.getRange(["A", "B", "C"], 2, 1));
115 });
116
117 test('two elements', () {
118 Expect.listEquals(["B", "C"], Lists.getRange(["A", "B", "C"], 1, 2));
119 });
120
121 test('negative length', () {
122 Expect.throws(
123 () => Lists.getRange(["A", "B", "C"], 2, -1),
124 (e) => e is IllegalArgumentException);
125 });
126
127 test('off the end', () {
128 Expect.throws(
129 () => Lists.getRange(["A", "B", "C"], 2, 2),
130 (e) => e is IndexOutOfRangeException);
131 });
132
133 test('off the beginning', () {
134 Expect.throws(
135 () => Lists.getRange(["A", "B", "C"], -1, 2),
136 (e) => e is IndexOutOfRangeException);
137 });
138 });
139
140 test('indexOf', () {
141 var list = ["A", "B", "C"];
142 Expect.equals(0, Lists.indexOf(list, "A", 0, list.length));
143 Expect.equals(1, Lists.indexOf(list, "B", 0, list.length));
144 Expect.equals(2, Lists.indexOf(list, "C", 0, list.length));
145 Expect.equals(-1, Lists.indexOf(list, "D", 0, list.length));
146 Expect.equals(1, Lists.indexOf(list, "B", 1, list.length));
147 Expect.equals(-1, Lists.indexOf(list, "B", 2, list.length));
148 });
149
150 test('lastIndexOf', () {
151 var list = ["A", "B", "C"];
152 Expect.equals(0, Lists.lastIndexOf(list, "A", list.length - 1));
153 Expect.equals(1, Lists.lastIndexOf(list, "B", list.length - 1));
154 Expect.equals(2, Lists.lastIndexOf(list, "C", list.length - 1));
155 Expect.equals(-1, Lists.lastIndexOf(list, "D", list.length - 1));
156 Expect.equals(1, Lists.lastIndexOf(list, "B", 1));
157 Expect.equals(-1, Lists.lastIndexOf(list, "E", 0));
158 });
159 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698