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 | 5 |
6 Node makeNode() => new Element.tag('div'); | 6 Node makeNode() => new Element.tag('div'); |
7 Node makeNodeWithChildren() => | 7 Node makeNodeWithChildren() => |
8 new Element.html("<div>Foo<br/><!--baz--></div>"); | 8 new Element.html("<div>Foo<br/><!--baz--></div>"); |
9 | 9 |
10 void testNode() { | 10 void testNode() { |
11 group('nodes', () { | 11 group('nodes', () { |
| 12 test('is a NodeList', () { |
| 13 Expect.isTrue(makeNodeWithChildren().nodes is NodeList); |
| 14 }); |
| 15 |
12 test('first', () { | 16 test('first', () { |
13 var node = makeNodeWithChildren(); | 17 var node = makeNodeWithChildren(); |
14 Expect.isTrue(node.nodes.first is Text); | 18 Expect.isTrue(node.nodes.first is Text); |
15 }); | 19 }); |
16 | 20 |
17 test('last', () { | 21 test('last', () { |
18 var node = makeNodeWithChildren(); | 22 var node = makeNodeWithChildren(); |
19 Expect.isTrue(node.nodes.last() is Comment); | 23 Expect.isTrue(node.nodes.last() is Comment); |
20 }); | 24 }); |
21 | 25 |
22 test('forEach', () { | 26 test('forEach', () { |
23 var nodes = []; | 27 var nodes = []; |
24 var node = makeNodeWithChildren(); | 28 var node = makeNodeWithChildren(); |
25 node.nodes.forEach((n) => nodes.add(n)); | 29 node.nodes.forEach((n) => nodes.add(n)); |
26 Expect.isTrue(nodes[0] is Text); | 30 Expect.isTrue(nodes[0] is Text); |
27 Expect.isTrue(nodes[1] is BRElement); | 31 Expect.isTrue(nodes[1] is BRElement); |
28 Expect.isTrue(nodes[2] is Comment); | 32 Expect.isTrue(nodes[2] is Comment); |
29 }); | 33 }); |
30 | 34 |
31 test('filter', () { | 35 test('filter', () { |
32 var filtered = makeNodeWithChildren().nodes.filter((n) => n is BRElement); | 36 var filtered = makeNodeWithChildren().nodes.filter((n) => n is BRElement); |
33 Expect.equals(1, filtered.length); | 37 Expect.equals(1, filtered.length); |
34 Expect.isTrue(filtered[0] is BRElement); | 38 Expect.isTrue(filtered[0] is BRElement); |
| 39 Expect.isTrue(filtered is NodeList); |
35 }); | 40 }); |
36 | 41 |
37 test('every', () { | 42 test('every', () { |
38 var node = makeNodeWithChildren(); | 43 var node = makeNodeWithChildren(); |
39 Expect.isTrue(node.nodes.every((n) => n is Node)); | 44 Expect.isTrue(node.nodes.every((n) => n is Node)); |
40 Expect.isFalse(node.nodes.every((n) => n is Comment)); | 45 Expect.isFalse(node.nodes.every((n) => n is Comment)); |
41 }); | 46 }); |
42 | 47 |
43 test('some', () { | 48 test('some', () { |
44 var node = makeNodeWithChildren(); | 49 var node = makeNodeWithChildren(); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 Expect.listEquals([], node.nodes); | 120 Expect.listEquals([], node.nodes); |
116 }); | 121 }); |
117 | 122 |
118 test('removeLast', () { | 123 test('removeLast', () { |
119 var node = makeNodeWithChildren(); | 124 var node = makeNodeWithChildren(); |
120 Expect.isTrue(node.nodes.removeLast() is Comment); | 125 Expect.isTrue(node.nodes.removeLast() is Comment); |
121 Expect.equals(2, node.nodes.length); | 126 Expect.equals(2, node.nodes.length); |
122 Expect.isTrue(node.nodes.removeLast() is BRElement); | 127 Expect.isTrue(node.nodes.removeLast() is BRElement); |
123 Expect.equals(1, node.nodes.length); | 128 Expect.equals(1, node.nodes.length); |
124 }); | 129 }); |
| 130 |
| 131 test('getRange', () { |
| 132 var node = makeNodeWithChildren(); |
| 133 Expect.isTrue(node.nodes.getRange(1, 2) is NodeList); |
| 134 }); |
| 135 }); |
| 136 |
| 137 group('_NodeList', () { |
| 138 NodeList makeNodeList() => |
| 139 makeNodeWithChildren().nodes.filter((_) => true); |
| 140 |
| 141 test('first', () { |
| 142 var nodes = makeNodeList(); |
| 143 Expect.isTrue(nodes.first is Text); |
| 144 }); |
| 145 |
| 146 test('filter', () { |
| 147 var filtered = makeNodeList().filter((n) => n is BRElement); |
| 148 Expect.equals(1, filtered.length); |
| 149 Expect.isTrue(filtered[0] is BRElement); |
| 150 Expect.isTrue(filtered is NodeList); |
| 151 }); |
| 152 |
| 153 test('getRange', () { |
| 154 var range = makeNodeList().getRange(1, 2); |
| 155 Expect.isTrue(range is NodeList); |
| 156 Expect.isTrue(range[0] is BRElement); |
| 157 Expect.isTrue(range[1] is Comment); |
| 158 }); |
125 }); | 159 }); |
126 } | 160 } |
OLD | NEW |