OLD | NEW |
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 library ElementTest; | 5 library ElementTest; |
6 import 'package:unittest/unittest.dart'; | 6 import 'package:unittest/unittest.dart'; |
7 import 'package:unittest/html_config.dart'; | 7 import 'package:unittest/html_config.dart'; |
8 import 'dart:collection'; | 8 import 'dart:collection'; |
9 import 'dart:html'; | 9 import 'dart:html'; |
10 | 10 |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 test('length', () { | 122 test('length', () { |
123 expect(makeClassSet().length, 3); | 123 expect(makeClassSet().length, 3); |
124 expect(makeElement().classes.length, 0); | 124 expect(makeElement().classes.length, 0); |
125 }); | 125 }); |
126 | 126 |
127 test('contains', () { | 127 test('contains', () { |
128 expect(makeClassSet().contains('foo'), isTrue); | 128 expect(makeClassSet().contains('foo'), isTrue); |
129 expect(makeClassSet().contains('qux'), isFalse); | 129 expect(makeClassSet().contains('qux'), isFalse); |
130 }); | 130 }); |
131 | 131 |
| 132 test('contains-bad', () { |
| 133 // Non-strings return `false`. |
| 134 // Strings need to be valid tokens. |
| 135 final classes = makeClassSet(); |
| 136 expect(classes.contains(1), isFalse); |
| 137 expect(() => classes.contains(''), throws); |
| 138 expect(() => classes.contains('foo bar'), throws); |
| 139 }); |
| 140 |
132 test('add', () { | 141 test('add', () { |
133 final classes = makeClassSet(); | 142 final classes = makeClassSet(); |
134 var added = classes.add('qux'); | 143 var added = classes.add('qux'); |
135 expect(added, isTrue); | 144 expect(added, isTrue); |
136 expect(classes, orderedEquals(['foo', 'bar', 'baz', 'qux'])); | 145 expect(classes, orderedEquals(['foo', 'bar', 'baz', 'qux'])); |
137 | 146 |
138 added = classes.add('qux'); | 147 added = classes.add('qux'); |
139 expect(added, isFalse); | 148 expect(added, isFalse); |
140 final list = new List.from(classes); | 149 final list = new List.from(classes); |
141 list.sort((a, b) => a.compareTo(b)); | 150 list.sort((a, b) => a.compareTo(b)); |
142 expect(list, orderedEquals(['bar', 'baz', 'foo', 'qux']), | 151 expect(list, orderedEquals(['bar', 'baz', 'foo', 'qux']), |
143 reason: "The class set shouldn't have duplicate elements."); | 152 reason: "The class set shouldn't have duplicate elements."); |
144 }); | 153 }); |
145 | 154 |
| 155 test('add-bad', () { |
| 156 final classes = makeClassSet(); |
| 157 expect(() => classes.add(''), throws); |
| 158 expect(() => classes.add('foo bar'), throws); |
| 159 }); |
| 160 |
146 test('remove', () { | 161 test('remove', () { |
147 final classes = makeClassSet(); | 162 final classes = makeClassSet(); |
148 classes.remove('bar'); | 163 classes.remove('bar'); |
149 expect(classes, orderedEquals(['foo', 'baz'])); | 164 expect(classes, orderedEquals(['foo', 'baz'])); |
150 classes.remove('qux'); | 165 classes.remove('qux'); |
151 expect(classes, orderedEquals(['foo', 'baz'])); | 166 expect(classes, orderedEquals(['foo', 'baz'])); |
152 }); | 167 }); |
153 | 168 |
| 169 test('remove-bad', () { |
| 170 final classes = makeClassSet(); |
| 171 expect(() => classes.remove(''), throws); |
| 172 expect(() => classes.remove('foo bar'), throws); |
| 173 }); |
| 174 |
154 test('toggle', () { | 175 test('toggle', () { |
155 final classes = makeClassSet(); | 176 final classes = makeClassSet(); |
156 classes.toggle('bar'); | 177 classes.toggle('bar'); |
157 expect(classes, orderedEquals(['foo', 'baz'])); | 178 expect(classes, orderedEquals(['foo', 'baz'])); |
158 classes.toggle('qux'); | 179 classes.toggle('qux'); |
159 expect(classes, orderedEquals(['foo', 'baz', 'qux'])); | 180 expect(classes, orderedEquals(['foo', 'baz', 'qux'])); |
160 | 181 |
161 classes.toggle('qux', true); | 182 classes.toggle('qux', true); |
162 expect(classes, orderedEquals(['foo', 'baz', 'qux'])); | 183 expect(classes, orderedEquals(['foo', 'baz', 'qux'])); |
163 classes.toggle('qux', false); | 184 classes.toggle('qux', false); |
164 expect(classes, orderedEquals(['foo', 'baz'])); | 185 expect(classes, orderedEquals(['foo', 'baz'])); |
165 classes.toggle('qux', false); | 186 classes.toggle('qux', false); |
166 expect(classes, orderedEquals(['foo', 'baz'])); | 187 expect(classes, orderedEquals(['foo', 'baz'])); |
167 classes.toggle('qux', true); | 188 classes.toggle('qux', true); |
168 expect(classes, orderedEquals(['foo', 'baz', 'qux'])); | 189 expect(classes, orderedEquals(['foo', 'baz', 'qux'])); |
169 }); | 190 }); |
170 | 191 |
| 192 test('toggle-bad', () { |
| 193 final classes = makeClassSet(); |
| 194 expect(() => classes.toggle(''), throws); |
| 195 expect(() => classes.toggle('', true), throws); |
| 196 expect(() => classes.toggle('', false), throws); |
| 197 expect(() => classes.toggle('foo bar'), throws); |
| 198 expect(() => classes.toggle('foo bar', true), throws); |
| 199 expect(() => classes.toggle('foo bar', false), throws); |
| 200 }); |
| 201 |
171 test('addAll', () { | 202 test('addAll', () { |
172 final classes = makeClassSet(); | 203 final classes = makeClassSet(); |
173 classes.addAll(['bar', 'qux', 'bip']); | 204 classes.addAll(['bar', 'qux', 'bip']); |
174 expect(classes, orderedEquals(['foo', 'bar', 'baz', 'qux', 'bip'])); | 205 expect(classes, orderedEquals(['foo', 'bar', 'baz', 'qux', 'bip'])); |
175 }); | 206 }); |
176 | 207 |
177 test('removeAll', () { | 208 test('removeAll', () { |
178 final classes = makeClassSet(); | 209 final classes = makeClassSet(); |
179 classes.removeAll(['bar', 'baz', 'qux']); | 210 classes.removeAll(['bar', 'baz', 'qux']); |
180 expect(classes, orderedEquals(['foo'])); | 211 expect(classes, orderedEquals(['foo'])); |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 expect(view(elements.classes), '[quux, qux]'); | 388 expect(view(elements.classes), '[quux, qux]'); |
358 expect(view(elements), '[[quux, qux], [], [], [qux]]'); | 389 expect(view(elements), '[[quux, qux], [], [], [qux]]'); |
359 }); | 390 }); |
360 | 391 |
361 test('listContainsAll', () { | 392 test('listContainsAll', () { |
362 var elements = listElementSetup(); | 393 var elements = listElementSetup(); |
363 expect(elements.classes.containsAll(['qux', 'meta', 'mornin']), isFalse); | 394 expect(elements.classes.containsAll(['qux', 'meta', 'mornin']), isFalse); |
364 expect(elements.classes.containsAll(['qux', 'lassy', 'classy']), isTrue); | 395 expect(elements.classes.containsAll(['qux', 'lassy', 'classy']), isTrue); |
365 }); | 396 }); |
366 } | 397 } |
OLD | NEW |