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

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

Issue 11275054: Modified unittest to use new argument syntax. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 1 month 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
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/unittest.dart'); 6 #import('../../pkg/unittest/unittest.dart');
7 #import('../../pkg/unittest/html_config.dart'); 7 #import('../../pkg/unittest/html_config.dart');
8 #import('dart:html'); 8 #import('dart:html');
9 9
10 Node makeNode() => new Element.tag('div'); 10 Node makeNode() => new Element.tag('div');
11 Node makeNodeWithChildren() => 11 Node makeNodeWithChildren() =>
12 new Element.html("<div>Foo<br/><!--baz--></div>"); 12 new Element.html("<div>Foo<br/><!--baz--></div>");
13 13
14 main() { 14 main() {
15 useHtmlConfiguration(); 15 useHtmlConfiguration();
16 16
17 var isText = new isInstanceOf<Text>('Text');
18 var isComment = new isInstanceOf<Comment>('Comment');
19 var isBRElement = new isInstanceOf<BRElement>('BRElement');
20 var isHRElement = new isInstanceOf<HRElement>('HRElement');
21 var isNodeList = new isInstanceOf<List<Node>>('List<Node>');
22 var isImageElement = new isInstanceOf<ImageElement>('ImageElement');
23 var isInputElement = new isInstanceOf<InputElement>('InputElement');
24
17 test('replaceWith', () { 25 test('replaceWith', () {
18 final node = makeNodeWithChildren(); 26 final node = makeNodeWithChildren();
19 final subnode = node.nodes[1]; 27 final subnode = node.nodes[1];
20 final out = subnode.replaceWith(new Text('Bar')); 28 final out = subnode.replaceWith(new Text('Bar'));
21 Expect.equals(subnode, out, '#replaceWith should be chainable'); 29 expect(out, equals(subnode), reason: '#replaceWith should be chainable');
22 Expect.equals(3, node.nodes.length); 30 expect(node.nodes.length, 3);
23 Expect.isTrue(node.nodes[0] is Text); 31 expect(node.nodes[0], isText);
24 Expect.equals('Foo', node.nodes[0].text); 32 expect(node.nodes[0].text, 'Foo');
25 Expect.isTrue(node.nodes[1] is Text); 33 expect(node.nodes[1], isText);
26 Expect.equals('Bar', node.nodes[1].text); 34 expect(node.nodes[1].text, 'Bar');
27 Expect.isTrue(node.nodes[2] is Comment); 35 expect(node.nodes[2], isComment);
28 }); 36 });
29 37
30 test('remove', () { 38 test('remove', () {
31 final node = makeNodeWithChildren(); 39 final node = makeNodeWithChildren();
32 final subnode = node.nodes[1]; 40 final subnode = node.nodes[1];
33 final out = subnode.remove(); 41 final out = subnode.remove();
34 Expect.isNull(out); 42 expect(out, isNull);
35 Expect.equals(2, node.nodes.length); 43 expect(node.nodes.length, 2);
36 Expect.isTrue(node.nodes[0] is Text); 44 expect(node.nodes[0], isText);
37 Expect.isTrue(node.nodes[1] is Comment); 45 expect(node.nodes[1], isComment);
38 }); 46 });
39 47
40 test('contains', () { 48 test('contains', () {
41 final Node node = new Element.html("<div>Foo<span>Bar</span></div>"); 49 final Node node = new Element.html("<div>Foo<span>Bar</span></div>");
42 Expect.isTrue(node.contains(node.nodes.first)); 50 expect(node.contains(node.nodes.first), isTrue);
43 Expect.isTrue(node.contains(node.nodes[1].nodes.first)); 51 expect(node.contains(node.nodes[1].nodes.first), isTrue);
44 Expect.isFalse(node.contains(new Text('Foo'))); 52 expect(node.contains(new Text('Foo')), isFalse);
45 }); 53 });
46 54
47 group('nodes', () { 55 group('nodes', () {
48 test('is a NodeList', () { 56 test('is a NodeList', () {
49 Expect.isTrue(makeNodeWithChildren().nodes is List<Node>); 57 expect(makeNodeWithChildren().nodes, isNodeList);
50 }); 58 });
51 59
52 test('first', () { 60 test('first', () {
53 var node = makeNodeWithChildren(); 61 var node = makeNodeWithChildren();
54 Expect.isTrue(node.nodes.first is Text); 62 expect(node.nodes.first, isText);
55 }); 63 });
56 64
57 test('last', () { 65 test('last', () {
58 var node = makeNodeWithChildren(); 66 var node = makeNodeWithChildren();
59 Expect.isTrue(node.nodes.last is Comment); 67 expect(node.nodes.last, isComment);
60 }); 68 });
61 69
62 test('forEach', () { 70 test('forEach', () {
63 var nodes = []; 71 var nodes = [];
64 var node = makeNodeWithChildren(); 72 var node = makeNodeWithChildren();
65 node.nodes.forEach((n) => nodes.add(n)); 73 node.nodes.forEach((n) => nodes.add(n));
66 Expect.isTrue(nodes[0] is Text); 74 expect(nodes[0], isText);
67 Expect.isTrue(nodes[1] is BRElement); 75 expect(nodes[1], isBRElement);
68 Expect.isTrue(nodes[2] is Comment); 76 expect(nodes[2], isComment);
69 }); 77 });
70 78
71 test('filter', () { 79 test('filter', () {
72 var filtered = makeNodeWithChildren().nodes.filter((n) => n is BRElement); 80 var filtered = makeNodeWithChildren().nodes.filter((n) => n is BRElement);
73 Expect.equals(1, filtered.length); 81 expect(filtered.length, 1);
74 Expect.isTrue(filtered[0] is BRElement); 82 expect(filtered[0], isBRElement);
75 Expect.isTrue(filtered is List<Node>); 83 expect(filtered, isNodeList);
76 }); 84 });
77 85
78 test('every', () { 86 test('every', () {
79 var node = makeNodeWithChildren(); 87 var node = makeNodeWithChildren();
80 Expect.isTrue(node.nodes.every((n) => n is Node)); 88 expect(node.nodes.every((n) => n is Node), isTrue);
81 Expect.isFalse(node.nodes.every((n) => n is Comment)); 89 expect(node.nodes.every((n) => n is Comment), isFalse);
82 }); 90 });
83 91
84 test('some', () { 92 test('some', () {
85 var node = makeNodeWithChildren(); 93 var node = makeNodeWithChildren();
86 Expect.isTrue(node.nodes.some((n) => n is Comment)); 94 expect(node.nodes.some((n) => n is Comment), isTrue);
87 Expect.isFalse(node.nodes.some((n) => n is SVGElement)); 95 expect(node.nodes.some((n) => n is SVGElement), isFalse);
88 }); 96 });
89 97
90 test('isEmpty', () { 98 test('isEmpty', () {
91 Expect.isTrue(makeNode().nodes.isEmpty); 99 expect(makeNode().nodes.isEmpty, isTrue);
92 Expect.isFalse(makeNodeWithChildren().nodes.isEmpty); 100 expect(makeNodeWithChildren().nodes.isEmpty, isFalse);
93 }); 101 });
94 102
95 test('length', () { 103 test('length', () {
96 Expect.equals(0, makeNode().nodes.length); 104 expect(makeNode().nodes.length, 0);
97 Expect.equals(3, makeNodeWithChildren().nodes.length); 105 expect(makeNodeWithChildren().nodes.length, 3);
98 }); 106 });
99 107
100 test('[]', () { 108 test('[]', () {
101 var node = makeNodeWithChildren(); 109 var node = makeNodeWithChildren();
102 Expect.isTrue(node.nodes[0] is Text); 110 expect(node.nodes[0], isText);
103 Expect.isTrue(node.nodes[1] is BRElement); 111 expect(node.nodes[1], isBRElement);
104 Expect.isTrue(node.nodes[2] is Comment); 112 expect(node.nodes[2], isComment);
105 }); 113 });
106 114
107 test('[]=', () { 115 test('[]=', () {
108 var node = makeNodeWithChildren(); 116 var node = makeNodeWithChildren();
109 node.nodes[1] = new Element.tag('hr'); 117 node.nodes[1] = new Element.tag('hr');
110 Expect.isTrue(node.nodes[0] is Text); 118 expect(node.nodes[0], isText);
111 Expect.isTrue(node.nodes[1] is HRElement); 119 expect(node.nodes[1], isHRElement);
112 Expect.isTrue(node.nodes[2] is Comment); 120 expect(node.nodes[2], isComment);
113 }); 121 });
114 122
115 test('add', () { 123 test('add', () {
116 var node = makeNode(); 124 var node = makeNode();
117 node.nodes.add(new Element.tag('hr')); 125 node.nodes.add(new Element.tag('hr'));
118 Expect.isTrue(node.nodes.last is HRElement); 126 expect(node.nodes.last, isHRElement);
119 }); 127 });
120 128
121 test('addLast', () { 129 test('addLast', () {
122 var node = makeNode(); 130 var node = makeNode();
123 node.nodes.addLast(new Element.tag('hr')); 131 node.nodes.addLast(new Element.tag('hr'));
124 Expect.isTrue(node.nodes.last is HRElement); 132 expect(node.nodes.last, isHRElement);
125 }); 133 });
126 134
127 test('iterator', () { 135 test('iterator', () {
128 var nodes = []; 136 var nodes = [];
129 var node = makeNodeWithChildren(); 137 var node = makeNodeWithChildren();
130 for (var subnode in node.nodes) { 138 for (var subnode in node.nodes) {
131 nodes.add(subnode); 139 nodes.add(subnode);
132 } 140 }
133 Expect.isTrue(nodes[0] is Text); 141 expect(nodes[0], isText);
134 Expect.isTrue(nodes[1] is BRElement); 142 expect(nodes[1], isBRElement);
135 Expect.isTrue(nodes[2] is Comment); 143 expect(nodes[2], isComment);
136 }); 144 });
137 145
138 test('addAll', () { 146 test('addAll', () {
139 var node = makeNodeWithChildren(); 147 var node = makeNodeWithChildren();
140 node.nodes.addAll([ 148 node.nodes.addAll([
141 new Element.tag('hr'), 149 new Element.tag('hr'),
142 new Element.tag('img'), 150 new Element.tag('img'),
143 new Element.tag('input') 151 new Element.tag('input')
144 ]); 152 ]);
145 Expect.isTrue(node.nodes[0] is Text); 153 expect(node.nodes[0], isText);
146 Expect.isTrue(node.nodes[1] is BRElement); 154 expect(node.nodes[1], isBRElement);
147 Expect.isTrue(node.nodes[2] is Comment); 155 expect(node.nodes[2], isComment);
148 Expect.isTrue(node.nodes[3] is HRElement); 156 expect(node.nodes[3], isHRElement);
149 Expect.isTrue(node.nodes[4] is ImageElement); 157 expect(node.nodes[4], isImageElement);
150 Expect.isTrue(node.nodes[5] is InputElement); 158 expect(node.nodes[5], isInputElement);
151 }); 159 });
152 160
153 test('clear', () { 161 test('clear', () {
154 var node = makeNodeWithChildren(); 162 var node = makeNodeWithChildren();
155 node.nodes.clear(); 163 node.nodes.clear();
156 Expect.listEquals([], node.nodes); 164 expect(node.nodes, []);
157 }); 165 });
158 166
159 test('removeLast', () { 167 test('removeLast', () {
160 var node = makeNodeWithChildren(); 168 var node = makeNodeWithChildren();
161 Expect.isTrue(node.nodes.removeLast() is Comment); 169 expect(node.nodes.removeLast(), isComment);
162 Expect.equals(2, node.nodes.length); 170 expect(node.nodes.length, 2);
163 Expect.isTrue(node.nodes.removeLast() is BRElement); 171 expect(node.nodes.removeLast(), isBRElement);
164 Expect.equals(1, node.nodes.length); 172 expect(node.nodes.length, 1);
165 }); 173 });
166 174
167 test('getRange', () { 175 test('getRange', () {
168 var node = makeNodeWithChildren(); 176 var node = makeNodeWithChildren();
169 Expect.isTrue(node.nodes.getRange(1, 2) is List<Node>); 177 expect(node.nodes.getRange(1, 2), isNodeList);
170 }); 178 });
171 }); 179 });
172 180
173 group('_NodeList', () { 181 group('_NodeList', () {
174 List<Node> makeNodeList() => 182 List<Node> makeNodeList() =>
175 makeNodeWithChildren().nodes.filter((_) => true); 183 makeNodeWithChildren().nodes.filter((_) => true);
176 184
177 test('first', () { 185 test('first', () {
178 var nodes = makeNodeList(); 186 var nodes = makeNodeList();
179 Expect.isTrue(nodes.first is Text); 187 expect(nodes.first, isText);
180 }); 188 });
181 189
182 test('filter', () { 190 test('filter', () {
183 var filtered = makeNodeList().filter((n) => n is BRElement); 191 var filtered = makeNodeList().filter((n) => n is BRElement);
184 Expect.equals(1, filtered.length); 192 expect(filtered.length, 1);
185 Expect.isTrue(filtered[0] is BRElement); 193 expect(filtered[0], isBRElement);
186 Expect.isTrue(filtered is List<Node>); 194 expect(filtered, isNodeList);
187 }); 195 });
188 196
189 test('getRange', () { 197 test('getRange', () {
190 var range = makeNodeList().getRange(1, 2); 198 var range = makeNodeList().getRange(1, 2);
191 Expect.isTrue(range is List<Node>); 199 expect(range, isNodeList);
192 Expect.isTrue(range[0] is BRElement); 200 expect(range[0], isBRElement);
193 Expect.isTrue(range[1] is Comment); 201 expect(range[1], isComment);
194 }); 202 });
195 }); 203 });
196 } 204 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698