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

Side by Side Diff: pkg/dev_compiler/test/codegen/lib/html/htmlcollection_test.dart

Issue 2413073002: Start cleaning up the HTML tests. (Closed)
Patch Set: Unfork expect.dart. Created 4 years, 2 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
OLDNEW
1 library ElementListTest;
2 import 'package:unittest/unittest.dart';
3 import 'package:unittest/html_config.dart';
4 import 'dart:html'; 1 import 'dart:html';
5 2
3 import 'package:minitest/minitest.dart';
4
5 bool isChecked(Element e) => (e as CheckboxInputElement).checked;
6 bool isUnchecked(Element e) => !(e as CheckboxInputElement).checked;
7
6 // Test that List<Element> implements List<T> 8 // Test that List<Element> implements List<T>
7 main() { 9 main() {
8 Element insertTestDiv() { 10 Element insertTestDiv() {
9 Element element = new Element.tag('div'); 11 Element element = new Element.tag('div');
10 element.innerHtml = r""" 12 element.innerHtml = r"""
11 <div id='allChecked'> 13 <div id='allChecked'>
12 <input type="checkbox" name="c1" value="1" checked="yes"> 14 <input type="checkbox" name="c1" value="1" checked="yes">
13 <input type="checkbox" name="c2" value="2" checked="yes"> 15 <input type="checkbox" name="c2" value="2" checked="yes">
14 <input type="checkbox" name="c3" value="3" checked="yes"> 16 <input type="checkbox" name="c3" value="3" checked="yes">
15 <input type="checkbox" name="c4" value="4" checked="yes"> 17 <input type="checkbox" name="c4" value="4" checked="yes">
16 </div> 18 </div>
17 <div id='someChecked'> 19 <div id='someChecked'>
18 <input type="checkbox" name="s1" value="1" checked="yes"> 20 <input type="checkbox" name="s1" value="1" checked="yes">
19 <input type="checkbox" name="s2" value="2"> 21 <input type="checkbox" name="s2" value="2">
20 <input type="checkbox" name="s3" value="3" checked="yes"> 22 <input type="checkbox" name="s3" value="3" checked="yes">
21 <input type="checkbox" name="s4" value="4"> 23 <input type="checkbox" name="s4" value="4">
22 </div> 24 </div>
23 <div id='noneChecked'> 25 <div id='noneChecked'>
24 <input type="checkbox" name="n1" value="1"> 26 <input type="checkbox" name="n1" value="1">
25 <input type="checkbox" name="n2" value="2"> 27 <input type="checkbox" name="n2" value="2">
26 <input type="checkbox" name="n3" value="3"> 28 <input type="checkbox" name="n3" value="3">
27 <input type="checkbox" name="n4" value="4"> 29 <input type="checkbox" name="n4" value="4">
28 </div> 30 </div>
29 <div id='emptyDiv'></div> 31 <div id='emptyDiv'></div>
30 """; 32 """;
31 document.body.append(element); 33 document.body.append(element);
32 return element; 34 return element;
33 } 35 }
34 36
35 useHtmlConfiguration();
36
37 test('IsList', () { 37 test('IsList', () {
38 Element root = insertTestDiv(); 38 Element root = insertTestDiv();
39 39
40 List<Element> eachChecked = 40 List<Element> eachChecked =
41 document.query('#allChecked').children; 41 document.query('#allChecked').children;
42 42
43 expect(eachChecked, isList); 43 expect(eachChecked is List, isTrue);
44 44
45 root.remove(); 45 root.remove();
46 }); 46 });
47 test('Every', () { 47 test('Every', () {
48 Element root = insertTestDiv(); 48 Element root = insertTestDiv();
49 49
50 List<Element> eachChecked = 50 List<Element> eachChecked =
51 document.query('#allChecked').children; 51 document.query('#allChecked').children;
52 52
53 List<Element> someChecked = 53 List<Element> someChecked =
54 document.query('#someChecked').children; 54 document.query('#someChecked').children;
55 55
56 List<Element> noneChecked = 56 List<Element> noneChecked =
57 document.query('#noneChecked').children; 57 document.query('#noneChecked').children;
58 58
59 expect(eachChecked.length, 4); 59 expect(eachChecked.length, 4);
60 expect(someChecked.length, 4); 60 expect(someChecked.length, 4);
61 expect(noneChecked.length, 4); 61 expect(noneChecked.length, 4);
62 62
63 expect(eachChecked.every((x) => x.checked), isTrue); 63 expect(eachChecked.every(isChecked), isTrue);
64 expect(eachChecked.every((x) => !x.checked), isFalse); 64 expect(eachChecked.every(isUnchecked), isFalse);
65 expect(someChecked.every((x) => x.checked), isFalse); 65 expect(someChecked.every(isChecked), isFalse);
66 expect(someChecked.every((x) => !x.checked), isFalse); 66 expect(someChecked.every(isUnchecked), isFalse);
67 expect(noneChecked.every((x) => x.checked), isFalse); 67 expect(noneChecked.every(isChecked), isFalse);
68 expect(noneChecked.every((x) => !x.checked), isTrue); 68 expect(noneChecked.every(isUnchecked), isTrue);
69 69
70 root.remove(); 70 root.remove();
71 }); 71 });
72 test('Some', () { 72 test('Some', () {
73 Element root = insertTestDiv(); 73 Element root = insertTestDiv();
74 74
75 List<Element> eachChecked = 75 List<Element> eachChecked =
76 document.query('#allChecked').children; 76 document.query('#allChecked').children;
77 77
78 List<Element> someChecked = 78 List<Element> someChecked =
79 document.query('#someChecked').children; 79 document.query('#someChecked').children;
80 80
81 List<Element> noneChecked = 81 List<Element> noneChecked =
82 document.query('#noneChecked').children; 82 document.query('#noneChecked').children;
83 83
84 expect(eachChecked.length, 4); 84 expect(eachChecked.length, 4);
85 expect(someChecked.length, 4); 85 expect(someChecked.length, 4);
86 expect(noneChecked.length, 4); 86 expect(noneChecked.length, 4);
87 87
88 expect(eachChecked.any((x) => x.checked), isTrue); 88 expect(eachChecked.any(isChecked), isTrue);
89 expect(eachChecked.any((x) => !x.checked), isFalse); 89 expect(eachChecked.any(isUnchecked), isFalse);
90 expect(someChecked.any((x) => x.checked), isTrue); 90 expect(someChecked.any(isChecked), isTrue);
91 expect(someChecked.any((x) => !x.checked), isTrue); 91 expect(someChecked.any(isUnchecked), isTrue);
92 expect(noneChecked.any((x) => x.checked), isFalse); 92 expect(noneChecked.any(isChecked), isFalse);
93 expect(noneChecked.any((x) => !x.checked), isTrue); 93 expect(noneChecked.any(isUnchecked), isTrue);
94 94
95 root.remove(); 95 root.remove();
96 }); 96 });
97 test('Filter', () { 97 test('Filter', () {
98 Element root = insertTestDiv(); 98 Element root = insertTestDiv();
99 99
100 List<Element> eachChecked = 100 List<Element> eachChecked =
101 document.query('#allChecked').children; 101 document.query('#allChecked').children;
102 102
103 List<Element> someChecked = 103 List<Element> someChecked =
104 document.query('#someChecked').children; 104 document.query('#someChecked').children;
105 105
106 List<Element> noneChecked = 106 List<Element> noneChecked =
107 document.query('#noneChecked').children; 107 document.query('#noneChecked').children;
108 108
109 expect(eachChecked.length, 4); 109 expect(eachChecked.length, 4);
110 expect(someChecked.length, 4); 110 expect(someChecked.length, 4);
111 expect(noneChecked.length, 4); 111 expect(noneChecked.length, 4);
112 112
113 expect(eachChecked.where((x) => x.checked).length, 4); 113 expect(eachChecked.where(isChecked).length, 4);
114 expect(eachChecked.where((x) => !x.checked).length, 0); 114 expect(eachChecked.where(isUnchecked).length, 0);
115 expect(someChecked.where((x) => x.checked).length, 2); 115 expect(someChecked.where(isChecked).length, 2);
116 expect(someChecked.where((x) => !x.checked).length, 2); 116 expect(someChecked.where(isUnchecked).length, 2);
117 expect(noneChecked.where((x) => x.checked).length, 0); 117 expect(noneChecked.where(isChecked).length, 0);
118 expect(noneChecked.where((x) => !x.checked).length, 4); 118 expect(noneChecked.where(isUnchecked).length, 4);
119 119
120 root.remove(); 120 root.remove();
121 }); 121 });
122 test('IsEmpty', () { 122 test('IsEmpty', () {
123 Element root = insertTestDiv(); 123 Element root = insertTestDiv();
124 124
125 List<Element> someChecked = 125 List<Element> someChecked =
126 document.query('#someChecked').children; 126 document.query('#someChecked').children;
127 127
128 List<Element> emptyDiv = 128 List<Element> emptyDiv =
(...skipping 25 matching lines...) Expand all
154 List<Element> someChecked = 154 List<Element> someChecked =
155 document.query('#someChecked').children; 155 document.query('#someChecked').children;
156 156
157 List<Element> noneChecked = 157 List<Element> noneChecked =
158 document.query('#noneChecked').children; 158 document.query('#noneChecked').children;
159 159
160 expect(eachChecked.length, 4); 160 expect(eachChecked.length, 4);
161 expect(someChecked.length, 4); 161 expect(someChecked.length, 4);
162 expect(noneChecked.length, 4); 162 expect(noneChecked.length, 4);
163 163
164 expect(countWithForEach(eachChecked, (x) => x.checked), 4); 164 expect(countWithForEach(eachChecked, isChecked), 4);
165 expect(countWithForEach(eachChecked, (x) => !x.checked), 0); 165 expect(countWithForEach(eachChecked, isUnchecked), 0);
166 expect(countWithForEach(someChecked, (x) => x.checked), 2); 166 expect(countWithForEach(someChecked, isChecked), 2);
167 expect(countWithForEach(someChecked, (x) => !x.checked), 2); 167 expect(countWithForEach(someChecked, isUnchecked), 2);
168 expect(countWithForEach(noneChecked, (x) => x.checked), 0); 168 expect(countWithForEach(noneChecked, isChecked), 0);
169 expect(countWithForEach(noneChecked, (x) => !x.checked), 4); 169 expect(countWithForEach(noneChecked, isUnchecked), 4);
170 170
171 root.remove(); 171 root.remove();
172 }); 172 });
173 173
174 int countWithForLoop(collection, predicate) { 174 int countWithForLoop(collection, predicate) {
175 int count = 0; 175 int count = 0;
176 for (var element in collection) { 176 for (var element in collection) {
177 if (predicate(element)) count++; 177 if (predicate(element)) count++;
178 } 178 }
179 return count; 179 return count;
180 } 180 }
181 181
182 test('ForLoop', () { // Uses iterator. 182 test('ForLoop', () { // Uses iterator.
183 Element root = insertTestDiv(); 183 Element root = insertTestDiv();
184 184
185 List<Element> eachChecked = 185 List<Element> eachChecked =
186 document.query('#allChecked').children; 186 document.query('#allChecked').children;
187 187
188 List<Element> someChecked = 188 List<Element> someChecked =
189 document.query('#someChecked').children; 189 document.query('#someChecked').children;
190 190
191 List<Element> noneChecked = 191 List<Element> noneChecked =
192 document.query('#noneChecked').children; 192 document.query('#noneChecked').children;
193 193
194 expect(eachChecked.length, 4); 194 expect(eachChecked.length, 4);
195 expect(someChecked.length, 4); 195 expect(someChecked.length, 4);
196 expect(noneChecked.length, 4); 196 expect(noneChecked.length, 4);
197 197
198 expect(countWithForLoop(eachChecked, (x) => x.checked), 4); 198 expect(countWithForLoop(eachChecked, isChecked), 4);
199 expect(countWithForLoop(eachChecked, (x) => !x.checked), 0); 199 expect(countWithForLoop(eachChecked, isUnchecked), 0);
200 expect(countWithForLoop(someChecked, (x) => x.checked), 2); 200 expect(countWithForLoop(someChecked, isChecked), 2);
201 expect(countWithForLoop(someChecked, (x) => !x.checked), 2); 201 expect(countWithForLoop(someChecked, isUnchecked), 2);
202 expect(countWithForLoop(noneChecked, (x) => x.checked), 0); 202 expect(countWithForLoop(noneChecked, isChecked), 0);
203 expect(countWithForLoop(noneChecked, (x) => !x.checked), 4); 203 expect(countWithForLoop(noneChecked, isUnchecked), 4);
204 204
205 root.remove(); 205 root.remove();
206 }); 206 });
207 test('Last', () { 207 test('Last', () {
208 Element root = insertTestDiv(); 208 Element root = insertTestDiv();
209 209
210 List<Element> someChecked = 210 List<Element> someChecked =
211 document.query('#someChecked').children; 211 document.query('#someChecked').children;
212 212
213 expect(someChecked.length, 4); 213 expect(someChecked.length, 4);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 expect(someChecked.lastIndexOf(someChecked[3], 2), -1); 268 expect(someChecked.lastIndexOf(someChecked[3], 2), -1);
269 269
270 expect(someChecked.lastIndexOf(noneChecked[0], 3), -1); 270 expect(someChecked.lastIndexOf(noneChecked[0], 3), -1);
271 expect(noneChecked.lastIndexOf(someChecked[0], 3), -1); 271 expect(noneChecked.lastIndexOf(someChecked[0], 3), -1);
272 expect(someChecked.lastIndexOf(noneChecked[1], 3), -1); 272 expect(someChecked.lastIndexOf(noneChecked[1], 3), -1);
273 expect(noneChecked.lastIndexOf(someChecked[1], 3), -1); 273 expect(noneChecked.lastIndexOf(someChecked[1], 3), -1);
274 274
275 root.remove(); 275 root.remove();
276 }); 276 });
277 } 277 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698