-
Notifications
You must be signed in to change notification settings - Fork 84
/
Copy pathunit-test-testharness.html
248 lines (213 loc) · 7.43 KB
/
unit-test-testharness.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
<!--
Copyright 2013 Google Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!DOCTYPE html><meta charset="UTF-8">
<script src="../bootstrap.js"></script>
<script>
"use strict";
test(function() {
var element = document.createElement('span');
assert_styles(element, {},
'assert_styles should support an element with no parent');
document.body.appendChild(element);
var childCount = document.body.children.length;
assert_styles(element, {});
assert_equals(childCount, document.body.children.length,
'assert_styles should not leave additional elements in the dom');
}, 'assert_styles reference_element');
test(function() {
try {
assert_styles(null, {});
assert_unreached();
} catch (e) {
assert_equals(e.message, 'Expected Array, NodeList or Element but got null');
}
}, 'assert_styles invalid arguments');
test(function() {
var element = document.createElement('span');
document.body.appendChild(element);
try {
assert_styles(element, {'left': 'abc123'}, "Description 1");
assert_unreached();
} catch (e) {
assert_regexp_match(e.message, /^Tried to set the reference element\'s "left"/);
}
try {
assert_styles(element, {'clip': 'rect(1px 2px 3px 4px)'});
assert_unreached();
} catch (e) {
assert_regexp_match(e.message, /Actual - /);
}
}, 'assert_styles given invalid style');
test(function() {
var element = document.createElement('span');
document.body.appendChild(element);
element.style.left = '-100px';
try {
assert_styles(element, {left: '100px'});
assert_unreached();
} catch(e) {
}
}, 'assert_styles should handle negative specified values');
test(function() {
var element = document.createElement('span');
document.body.appendChild(element);
element.style.left = '100px';
try {
assert_styles(element, {left: '-100px'});
assert_unreached();
} catch(e) {
}
}, 'assert_styles should handle negative expected values');
test(function() {
var element = document.createElement('span');
document.body.appendChild(element);
element.style.left = '-100px';
assert_styles(element, {left: '-100px'});
}, 'assert_styles should handle negative values');
test(function() {
var AssertionError = window.assert_styles_assertion_error;
var assert = window.assert_styles_assert_important_in_array;
assert('matrix(1%)', ['matrix(1%)']);
assert('matrix(1%)', ['', 'matrix(1%)']);
assert('matrix(1% 1px)', ['matrix(1%, 1px)']);
assert('rect(1px 2px 3px 4px)', ['rect(1px 2px 3px 4px)']);
assert('rect(1px 2px 3px 4px)', ['rect(1px, 2px, 3px, 4px)']);
try {
assert('', [], 'empty');
assert_unreached();
} catch(e) {
assert_regexp_match(e.message, /^empty/);
}
try {
assert('matrix(1%)', [], 'matrix 1% to empty');
assert_unreached();
} catch(e) {
assert_regexp_match(e.message, /^matrix 1% to empty/);
}
try {
assert('matrix(1%)', [''], 'matrix 1% to empty string');
assert_unreached();
} catch(e) {
assert_regexp_match(e.message, /^matrix 1% to empty string\n/);
}
try {
assert('matrix(1%)', ['matrix(1px)'], 'matrix 1% to matrix 1px');
assert_unreached();
} catch(e) {
assert_regexp_match(e.message, /^matrix 1% to matrix 1px/);
}
/* Check that it only needs to match to 4 significant figures */
assert('1', [1.0001]);
assert('1.0001', [1]);
try {
assert('1', [1.001]);
assert_unreached();
} catch(e) {
assert_not_equals(e.message, "assert_unreached: Reached unreachable code");
}
assert('10', [10.001]);
assert('10.001', [10]);
try {
assert('10', [10.01]);
assert_unreached();
} catch(e) {
assert_not_equals(e.message, "assert_unreached: Reached unreachable code");
}
assert('2.0', [2.0001]);
assert('2.0001', [2]);
try {
assert('2', [2.001]);
assert_unreached();
} catch(e) {
assert_not_equals(e.message, "assert_unreached: Reached unreachable code");
}
assert('20.0', [20.001]);
assert('20.001', [20]);
try {
assert('20.0', [20.01]);
assert_unreached();
} catch(e) {
assert_not_equals(e.message, "assert_unreached: Reached unreachable code");
}
assert('40e2', [4000.1]);
assert('40.001e2', [4000]);
try {
assert('40e2', [4001]);
assert_unreached();
} catch(e) {
assert_not_equals(e.message, "assert_unreached: Reached unreachable code");
}
assert('40e+3', [40001]);
assert('40.001e+3', [40000]);
try {
assert('40e+3', [40010]);
assert_unreached();
} catch(e) {
assert_not_equals(e.message, "assert_unreached: Reached unreachable code");
}
assert('50e-4', [0.0050001]);
assert('50.001e-4', [0.005]);
try {
assert('50e-4', [0.005001]);
assert_unreached();
} catch(e) {
assert_not_equals(e.message, "assert_unreached: Reached unreachable code");
}
}, 'Checking assert_important_in_array works');
test(function() {
var ei = window.assert_styles_extract_important;
assert_array_equals(ei('1'), [1]);
assert_array_equals(ei('10'), [10]);
assert_array_equals(ei('2.0'), [2.0]);
assert_array_equals(ei('20.0'), [20.0]);
assert_array_equals(ei('40e2'), [4000.0]);
assert_array_equals(ei('40e+3'), [40000.0]);
assert_array_equals(ei('50e-4'), [0.005]);
assert_array_equals(ei('60.6e-4'), [0.00606]);
assert_array_equals(ei('+1'), [1]);
assert_array_equals(ei('+10'), [10]);
assert_array_equals(ei('+2.0'), [2.0]);
assert_array_equals(ei('+20.0'), [20.0]);
assert_array_equals(ei('+40e2'), [4000.0]);
assert_array_equals(ei('+40e+3'), [40000.0]);
assert_array_equals(ei('+50e-4'), [0.005]);
assert_array_equals(ei('+60.6e-4'), [0.00606]);
assert_array_equals(ei('-1'), [-1]);
assert_array_equals(ei('-10'), [-10]);
assert_array_equals(ei('-2.0'), [-2.0]);
assert_array_equals(ei('-20.0'), [-20.0]);
assert_array_equals(ei('-40e2'), [-4000]);
assert_array_equals(ei('-50e-3'), [-0.05]);
assert_array_equals(ei('-60.6e-4'), [-0.00606]);
assert_array_equals(ei('matrix(1%'), ['matrix', 1, '%']);
assert_array_equals(ei('matrix(10px'), ['matrix', 10, 'px']);
assert_array_equals(ei('matrix(2.0em'), ['matrix', 2.0, 'em']);
assert_array_equals(ei('matrix(20.0en'), ['matrix', 20.0, 'en']);
assert_array_equals(ei('matrix(40e2ve'), ['matrix', 4000.0, 've']);
assert_array_equals(ei('matrix(40e+3vw'), ['matrix', 40000.0, 'vw']);
assert_array_equals(ei('matrix(50e-4%'), ['matrix', 0.005, '%']);
assert_array_equals(ei('matrix('), ['matrix']);
assert_array_equals(ei('blah'), ['blah']);
assert_array_equals(ei('+'), []);
assert_array_equals(ei('none'), ['none']);
assert_array_equals(ei('----'), []);
assert_array_equals(ei('-a'), ['a']);
assert_array_equals(ei('b.j'), ['b', 'j']);
assert_array_equals(ei('matrix(1, 0, 0, 1, 0, 0)'),
['matrix', 1, 0, 0, 1, 0, 0]);
assert_array_equals(ei('matrix(1 0 0 1 0 0)'),
['matrix', 1, 0, 0, 1, 0, 0]);
assert_array_equals(ei('matrix(0.9511, 0.309, -0.309, 0.9511, 0, 0)'),
['matrix', 0.9511, 0.309, -0.309, 0.9511, 0, 0]);
}, 'Checking important parts are extracted successfully');
</script>