|
13 | 13 | <script src="/resources/testharnessreport.js"></script>
|
14 | 14 | <script src="/mathml/support/feature-detection.js"></script>
|
15 | 15 | <script src="/mathml/support/operator-dictionary.js"></script>
|
16 |
| -<style> |
17 |
| - @font-face { |
18 |
| - font-family: operators; |
19 |
| - src: url("/fonts/math/operators.woff"); |
20 |
| - } |
21 |
| - math, math * { |
22 |
| - font-family: operators; |
23 |
| - /* Use large enough font-size so that 1/18em = 2.77px > epsilon and |
24 |
| - one can really distinguish lspace/rspace values. */ |
25 |
| - font-size: 50px; |
26 |
| - } |
27 |
| -</style> |
| 16 | +<script src="./support/operator-dictionary-tests.js"></script> |
| 17 | +<link rel="stylesheet" href="./support/operator-dictionary-tests.css"/> |
28 | 18 | <script>
|
29 | 19 | setup({ explicit_done: true });
|
30 | 20 | window.addEventListener("load", () => { document.fonts.ready.then(runTests); });
|
31 |
| - |
32 | 21 | async function runTests() {
|
33 |
| - let epsilon = 1; |
34 | 22 | let json = await fetchOperatorDictionary();
|
35 |
| - |
36 |
| - // The operator dictionary has more than one thousand of entries so the |
37 |
| - // tests are grouped in chunks so that these don't get much more |
38 |
| - // importance than other MathML tests. For easy debugging, one can set the |
39 |
| - // chunk size to 1. Also, note that the test div will remain visible for |
40 |
| - // failed tests. |
41 |
| - const entryPerChunk = 50 |
42 |
| - |
43 |
| - var counter = 0; |
44 |
| - var tests = { |
45 |
| - "lspace/rspace": null, |
46 |
| - "movablelimits": null, |
47 |
| - "largeop": null, |
48 |
| - "stretchy": null, |
49 |
| - "symmetric": null, |
50 |
| - "accent": null |
51 |
| - }; |
52 |
| - |
53 |
| - for (key in json.dictionary) { |
54 |
| - |
55 |
| - if (counter % entryPerChunk === 0) { |
56 |
| - // Start of a new chunk. |
57 |
| - // Complete current async tests and create new ones for the next chunk. |
58 |
| - for (name in tests) { |
59 |
| - if (tests[name]) tests[name].done(); |
60 |
| - tests[name] = async_test(`Operator dictionary chunk ${1 + counter / entryPerChunk} - ${name}`); |
61 |
| - } |
62 |
| - } |
63 |
| - |
64 |
| - let parsedKey = splitKey(key); |
65 |
| - let entry = json.dictionary[key]; |
66 |
| - |
67 |
| - tests["lspace/rspace"].step(function() { |
68 |
| - assert_true(MathMLFeatureDetection.has_operator_spacing()); |
69 |
| - document.body.insertAdjacentHTML("beforeend", `<div>\ |
70 |
| -lspace/rspace for "${parsedKey.characters}" (${parsedKey.form}): \ |
71 |
| -<math>\ |
72 |
| - <mrow>\ |
73 |
| - <mn> </mn>\ |
74 |
| - <mo form="${parsedKey.form}">${parsedKey.characters}</mo>\ |
75 |
| - <mn> </mn>\ |
76 |
| - </mrow>\ |
77 |
| -</math>\ |
78 |
| - VS \ |
79 |
| -<math>\ |
80 |
| - <mrow>\ |
81 |
| - <mn> </mn>\ |
82 |
| - <mo form="${parsedKey.form}" lspace="${defaultPropertyValue(entry, 'lspace')}" rspace="${defaultPropertyValue(entry, 'rspace')}">${parsedKey.characters}</mo>\ |
83 |
| - <mn> </mn>\ |
84 |
| - </mrow>\ |
85 |
| -</math>\ |
86 |
| -</div>`); |
87 |
| - var div = document.body.lastElementChild; |
88 |
| - var mrows = div.getElementsByTagName("mrow"); |
89 |
| - function spaceBetween(element, i, j) { |
90 |
| - return element.children[j].getBoundingClientRect().left - |
91 |
| - element.children[i].getBoundingClientRect().right; |
92 |
| - } |
93 |
| - var lspace = spaceBetween(mrows[0], 0, 1); |
94 |
| - var rspace = spaceBetween(mrows[0], 1, 2); |
95 |
| - var lspaceRef = spaceBetween(mrows[1], 0, 1); |
96 |
| - var rspaceRef = spaceBetween(mrows[1], 1, 2); |
97 |
| - assert_approx_equals(lspace, lspaceRef, epsilon, `lspace (${key})`); |
98 |
| - assert_approx_equals(rspace, rspaceRef, epsilon, `rspace (${key})`); |
99 |
| - div.style.display = "none"; |
100 |
| - }); |
101 |
| - |
102 |
| - tests["movablelimits"].step(function() { |
103 |
| - assert_true(MathMLFeatureDetection.has_movablelimits()); |
104 |
| - var defaultValue = defaultPropertyValue(entry, "movablelimits"); |
105 |
| - document.body.insertAdjacentHTML("beforeend", `<div>\ |
106 |
| -movablelimits for "${parsedKey.characters}" (${parsedKey.form}): \ |
107 |
| -<math>\ |
108 |
| - <munder>\ |
109 |
| - <mo stretchy="false" form="${parsedKey.form}">${parsedKey.characters}</mo>\ |
110 |
| - <mn> </mn>\ |
111 |
| - </munder>\ |
112 |
| -</math>\ |
113 |
| - VS \ |
114 |
| -<math>\ |
115 |
| - <munder>\ |
116 |
| - <mo stretchy="false" form="${parsedKey.form}" movablelimits="${defaultValue}">${parsedKey.characters}</mo>\ |
117 |
| - <mn> </mn>\ |
118 |
| - </munder>\ |
119 |
| -</math>\ |
120 |
| -</div>`); |
121 |
| - var div = document.body.lastElementChild; |
122 |
| - var munders = div.getElementsByTagName("munder"); |
123 |
| - munder = munders[0].getBoundingClientRect() |
124 |
| - munderRef = munders[1].getBoundingClientRect() |
125 |
| - assert_approx_equals(munder.height, munderRef.height, epsilon, `Movablelimits property for ${key} should be '${defaultValue}'`); |
126 |
| - div.style.display = "none"; |
127 |
| - }); |
128 |
| - |
129 |
| - tests["largeop"].step(function() { |
130 |
| - // FIXME: Should really detect largeop support... |
131 |
| - assert_true(MathMLFeatureDetection.has_mspace()); |
132 |
| - var defaultValue = defaultPropertyValue(entry, "largeop"); |
133 |
| - document.body.insertAdjacentHTML("beforeend", `<div>\ |
134 |
| -largeop for "${parsedKey.characters}" (${parsedKey.form}): \ |
135 |
| -<math displaystyle="true">\ |
136 |
| - <mo form="${parsedKey.form}">${parsedKey.characters}</mo>\ |
137 |
| -</math>\ |
138 |
| - VS \ |
139 |
| -<math displaystyle="true">\ |
140 |
| - <mo form="${parsedKey.form}" largeop="${defaultValue}">${parsedKey.characters}</mo>\ |
141 |
| -</math>\ |
142 |
| -</div>`); |
143 |
| - var div = document.body.lastElementChild; |
144 |
| - var mos = div.getElementsByTagName("mo"); |
145 |
| - mo = mos[0].getBoundingClientRect() |
146 |
| - moRef = mos[1].getBoundingClientRect() |
147 |
| - assert_approx_equals(mo.height, moRef.height, epsilon, `Largeop property for ${key} should be '${defaultValue}'`); |
148 |
| - div.style.display = "none"; |
149 |
| - }); |
150 |
| - |
151 |
| - if (entry.horizontal) { |
152 |
| - tests["stretchy"].step(function() { |
153 |
| - // FIXME: Should really detect stretchy support... |
154 |
| - assert_true(MathMLFeatureDetection.has_munder()); |
155 |
| - var defaultValue = defaultPropertyValue(entry, "stretchy"); |
156 |
| - document.body.insertAdjacentHTML("beforeend", `<div>\ |
157 |
| -stretchy for "${parsedKey.characters}" (${parsedKey.form}): \ |
158 |
| -<math>\ |
159 |
| - <munder>\ |
160 |
| - <mn> </mn>\ |
161 |
| - <mo form="${parsedKey.form}">${parsedKey.characters}</mo>\ |
162 |
| - </munder>\ |
163 |
| -</math>\ |
164 |
| - VS \ |
165 |
| -<math>\ |
166 |
| - <munder>\ |
167 |
| - <mn> </mn>\ |
168 |
| - <mo form="${parsedKey.form}" stretchy="${defaultValue}">${parsedKey.characters}</mo>\ |
169 |
| - </munder>\ |
170 |
| -</math>\ |
171 |
| -</div>`); |
172 |
| - var div = document.body.lastElementChild; |
173 |
| - var mos = div.getElementsByTagName("mo"); |
174 |
| - mo = mos[0].getBoundingClientRect() |
175 |
| - moRef = mos[1].getBoundingClientRect() |
176 |
| - assert_approx_equals(mo.width, moRef.width, epsilon, `Stretchy property for ${key} should be '${defaultValue}'`); |
177 |
| - div.style.display = "none"; |
178 |
| - }); |
179 |
| - } else { |
180 |
| - tests["stretchy"].step(function() { |
181 |
| - // FIXME: Should really detect stretchy support... |
182 |
| - assert_true(MathMLFeatureDetection.has_mspace()); |
183 |
| - var defaultValue = defaultPropertyValue(entry, "stretchy"); |
184 |
| - document.body.insertAdjacentHTML("beforeend", `<div>\ |
185 |
| -stretchy for "${parsedKey.characters}" (${parsedKey.form}): \ |
186 |
| -<math>\ |
187 |
| - <mrow>\ |
188 |
| - <mo form="${parsedKey.form}" symmetric="false">${parsedKey.characters}</mo>\ |
189 |
| - <mspace height="2em"></mspace>\ |
190 |
| - </mrow>\ |
191 |
| -</math>\ |
192 |
| - VS \ |
193 |
| -<math>\ |
194 |
| - <mrow>\ |
195 |
| - <mo form="${parsedKey.form}" symmetric="false" stretchy="${defaultValue}">${parsedKey.characters}</mo>\ |
196 |
| - <mspace height="2em"></mspace>\ |
197 |
| - </mrow>\ |
198 |
| -</math>\ |
199 |
| -</div>`); |
200 |
| - var div = document.body.lastElementChild; |
201 |
| - var mos = div.getElementsByTagName("mo"); |
202 |
| - mo = mos[0].getBoundingClientRect() |
203 |
| - moRef = mos[1].getBoundingClientRect() |
204 |
| - assert_approx_equals(mo.height, moRef.height, epsilon, `Stretchy property for ${key} should be '${defaultValue}'`); |
205 |
| - div.style.display = "none"; |
206 |
| - }); |
207 |
| - tests["symmetric"].step(function() { |
208 |
| - // FIXME: Should really detect symmetric support... |
209 |
| - assert_true(MathMLFeatureDetection.has_mspace()); |
210 |
| - var defaultValue = defaultPropertyValue(entry, "symmetric"); |
211 |
| - document.body.insertAdjacentHTML("beforeend", `<div>\ |
212 |
| -symmetric for "${parsedKey.characters}" (${parsedKey.form}): \ |
213 |
| -<math>\ |
214 |
| - <mrow>\ |
215 |
| - <mo form="${parsedKey.form}" stretchy="true">${parsedKey.characters}</mo>\ |
216 |
| - <mspace height="1.5em"></mspace>\ |
217 |
| - </mrow>\ |
218 |
| -</math>\ |
219 |
| - VS \ |
220 |
| -<math>\ |
221 |
| - <mrow>\ |
222 |
| - <mo form="${parsedKey.form}" stretchy="true" symmetric="${defaultValue}">${parsedKey.characters}</mo>\ |
223 |
| - <mspace height="1.5em"></mspace>\ |
224 |
| - </mrow>\ |
225 |
| -</math>\ |
226 |
| -</div>`); |
227 |
| - var div = document.body.lastElementChild; |
228 |
| - var mos = div.getElementsByTagName("mo"); |
229 |
| - mo = mos[0].getBoundingClientRect() |
230 |
| - moRef = mos[1].getBoundingClientRect() |
231 |
| - assert_approx_equals(mo.height, moRef.height, epsilon, `Symmetric property for ${key} should be '${defaultValue}'`); |
232 |
| - div.style.display = "none"; |
233 |
| - }); |
234 |
| - } |
235 |
| - |
236 |
| - tests["accent"].step(function() { |
237 |
| - // FIXME: Should really detect accent support... |
238 |
| - assert_true(MathMLFeatureDetection.has_mover()); |
239 |
| - var defaultValue = defaultPropertyValue(entry, "accent"); |
240 |
| - document.body.insertAdjacentHTML("beforeend", `<div>\ |
241 |
| -accent for "${parsedKey.characters}" (${parsedKey.form}): \ |
242 |
| -<math>\ |
243 |
| - <mover>\ |
244 |
| - <mn> </mn>\ |
245 |
| - <mo form="${parsedKey.form}">${parsedKey.characters}</mo>\ |
246 |
| - </mover>\ |
247 |
| -</math>\ |
248 |
| - VS \ |
249 |
| -<math>\ |
250 |
| - <mover>\ |
251 |
| - <mn> </mn>\ |
252 |
| - <mo form="${parsedKey.form}" accent="${defaultValue}">${parsedKey.characters}</mo>\ |
253 |
| - </mover>\ |
254 |
| -</math>\ |
255 |
| -</div>`); |
256 |
| - var div = document.body.lastElementChild; |
257 |
| - var movers = div.getElementsByTagName("mover"); |
258 |
| - function gapBetweenBaseAndScript(mover) { |
259 |
| - return mover.children[0].getBoundingClientRect().top - |
260 |
| - mover.children[1].getBoundingClientRect().bottom; |
261 |
| - } |
262 |
| - var gap = gapBetweenBaseAndScript(movers[0]) |
263 |
| - var gapRef = gapBetweenBaseAndScript(movers[1]) |
264 |
| - assert_approx_equals(gap, gapRef, epsilon, `Accent property for ${key} should be '${defaultValue}'`); |
265 |
| - div.style.display = "none"; |
266 |
| - }); |
267 |
| - |
268 |
| - counter++; |
269 |
| - } |
270 |
| - |
271 |
| - // Complete current async tests. |
272 |
| - for (name in tests) { |
273 |
| - if (tests[name]) tests[name].done(); |
274 |
| - } |
275 |
| - |
| 23 | + OperatorDictionaryTests.run(json, "lspace/rspace"); |
276 | 24 | done();
|
277 | 25 | }
|
278 | 26 | </script>
|
|
0 commit comments