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 '../../pkg/unittest/lib/unittest.dart'; | 6 import '../../pkg/unittest/lib/unittest.dart'; |
7 import '../../pkg/unittest/lib/html_config.dart'; | 7 import '../../pkg/unittest/lib/html_config.dart'; |
8 import 'dart:collection'; | 8 import 'dart:collection'; |
9 import 'dart:html'; | 9 import 'dart:html'; |
10 | 10 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 expect(makeElement().classes.length, 0); | 100 expect(makeElement().classes.length, 0); |
101 }); | 101 }); |
102 | 102 |
103 test('contains', () { | 103 test('contains', () { |
104 expect(makeClassSet().contains('foo'), isTrue); | 104 expect(makeClassSet().contains('foo'), isTrue); |
105 expect(makeClassSet().contains('qux'), isFalse); | 105 expect(makeClassSet().contains('qux'), isFalse); |
106 }); | 106 }); |
107 | 107 |
108 test('add', () { | 108 test('add', () { |
109 final classes = makeClassSet(); | 109 final classes = makeClassSet(); |
110 classes.add('qux'); | 110 var added = classes.add('qux'); |
| 111 expect(added, isTrue); |
111 expect(classes, orderedEquals(['foo', 'bar', 'baz', 'qux'])); | 112 expect(classes, orderedEquals(['foo', 'bar', 'baz', 'qux'])); |
112 | 113 |
113 classes.add('qux'); | 114 added = classes.add('qux'); |
| 115 expect(added, isFalse); |
114 final list = new List.from(classes); | 116 final list = new List.from(classes); |
115 list.sort((a, b) => a.compareTo(b)); | 117 list.sort((a, b) => a.compareTo(b)); |
116 expect(list, orderedEquals(['bar', 'baz', 'foo', 'qux']), | 118 expect(list, orderedEquals(['bar', 'baz', 'foo', 'qux']), |
117 reason: "The class set shouldn't have duplicate elements."); | 119 reason: "The class set shouldn't have duplicate elements."); |
118 }); | 120 }); |
119 | 121 |
120 test('remove', () { | 122 test('remove', () { |
121 final classes = makeClassSet(); | 123 final classes = makeClassSet(); |
122 classes.remove('bar'); | 124 classes.remove('bar'); |
123 expect(classes, orderedEquals(['foo', 'baz'])); | 125 expect(classes, orderedEquals(['foo', 'baz'])); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 test('listContains', () { | 230 test('listContains', () { |
229 var elements = listElementSetup(); | 231 var elements = listElementSetup(); |
230 expect(elements.classes.contains('lassy'), isTrue); | 232 expect(elements.classes.contains('lassy'), isTrue); |
231 expect(elements.classes.contains('foo'), isFalse); | 233 expect(elements.classes.contains('foo'), isFalse); |
232 document.documentElement.children.remove(listElement); | 234 document.documentElement.children.remove(listElement); |
233 }); | 235 }); |
234 | 236 |
235 | 237 |
236 test('listAdd', () { | 238 test('listAdd', () { |
237 var elements = listElementSetup(); | 239 var elements = listElementSetup(); |
238 elements.classes.add('lassie'); | 240 var added = elements.classes.add('lassie'); |
| 241 expect(added, isNull); |
| 242 |
239 expect(elements.classes, | 243 expect(elements.classes, |
240 unorderedEquals(['lassie', 'qux', 'quux', 'meta', 'classy', 'lassy'])); | 244 unorderedEquals(['lassie', 'qux', 'quux', 'meta', 'classy', 'lassy'])); |
241 for (Element e in elements) { | 245 for (Element e in elements) { |
242 expect(e.classes, anyOf(unorderedEquals(['quux', 'qux', 'lassie']), | 246 expect(e.classes, anyOf(unorderedEquals(['quux', 'qux', 'lassie']), |
243 unorderedEquals(['meta', 'lassie']), | 247 unorderedEquals(['meta', 'lassie']), |
244 unorderedEquals(['classy', 'lassy', 'lassie']), | 248 unorderedEquals(['classy', 'lassy', 'lassie']), |
245 unorderedEquals(['qux', 'lassy', 'lassie']))); | 249 unorderedEquals(['qux', 'lassy', 'lassie']))); |
246 } | 250 } |
247 document.documentElement.children.remove(listElement); | 251 document.documentElement.children.remove(listElement); |
248 }); | 252 }); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 document.documentElement.children.remove(listElement); | 328 document.documentElement.children.remove(listElement); |
325 }); | 329 }); |
326 | 330 |
327 test('listContainsAll', () { | 331 test('listContainsAll', () { |
328 var elements = listElementSetup(); | 332 var elements = listElementSetup(); |
329 expect(elements.classes.containsAll(['qux', 'meta', 'mornin']), isFalse); | 333 expect(elements.classes.containsAll(['qux', 'meta', 'mornin']), isFalse); |
330 expect(elements.classes.containsAll(['qux', 'lassy', 'classy']), isTrue); | 334 expect(elements.classes.containsAll(['qux', 'lassy', 'classy']), isTrue); |
331 document.documentElement.children.remove(listElement); | 335 document.documentElement.children.remove(listElement); |
332 }); | 336 }); |
333 } | 337 } |
OLD | NEW |