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

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

Issue 13852008: Removing redundant collection methods from DOM collections. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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
« no previous file with comments | « tests/html/element_test.dart ('k') | tools/dom/src/WrappedList.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 NodeTest; 5 library NodeTest;
6 import '../../pkg/unittest/lib/unittest.dart'; 6 import '../../pkg/unittest/lib/unittest.dart';
7 import '../../pkg/unittest/lib/html_individual_config.dart'; 7 import '../../pkg/unittest/lib/html_individual_config.dart';
8 import 'dart:html'; 8 import 'dart:html';
9 import 'dart:svg' as svg; 9 import 'dart:svg' as svg;
10 10
11 Node makeNode() => new Element.tag('div'); 11 Node makeNode() => new Element.tag('div');
12 Node makeNodeWithChildren() => 12 Node makeNodeWithChildren() =>
13 new Element.html("<div>Foo<br/><!--baz--></div>"); 13 new Element.html("<div>Foo<br/><!--baz--></div>");
14 14
15 void testUnsupported(String name, void f()) {
16 test(name, () {
17 expect(f, throwsUnsupportedError);
18 });
19 }
20
15 main() { 21 main() {
16 useHtmlIndividualConfiguration(); 22 useHtmlIndividualConfiguration();
17 23
18 var isText = predicate((x) => x is Text, 'is a Text'); 24 var isText = predicate((x) => x is Text, 'is a Text');
19 var isComment = predicate((x) => x is Comment, 'is a Comment'); 25 var isComment = predicate((x) => x is Comment, 'is a Comment');
20 var isBRElement = predicate((x) => x is BRElement, 'is a BRElement'); 26 var isBRElement = predicate((x) => x is BRElement, 'is a BRElement');
21 var isHRElement = predicate((x) => x is HRElement, 'is a HRElement'); 27 var isHRElement = predicate((x) => x is HRElement, 'is a HRElement');
22 var isNodeList = predicate((x) => x is List<Node>, 'is a List<Node>'); 28 var isNodeList = predicate((x) => x is List<Node>, 'is a List<Node>');
23 var isImageElement = 29 var isImageElement =
24 predicate((x) => x is ImageElement, 'is an ImageElement'); 30 predicate((x) => x is ImageElement, 'is an ImageElement');
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 }); 255 });
250 256
251 test('removeLast', () { 257 test('removeLast', () {
252 var node = makeNodeWithChildren(); 258 var node = makeNodeWithChildren();
253 expect(node.nodes.removeLast(), isComment); 259 expect(node.nodes.removeLast(), isComment);
254 expect(node.nodes.length, 2); 260 expect(node.nodes.length, 2);
255 expect(node.nodes.removeLast(), isBRElement); 261 expect(node.nodes.removeLast(), isBRElement);
256 expect(node.nodes.length, 1); 262 expect(node.nodes.length, 1);
257 }); 263 });
258 264
265 test('getRange', () {
266 var items = makeNodeWithChildren().nodes.getRange(0, 1);
267 expect(items.length, 1);
268 expect(items.first, isText);
269 });
270
259 test('sublist', () { 271 test('sublist', () {
260 var node = makeNodeWithChildren(); 272 var node = makeNodeWithChildren();
261 expect(node.nodes.sublist(1, 3), isNodeList); 273 expect(node.nodes.sublist(1, 3), isNodeList);
262 }); 274 });
275
276 test('insertAll', () {
277 var node = makeNodeWithChildren();
278 var b = new DivElement();
279 b.nodes.addAll([
280 new HRElement(),
281 new ImageElement(),
282 new InputElement()
283 ]);
284 node.nodes.insertAll(1, b.nodes);
285 expect(node.nodes[0], isText);
286 expect(node.nodes[1], isHRElement);
287 expect(node.nodes[2], isImageElement);
288 expect(node.nodes[3], isInputElement);
289 expect(node.nodes[4], isBRElement);
290 expect(node.nodes[5], isComment);
291
292 var nodes = [
293 new HRElement(),
294 new ImageElement(),
295 new InputElement()
296 ];
297 node.nodes.insertAll(5, nodes);
298
299 expect(node.nodes[0], isText);
300 expect(node.nodes[1], isHRElement);
301 expect(node.nodes[2], isImageElement);
302 expect(node.nodes[3], isInputElement);
303 expect(node.nodes[4], isBRElement);
304 expect(node.nodes[5], isHRElement);
305 expect(node.nodes[6], isImageElement);
306 expect(node.nodes[7], isInputElement);
307 expect(node.nodes[8], isComment);
308 });
309
310 testUnsupported('removeRange', () {
311 makeNodeWithChildren().nodes.removeRange(0, 1);
312 });
313
314 testUnsupported('replaceRange', () {
315 makeNodeWithChildren().nodes.replaceRange(0, 1, [new InputElement()]);
316 });
317
318 testUnsupported('fillRange', () {
319 makeNodeWithChildren().nodes.fillRange(0, 1, null);
320 });
321
322 testUnsupported('setAll', () {
323 makeNodeWithChildren().nodes.setAll(0, [new InputElement()]);
324 });
263 }); 325 });
264 326
265 group('_NodeList', () { 327 group('_NodeList', () {
266 List<Node> makeNodeList() => 328 List<Node> makeNodeList() =>
267 makeNodeWithChildren().nodes.where((_) => true).toList(); 329 makeNodeWithChildren().nodes.where((_) => true).toList();
268 330
269 test('first', () { 331 test('first', () {
270 var nodes = makeNodeList(); 332 var nodes = makeNodeList();
271 expect(nodes.first, isText); 333 expect(nodes.first, isText);
272 }); 334 });
273 335
274 test('where', () { 336 test('where', () {
275 var filtered = makeNodeList().where((n) => n is BRElement).toList(); 337 var filtered = makeNodeList().where((n) => n is BRElement).toList();
276 expect(filtered.length, 1); 338 expect(filtered.length, 1);
277 expect(filtered[0], isBRElement); 339 expect(filtered[0], isBRElement);
278 expect(filtered, isNodeList); 340 expect(filtered, isNodeList);
279 }); 341 });
280 342
281 test('sublist', () { 343 test('sublist', () {
282 var range = makeNodeList().sublist(1, 3); 344 var range = makeNodeList().sublist(1, 3);
283 expect(range, isNodeList); 345 expect(range, isNodeList);
284 expect(range[0], isBRElement); 346 expect(range[0], isBRElement);
285 expect(range[1], isComment); 347 expect(range[1], isComment);
286 }); 348 });
287 }); 349 });
288 } 350 }
OLDNEW
« no previous file with comments | « tests/html/element_test.dart ('k') | tools/dom/src/WrappedList.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698