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

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

Issue 13934019: Revert "With the collections deriving from ListBase, we no longer need to implement a number of boi… (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
21 main() { 15 main() {
22 useHtmlIndividualConfiguration(); 16 useHtmlIndividualConfiguration();
23 17
24 var isText = predicate((x) => x is Text, 'is a Text'); 18 var isText = predicate((x) => x is Text, 'is a Text');
25 var isComment = predicate((x) => x is Comment, 'is a Comment'); 19 var isComment = predicate((x) => x is Comment, 'is a Comment');
26 var isBRElement = predicate((x) => x is BRElement, 'is a BRElement'); 20 var isBRElement = predicate((x) => x is BRElement, 'is a BRElement');
27 var isHRElement = predicate((x) => x is HRElement, 'is a HRElement'); 21 var isHRElement = predicate((x) => x is HRElement, 'is a HRElement');
28 var isNodeList = predicate((x) => x is List<Node>, 'is a List<Node>'); 22 var isNodeList = predicate((x) => x is List<Node>, 'is a List<Node>');
29 var isImageElement = 23 var isImageElement =
30 predicate((x) => x is ImageElement, 'is an ImageElement'); 24 predicate((x) => x is ImageElement, 'is an ImageElement');
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 }); 249 });
256 250
257 test('removeLast', () { 251 test('removeLast', () {
258 var node = makeNodeWithChildren(); 252 var node = makeNodeWithChildren();
259 expect(node.nodes.removeLast(), isComment); 253 expect(node.nodes.removeLast(), isComment);
260 expect(node.nodes.length, 2); 254 expect(node.nodes.length, 2);
261 expect(node.nodes.removeLast(), isBRElement); 255 expect(node.nodes.removeLast(), isBRElement);
262 expect(node.nodes.length, 1); 256 expect(node.nodes.length, 1);
263 }); 257 });
264 258
265 test('getRange', () {
266 var items = makeNodeWithChildren().nodes.getRange(0, 1);
267 expect(items.length, 1);
268 expect(items.first, isText);
269 });
270
271 test('sublist', () { 259 test('sublist', () {
272 var node = makeNodeWithChildren(); 260 var node = makeNodeWithChildren();
273 expect(node.nodes.sublist(1, 3), isNodeList); 261 expect(node.nodes.sublist(1, 3), isNodeList);
274 }); 262 });
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 });
325 }); 263 });
326 264
327 group('_NodeList', () { 265 group('_NodeList', () {
328 List<Node> makeNodeList() => 266 List<Node> makeNodeList() =>
329 makeNodeWithChildren().nodes.where((_) => true).toList(); 267 makeNodeWithChildren().nodes.where((_) => true).toList();
330 268
331 test('first', () { 269 test('first', () {
332 var nodes = makeNodeList(); 270 var nodes = makeNodeList();
333 expect(nodes.first, isText); 271 expect(nodes.first, isText);
334 }); 272 });
335 273
336 test('where', () { 274 test('where', () {
337 var filtered = makeNodeList().where((n) => n is BRElement).toList(); 275 var filtered = makeNodeList().where((n) => n is BRElement).toList();
338 expect(filtered.length, 1); 276 expect(filtered.length, 1);
339 expect(filtered[0], isBRElement); 277 expect(filtered[0], isBRElement);
340 expect(filtered, isNodeList); 278 expect(filtered, isNodeList);
341 }); 279 });
342 280
343 test('sublist', () { 281 test('sublist', () {
344 var range = makeNodeList().sublist(1, 3); 282 var range = makeNodeList().sublist(1, 3);
345 expect(range, isNodeList); 283 expect(range, isNodeList);
346 expect(range[0], isBRElement); 284 expect(range[0], isBRElement);
347 expect(range[1], isComment); 285 expect(range[1], isComment);
348 }); 286 });
349 }); 287 });
350 } 288 }
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