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

Side by Side Diff: tests/html/element_classes_test.dart

Issue 1098073003: Revert "Enforce token syntax for CssClassSet arguments" (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 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
« no previous file with comments | « sdk/lib/html/html_common/css_class_set.dart ('k') | tests/html/svgelement_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 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
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
141 test('add', () { 132 test('add', () {
142 final classes = makeClassSet(); 133 final classes = makeClassSet();
143 var added = classes.add('qux'); 134 var added = classes.add('qux');
144 expect(added, isTrue); 135 expect(added, isTrue);
145 expect(classes, orderedEquals(['foo', 'bar', 'baz', 'qux'])); 136 expect(classes, orderedEquals(['foo', 'bar', 'baz', 'qux']));
146 137
147 added = classes.add('qux'); 138 added = classes.add('qux');
148 expect(added, isFalse); 139 expect(added, isFalse);
149 final list = new List.from(classes); 140 final list = new List.from(classes);
150 list.sort((a, b) => a.compareTo(b)); 141 list.sort((a, b) => a.compareTo(b));
151 expect(list, orderedEquals(['bar', 'baz', 'foo', 'qux']), 142 expect(list, orderedEquals(['bar', 'baz', 'foo', 'qux']),
152 reason: "The class set shouldn't have duplicate elements."); 143 reason: "The class set shouldn't have duplicate elements.");
153 }); 144 });
154 145
155 test('add-bad', () {
156 final classes = makeClassSet();
157 expect(() => classes.add(''), throws);
158 expect(() => classes.add('foo bar'), throws);
159 });
160
161 test('remove', () { 146 test('remove', () {
162 final classes = makeClassSet(); 147 final classes = makeClassSet();
163 classes.remove('bar'); 148 classes.remove('bar');
164 expect(classes, orderedEquals(['foo', 'baz'])); 149 expect(classes, orderedEquals(['foo', 'baz']));
165 classes.remove('qux'); 150 classes.remove('qux');
166 expect(classes, orderedEquals(['foo', 'baz'])); 151 expect(classes, orderedEquals(['foo', 'baz']));
167 }); 152 });
168 153
169 test('remove-bad', () {
170 final classes = makeClassSet();
171 expect(() => classes.remove(''), throws);
172 expect(() => classes.remove('foo bar'), throws);
173 });
174
175 test('toggle', () { 154 test('toggle', () {
176 final classes = makeClassSet(); 155 final classes = makeClassSet();
177 classes.toggle('bar'); 156 classes.toggle('bar');
178 expect(classes, orderedEquals(['foo', 'baz'])); 157 expect(classes, orderedEquals(['foo', 'baz']));
179 classes.toggle('qux'); 158 classes.toggle('qux');
180 expect(classes, orderedEquals(['foo', 'baz', 'qux'])); 159 expect(classes, orderedEquals(['foo', 'baz', 'qux']));
181 160
182 classes.toggle('qux', true); 161 classes.toggle('qux', true);
183 expect(classes, orderedEquals(['foo', 'baz', 'qux'])); 162 expect(classes, orderedEquals(['foo', 'baz', 'qux']));
184 classes.toggle('qux', false); 163 classes.toggle('qux', false);
185 expect(classes, orderedEquals(['foo', 'baz'])); 164 expect(classes, orderedEquals(['foo', 'baz']));
186 classes.toggle('qux', false); 165 classes.toggle('qux', false);
187 expect(classes, orderedEquals(['foo', 'baz'])); 166 expect(classes, orderedEquals(['foo', 'baz']));
188 classes.toggle('qux', true); 167 classes.toggle('qux', true);
189 expect(classes, orderedEquals(['foo', 'baz', 'qux'])); 168 expect(classes, orderedEquals(['foo', 'baz', 'qux']));
190 }); 169 });
191 170
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
202 test('addAll', () { 171 test('addAll', () {
203 final classes = makeClassSet(); 172 final classes = makeClassSet();
204 classes.addAll(['bar', 'qux', 'bip']); 173 classes.addAll(['bar', 'qux', 'bip']);
205 expect(classes, orderedEquals(['foo', 'bar', 'baz', 'qux', 'bip'])); 174 expect(classes, orderedEquals(['foo', 'bar', 'baz', 'qux', 'bip']));
206 }); 175 });
207 176
208 test('removeAll', () { 177 test('removeAll', () {
209 final classes = makeClassSet(); 178 final classes = makeClassSet();
210 classes.removeAll(['bar', 'baz', 'qux']); 179 classes.removeAll(['bar', 'baz', 'qux']);
211 expect(classes, orderedEquals(['foo'])); 180 expect(classes, orderedEquals(['foo']));
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 expect(view(elements.classes), '[quux, qux]'); 357 expect(view(elements.classes), '[quux, qux]');
389 expect(view(elements), '[[quux, qux], [], [], [qux]]'); 358 expect(view(elements), '[[quux, qux], [], [], [qux]]');
390 }); 359 });
391 360
392 test('listContainsAll', () { 361 test('listContainsAll', () {
393 var elements = listElementSetup(); 362 var elements = listElementSetup();
394 expect(elements.classes.containsAll(['qux', 'meta', 'mornin']), isFalse); 363 expect(elements.classes.containsAll(['qux', 'meta', 'mornin']), isFalse);
395 expect(elements.classes.containsAll(['qux', 'lassy', 'classy']), isTrue); 364 expect(elements.classes.containsAll(['qux', 'lassy', 'classy']), isTrue);
396 }); 365 });
397 } 366 }
OLDNEW
« no previous file with comments | « sdk/lib/html/html_common/css_class_set.dart ('k') | tests/html/svgelement_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698