1use super::*;
4
5pub fn selftest() -> (usize, usize) {
8 fn box_id<'a>(b: &LayoutBox<'a>) -> Option<&'a str> {
9 let styled = match &b.box_type {
10 BoxType::BlockNode(s)
11 | BoxType::InlineNode(s)
12 | BoxType::InlineBlockNode(s)
13 | BoxType::FlexNode(s)
14 | BoxType::GridNode(s)
15 | BoxType::TableNode(s)
16 | BoxType::TableRowGroupNode(s)
17 | BoxType::TableRowNode(s)
18 | BoxType::TableCellNode(s) => *s,
19 BoxType::AnonymousBlock => return None,
20 };
21 match &styled.node.node_type {
22 NodeType::Element { id, .. } => id.as_deref(),
23 NodeType::Text(_) => None,
24 }
25 }
26 fn find<'a, 'b>(b: &'b LayoutBox<'a>, id: &str) -> Option<&'b LayoutBox<'a>> {
27 if box_id(b) == Some(id) {
28 return Some(b);
29 }
30 for c in &b.children {
31 if let Some(r) = find(c, id) {
32 return Some(r);
33 }
34 }
35 None
36 }
37 fn measure(html: &str, css: &str, vw: i32, id: &str) -> Option<(i32, i32, i32, i32)> {
38 set_viewport_hint(vw, 600);
42 let dom = super::super::dom::parse_html(html);
43 let css_owned;
46 let css = if html.contains("<body") {
47 css
48 } else {
49 css_owned = alloc::format!("body{{margin:0}} {}", css);
50 css_owned.as_str()
51 };
52 let sheet = super::super::css::parse_css(css);
53 let styled = super::super::css::style_tree(&dom, &sheet);
54 let icb = Dimensions {
55 content: Rect {
56 x: 0,
57 y: 0,
58 width: vw,
59 height: 0,
60 },
61 ..Default::default()
62 };
63 let tree = layout_tree(&styled, icb);
64 let b = find(&tree, id)?;
65 let c = &b.dimensions.content;
66 Some((c.x, c.y, c.width, c.height))
67 }
68
69 let cases: &[(&str, &str, i32, &str, (i32, i32, i32, i32))] = &[
71 ("<div id='f'><div id='a'></div><div id='b'></div></div>",
73 "#f{display:flex} #a{width:30px;height:10px} #b{width:40px;height:10px}", 200, "a", (0, 0, 30, 10)),
74 ("<div id='f'><div id='a'></div><div id='b'></div></div>",
75 "#f{display:flex} #a{width:30px;height:10px} #b{width:40px;height:10px}", 200, "b", (30, 0, 40, 10)),
76 ("<div id='f'><div id='a'></div></div>",
78 "#f{display:flex;justify-content:center} #a{width:50px;height:10px}", 200, "a", (75, 0, 50, 10)),
79 ("<div id='f'><div id='a'></div></div>",
81 "#f{display:flex;justify-content:flex-end} #a{width:50px;height:10px}", 200, "a", (150, 0, 50, 10)),
82 ("<div id='f'><div id='a'></div><div id='b'></div></div>",
84 "#f{display:flex;justify-content:space-between} #a{width:20px;height:10px} #b{width:20px;height:10px}", 200, "b", (180, 0, 20, 10)),
85 ("<div id='f'><div id='a'></div><div id='b'></div></div>",
89 "#f{display:flex;justify-content:space-evenly} #a{width:20px;height:10px} #b{width:20px;height:10px}", 200, "a", (53, 0, 20, 10)),
90 ("<div id='f'><div id='a'></div><div id='b'></div></div>",
91 "#f{display:flex;justify-content:space-evenly} #a{width:20px;height:10px} #b{width:20px;height:10px}", 200, "b", (126, 0, 20, 10)),
92 ("<div id='f'><div id='a'></div></div>",
95 "#f{display:flex;justify-content:end} #a{width:50px;height:10px}", 200, "a", (150, 0, 50, 10)),
96 ("<div id='f'><div id='a'></div></div>",
99 "#f{display:flex;height:100px;align-items:end} #a{width:30px;height:20px}", 200, "a", (0, 80, 30, 20)),
100 ("<div id='f'><div id='a'></div></div>",
102 "#f{display:flex;height:100px} #a{width:30px;height:20px;align-self:self-end}", 200, "a", (0, 80, 30, 20)),
103 ("<div id='f'><div id='a'></div></div>",
106 "#f{display:flex;flex-wrap:wrap;justify-content:end} #a{width:50px;height:10px}", 200, "a", (150, 0, 50, 10)),
107 ("<div id='f'><div id='a'></div><div id='b'></div></div>",
110 "#f{display:flex;flex-wrap:wrap;justify-content:space-evenly} #a{width:20px;height:10px} #b{width:20px;height:10px}", 200, "b", (126, 0, 20, 10)),
111 ("<div id='f'><div id='a'></div><div id='b'></div></div>",
113 "#f{display:flex;flex-direction:column} #a{width:30px;height:10px} #b{width:30px;height:15px}", 200, "b", (0, 10, 30, 15)),
114 ("<div id='f'><div id='a'></div></div>",
116 "#f{display:flex;align-items:center;height:100px} #a{width:30px;height:20px}", 200, "a", (0, 40, 30, 20)),
117 ("<div id='f'><div id='a'></div><div id='b'></div></div>",
119 "#f{display:flex;gap:10px} #a{width:20px;height:10px} #b{width:20px;height:10px}", 200, "b", (30, 0, 20, 10)),
120 ("<div id='t'></div>", "#t{height:10px}", 200, "t", (0, 0, 200, 10)),
122 ("<div id='f'><div id='a'></div></div>",
124 "#f{display:flex;height:100px} #a{width:30px}", 200, "a", (0, 0, 30, 100)),
125 ("<div id='f'><div id='a'></div></div>",
127 "#f{display:flex;height:100px} #a{width:30px;height:20px}", 200, "a", (0, 0, 30, 20)),
128 ("<div id='f'><div id='a'></div></div>",
130 "#f{display:flex;flex-direction:column} #a{height:10px}", 200, "a", (0, 0, 200, 10)),
131 ("<div id='f'><div id='a'></div><div id='b'></div></div>",
133 "#f{display:flex} #a{flex:1;height:10px} #b{flex:1;height:10px}", 200, "a", (0, 0, 100, 10)),
134 ("<div id='f'><div id='a'></div><div id='b'></div></div>",
135 "#f{display:flex} #a{flex:1;height:10px} #b{flex:1;height:10px}", 200, "b", (100, 0, 100, 10)),
136 ("<div id='f'><div id='a'></div><div id='b'></div></div>",
138 "#f{display:flex} #a{width:50px;height:10px} #b{flex:1;height:10px}", 200, "b", (50, 0, 150, 10)),
139 ("<div id='f'><div id='a'></div><div id='b'></div></div>",
141 "#f{display:flex} #a{flex-grow:1;height:10px} #b{flex-grow:2;height:10px}", 200, "b", (66, 0, 134, 10)),
142 ("<div id='f'><div id='a'></div><div id='b'></div></div>",
144 "#f{display:flex;flex-direction:column;height:100px} #a{flex:1;width:30px} #b{height:20px;width:30px}", 200, "b", (0, 80, 30, 20)),
145 ("<div id='p'><div id='a'></div><div id='b'></div></div>",
147 "#a{height:10px} #b{height:10px;position:relative;left:20px;top:5px}", 200, "b", (20, 15, 200, 10)),
148 ("<div id='p'><div id='a'></div><div id='b'></div></div>",
150 "#a{height:10px} #b{height:10px;position:relative;left:20px;top:5px}", 200, "a", (0, 0, 200, 10)),
151 ("<div id='p'><div id='a'></div></div>",
153 "#p{position:relative;height:100px} #a{position:absolute;top:10px;left:30px;width:40px;height:20px}", 200, "a", (30, 10, 40, 20)),
154 ("<div id='p'><div id='a'></div></div>",
157 "#p{position:relative;height:100px} #a{position:absolute;inset:10px 0 0 30px;width:40px;height:20px}", 200, "a", (30, 10, 40, 20)),
158 ("<div id='p'><div id='a'></div></div>",
160 "#p{position:relative;height:100px} #a{position:absolute;inset:0;width:40px;height:20px}", 200, "a", (0, 0, 40, 20)),
161 ("<div id='p'><div id='a'></div></div>",
163 "#p{position:relative;height:100px} #a{position:absolute;inset:0;left:15px;width:40px;height:20px}", 200, "a", (15, 0, 40, 20)),
164 ("<div id='p'><div id='a'></div></div>",
166 "#p{position:relative;width:200px;height:100px} #a{position:absolute;right:10px;bottom:5px;width:40px;height:20px}", 200, "a", (150, 75, 40, 20)),
167 ("<div id='p'><div id='a'></div><div id='b'></div></div>",
169 "#p{position:relative} #a{position:absolute;top:0;left:0;width:50px;height:50px} #b{height:10px}", 200, "b", (0, 0, 200, 10)),
170 ("<div id='gp'><div id='sp'></div><div id='wrap'><div id='a'></div></div></div>",
173 "#gp{position:relative;height:100px} #sp{height:30px} #a{position:absolute;top:10px;left:20px;width:30px;height:15px}", 200, "a", (20, 10, 30, 15)),
174 ("<div id='h'></div>",
176 "#h{position:fixed;top:5px;left:8px;width:100px;height:20px}", 200, "h", (8, 5, 100, 20)),
177 ("<div id='p'><div id='a'></div><div id='b'></div></div>",
179 "#a{height:10px} #b{height:10px;transform:translate(10px,5px)}", 200, "b", (10, 15, 200, 10)),
180 ("<div id='p'><div id='a'></div><div id='b'></div></div>",
182 "#a{height:10px} #b{height:10px;transform:translate(10px,5px)}", 200, "a", (0, 0, 200, 10)),
183 ("<div id='p'><div id='a'></div><div id='b'></div></div>",
185 "#a{height:10px} #b{height:10px;transform:translateX(20px)}", 200, "b", (20, 10, 200, 10)),
186 ("<div id='p'><div id='a'></div><div id='b'></div></div>",
188 "#a{height:10px} #b{width:40px;height:10px;transform:translate(50%,100%)}", 200, "b", (20, 20, 40, 10)),
189 ("<div id='p'><div id='a'></div><div id='b'></div></div>",
191 "#a{display:none;height:10px} #b{height:10px}", 200, "b", (0, 0, 200, 10)),
192 ("<div id='t'></div>",
194 "#t{width:100px;padding:0 10px;box-sizing:border-box;height:30px}", 200, "t", (10, 0, 80, 30)),
195 ("<div id='p'><div id='a'></div></div>",
197 "#a{width:100px;margin:0 auto;height:10px}", 200, "a", (50, 0, 100, 10)),
198 ("<div id='t'></div>",
200 "#t{width:50px;height:50px;padding:10px 0;box-sizing:border-box}", 200, "t", (0, 10, 50, 30)),
201 ("<div id='t'></div>", "#t{height:100vh}", 200, "t", (0, 0, 200, 600)),
203 ("<div id='t'></div>", "#t{height:2rem}", 200, "t", (0, 0, 200, 32)),
205 ("<div id='g'><div id='a'></div><div id='b'></div><div id='c'></div></div>",
207 "#g{display:grid;grid-template-columns:repeat(3,1fr)} #a,#b,#c{height:10px}", 198, "b", (66, 0, 66, 10)),
208 ("<div id='m'><div id='a'></div><div id='b'></div></div>",
212 "#m{column-count:2} #a,#b{height:10px}", 216, "b", (116, 0, 100, 10)),
213 ("<div id='m'><div id='a'></div><div id='b'></div><div id='c'></div></div>",
215 "#m{column-count:2} #a,#b,#c{height:10px}", 216, "c", (0, 10, 100, 10)),
216 ("<div id='m'><div id='a'></div><div id='b'></div></div>",
218 "#m{columns:100px 2;column-gap:0px} #a,#b{height:10px}", 200, "b", (100, 0, 100, 10)),
219 ("<div id='m'><div id='a'></div><div id='b'></div><div id='s'></div><div id='c'></div></div>",
221 "#m{column-count:2} #a,#b,#c{height:10px} #s{column-span:all;height:20px}", 216, "s", (0, 10, 216, 20)),
222 ("<div id='m'><div id='a'></div><div id='b'></div><div id='s'></div><div id='c'></div></div>",
224 "#m{column-count:2} #a,#b,#c{height:10px} #s{column-span:all;height:20px}", 216, "c", (0, 30, 100, 10)),
225 ("<div id='m'><div id='a'></div><div id='b'></div></div>",
227 "#m{column-count:2;column-gap:2rem} #a,#b{height:10px}", 232, "b", (132, 0, 100, 10)),
228
229 ("<div id='g'><div id='a'></div><div id='b'></div></div>",
231 "#g{display:grid;grid-template-columns:1fr 2fr} #a,#b{height:10px}", 210, "b", (70, 0, 140, 10)),
232 ("<div id='g'><div id='a'></div><div id='b'></div></div>",
234 "#g{display:grid;grid-template-columns:repeat(auto-fit,minmax(80px,1fr))} #a,#b{height:10px}", 200, "b", (100, 0, 100, 10)),
235 ("<div id='g'><div id='a'></div><div id='b'></div></div>",
239 "#g{display:grid;grid-template-columns:50% 1fr} #a,#b{height:10px}", 200, "a", (0, 0, 100, 10)),
240 ("<div id='g'><div id='a'></div><div id='b'></div></div>",
241 "#g{display:grid;grid-template-columns:50% 1fr} #a,#b{height:10px}", 200, "b", (100, 0, 100, 10)),
242 ("<div id='g'><div id='a'></div><div id='b'></div></div>",
247 "#g{display:grid;grid-template-columns:repeat(auto-fit,minmax(50%,1fr))} #a,#b{height:10px}", 200, "b", (100, 0, 100, 10)),
248 ("<div id='t'></div>", "#t{width:160px;aspect-ratio:16/9}", 200, "t", (0, 0, 160, 90)),
250 ("<div id='t'></div>", "#t{width:80px;aspect-ratio:1/1}", 200, "t", (0, 0, 80, 80)),
252 ("<div id='t'></div>", "@media (max-width:300px){#t{height:42px}}", 200, "t", (0, 0, 200, 42)),
254 ("<div id='f'><div id='a'></div><div id='b'></div></div>",
256 "#f{display:flex;flex-direction:row-reverse} #a{width:30px;height:10px} #b{width:40px;height:10px}", 200, "a", (170, 0, 30, 10)),
257 ("<div id='f'><div id='a'></div><div id='b'></div></div>",
258 "#f{display:flex;flex-direction:row-reverse} #a{width:30px;height:10px} #b{width:40px;height:10px}", 200, "b", (130, 0, 40, 10)),
259 ("<div id='f'><div id='a'></div></div>",
261 "#f{display:flex;height:100px} #a{width:30px;height:20px;align-self:flex-end}", 200, "a", (0, 80, 30, 20)),
262 ("<div id='f'><div id='a'></div></div>",
264 "#f{display:flex;height:100px;align-items:flex-start} #a{width:30px;height:20px;align-self:center}", 200, "a", (0, 40, 30, 20)),
265 ("<div id='f'><div id='a'></div><div id='b'></div><div id='c'></div></div>",
267 "#f{display:flex;flex-wrap:wrap} #a{width:100px;height:10px} #b{width:100px;height:10px} #c{width:100px;height:10px}", 200, "c", (0, 10, 100, 10)),
268 ("<div id='f'><div id='a'></div><div id='b'></div><div id='c'></div></div>",
270 "#f{display:flex;flex-wrap:wrap} #a{width:100px;height:10px} #b{width:100px;height:10px} #c{width:100px;height:10px}", 200, "b", (100, 0, 100, 10)),
271 ("<div id='f'><div id='x'></div><div id='a'></div></div>",
274 "#f{display:flex;position:relative;height:100px} #x{position:absolute;top:10px;left:20px;width:30px;height:15px} #a{width:40px;height:10px}", 200, "x", (20, 10, 30, 15)),
275 ("<div id='f'><div id='x'></div><div id='a'></div></div>",
277 "#f{display:flex;position:relative;height:100px} #x{position:absolute;top:10px;left:20px;width:30px;height:15px} #a{width:40px;height:10px}", 200, "a", (0, 0, 40, 10)),
278 ("<div id='f'><div id='a'></div><div id='b'></div></div>",
280 "#f{display:flex} #a{width:40px;height:10px} #b{width:30px;height:10px;position:relative;left:5px;top:3px}", 200, "b", (45, 3, 30, 10)),
281 ("<div id='g'><div id='x'></div><div id='a'></div><div id='b'></div></div>",
283 "#g{display:grid;position:relative;grid-template-columns:repeat(2,1fr)} #x{position:absolute;top:8px;left:12px;width:20px;height:10px} #a,#b{height:10px}", 200, "x", (12, 8, 20, 10)),
284 ("<div id='g'><div id='x'></div><div id='a'></div><div id='b'></div></div>",
286 "#g{display:grid;position:relative;grid-template-columns:repeat(2,1fr)} #x{position:absolute;top:8px;left:12px;width:20px;height:10px} #a,#b{height:10px}", 200, "b", (100, 0, 100, 10)),
287 ("<table id='t'><tr><td id='c1'></td><td id='c2'></td></tr></table>",
290 "table{border-spacing:0} td{padding:0} #t{position:relative} #c1{width:50px;height:10px} #c2{width:50px;height:10px;position:relative;left:7px;top:4px}", 200, "c2", (107, 4, 100, 10)),
291 ("<div id='g'><div id='a'></div><div id='b'></div><div id='c'></div></div>",
293 "#g{display:grid;grid-template-columns:repeat(2,1fr);grid-template-rows:20px 30px} #a,#b,#c{height:10px}", 200, "c", (0, 20, 100, 10)),
294 ("<div id='g'><div id='a'></div><div id='b'></div></div>",
296 "#g{display:grid;grid-template-columns:repeat(2,1fr)} #a{height:10px} #b{height:10px;grid-column:2}", 200, "b", (100, 0, 100, 10)),
297 ("<div id='g'><div id='a'></div><div id='b'></div></div>",
299 "#g{display:grid;grid-template-columns:1fr} #a{height:10px} #b{height:10px;grid-row:2}", 200, "b", (0, 10, 200, 10)),
300 ("<div id='g'><div id='a'></div><div id='b'></div></div>",
302 "#g{display:grid;grid-template-columns:repeat(3,100px)} #a{height:10px;grid-column:span 2} #b{height:10px}", 400, "a", (0, 0, 200, 10)),
303 ("<div id='g'><div id='a'></div><div id='b'></div></div>",
305 "#g{display:grid;grid-template-columns:repeat(3,100px)} #a{height:10px;grid-column:span 2} #b{height:10px}", 400, "b", (200, 0, 100, 10)),
306 ("<div id='g'><div id='a'></div><div id='b'></div><div id='c'></div><div id='d'></div></div>",
308 "#g{display:grid;grid-template-columns:repeat(2,1fr);grid-template-rows:1fr 1fr;height:100px} #a,#b,#c,#d{height:10px}", 200, "c", (0, 50, 100, 10)),
309 ("<div id='f'><div id='a'></div><div id='b'></div></div>",
312 "#f{display:flex;flex-wrap:wrap;width:100px;height:100px;align-content:flex-start} #a{width:60px;height:10px} #b{width:60px;height:10px}", 200, "b", (0, 10, 60, 10)),
313 ("<div id='f'><div id='a'></div><div id='b'></div></div>",
315 "#f{display:flex;flex-wrap:wrap;width:100px;height:100px;align-content:flex-end} #a{width:60px;height:10px} #b{width:60px;height:10px}", 200, "b", (0, 90, 60, 10)),
316 ("<div id='f'><div id='a'></div><div id='b'></div></div>",
318 "#f{display:flex;flex-wrap:wrap;width:100px;height:100px;align-content:center} #a{width:60px;height:10px} #b{width:60px;height:10px}", 200, "a", (0, 40, 60, 10)),
319 ("<div id='f'><div id='a'></div><div id='b'></div></div>",
321 "#f{display:flex;flex-wrap:wrap;width:100px;height:100px;align-content:space-between} #a{width:60px;height:10px} #b{width:60px;height:10px}", 200, "b", (0, 90, 60, 10)),
322 ("<div id='f'><div id='a'></div><div id='b'></div></div>",
324 "#f{display:flex;flex-wrap:wrap;width:100px;height:100px;align-content:stretch} #a{width:60px;height:10px} #b{width:60px;height:10px}", 200, "b", (0, 50, 60, 10)),
325 ("<div id='f'><div id='a'></div><div id='b'></div></div>",
327 "#f{display:flex;flex-wrap:wrap;width:100px;height:100px;align-content:space-around} #a{width:60px;height:10px} #b{width:60px;height:10px}", 200, "b", (0, 70, 60, 10)),
328 ("<div id='g'><div id='a'></div></div>",
331 "#g{display:grid;grid-template-columns:100px;width:200px} #a{width:40px;height:20px;justify-self:center}", 200, "a", (30, 0, 40, 20)),
332 ("<div id='g'><div id='a'></div></div>",
334 "#g{display:grid;grid-template-columns:100px;width:200px} #a{width:40px;height:20px;justify-self:end}", 200, "a", (60, 0, 40, 20)),
335 ("<div id='g'><div id='a'></div></div>",
337 "#g{display:grid;grid-template-columns:100px;grid-template-rows:60px;width:200px} #a{width:40px;height:20px;align-self:center}", 200, "a", (0, 20, 40, 20)),
338 ("<div id='g'><div id='a'></div></div>",
340 "#g{display:grid;grid-template-columns:100px;grid-template-rows:60px;width:200px} #a{width:40px;height:20px;align-self:end}", 200, "a", (0, 40, 40, 20)),
341 ("<div id='g'><div id='a'></div></div>",
343 "#g{display:grid;grid-template-columns:100px;width:200px;justify-items:center} #a{width:40px;height:20px}", 200, "a", (30, 0, 40, 20)),
344 ("<div id='g'><div id='a'></div></div>",
346 "#g{display:grid;grid-template-columns:100px;grid-template-rows:60px;width:200px;align-items:end} #a{width:40px;height:20px}", 200, "a", (0, 40, 40, 20)),
347 ("<div id='g'><div id='a'></div></div>",
351 "#g{display:grid;grid-template-columns:100px;width:200px;justify-content:center} #a{width:100px;height:20px}", 200, "a", (50, 0, 100, 20)),
352 ("<div id='g'><div id='a'></div></div>",
354 "#g{display:grid;grid-template-columns:100px;width:200px;justify-content:end} #a{width:100px;height:20px}", 200, "a", (100, 0, 100, 20)),
355 ("<div id='g'><div id='a'></div><div id='b'></div></div>",
358 "#g{display:grid;grid-template-columns:50px 50px;width:200px;justify-content:space-between} #a{width:50px;height:20px} #b{width:50px;height:20px}", 200, "b", (150, 0, 50, 20)),
359 ("<div id='g'><div id='a'></div></div>",
363 "#g{display:grid;grid-template-rows:50px;height:150px;width:200px;align-content:center} #a{width:40px;height:50px}", 200, "a", (0, 50, 40, 50)),
364 ("<div id='g'><div id='a'></div><div id='b'></div></div>",
367 "#g{display:grid;grid-template-rows:20px 20px;height:150px;width:200px;align-content:space-between} #a{width:40px;height:20px} #b{width:40px;height:20px}", 200, "b", (0, 130, 40, 20)),
368 ("<div id='f'><div id='a'></div><div id='b'></div></div>",
371 "#f{display:flex;width:100px} #a{width:80px;height:10px} #b{width:80px;height:10px}", 200, "a", (0, 0, 50, 10)),
372 ("<div id='f'><div id='a'></div><div id='b'></div></div>",
374 "#f{display:flex;width:100px} #a{width:80px;height:10px} #b{width:80px;height:10px}", 200, "b", (50, 0, 50, 10)),
375 ("<div id='f'><div id='a'></div><div id='b'></div></div>",
377 "#f{display:flex;width:100px} #a{width:80px;height:10px;flex-shrink:0} #b{width:80px;height:10px}", 200, "b", (80, 0, 20, 10)),
378 ("<div id='f'><div id='a'></div><div id='b'></div><div id='c'></div></div>",
380 "#f{display:flex} #a{width:30px;height:10px} #b{width:30px;height:10px} #c{width:30px;height:10px;order:-1}", 200, "b", (60, 0, 30, 10)),
381 ("<div id='f'><div id='a'></div><div id='b'></div><div id='c'></div></div>",
383 "#f{display:flex} #a{width:30px;height:10px} #b{width:30px;height:10px} #c{width:30px;height:10px;order:-1}", 200, "c", (0, 0, 30, 10)),
384 ("<div id='f'><div id='a'></div><div id='b'></div></div>",
387 "#f{display:flex} #a{width:20px;height:10px;flex-basis:60px} #b{width:30px;height:10px}", 200, "b", (60, 0, 30, 10)),
388 ("<div id='f'><div id='a'></div></div>",
390 "#f{display:flex;width:200px} #a{height:10px;flex-basis:50%}", 200, "a", (0, 0, 100, 10)),
391 ("<div id='f'><div id='a'></div><div id='b'></div></div>",
393 "#f{display:flex;width:200px} #a{height:10px;flex-basis:40px} #b{height:10px;flex-basis:40px;flex-grow:1}", 200, "b", (40, 0, 160, 10)),
394 ("<div id='f'><div id='a'></div><div id='b'></div></div>",
399 "#f{display:flex;width:200px} #a{height:10px;flex:0 0 40vw} #b{width:10px;height:10px}", 200, "b", (80, 0, 10, 10)),
400 ("<div id='t'><span id='a'></span><span id='b'></span></div>",
403 "#t{width:max-content;line-height:10px} #a{display:inline-block;width:50px;height:10px} #b{display:inline-block;width:50px;height:10px}", 400, "t", (0, 0, 100, 10)),
404 ("<div id='t'><span id='a'></span><span id='b'></span></div>",
406 "#t{width:min-content;line-height:10px} #a{display:inline-block;width:50px;height:10px} #b{display:inline-block;width:50px;height:10px}", 400, "t", (0, 0, 50, 20)),
407 ("<div id='t'><span id='a'></span><span id='b'></span></div>",
409 "#t{width:fit-content;line-height:10px} #a{display:inline-block;width:50px;height:10px} #b{display:inline-block;width:50px;height:10px}", 400, "t", (0, 0, 100, 10)),
410 ("<div id='outer'><div id='t'><span id='a'></span><span id='b'></span></div></div>",
412 "#outer{width:70px} #t{width:fit-content;line-height:10px} #a{display:inline-block;width:50px;height:10px} #b{display:inline-block;width:50px;height:10px}", 400, "t", (0, 0, 70, 20)),
413 ("<div id='t'></div>", "#t{height:90px;width:auto;aspect-ratio:16/9}", 400, "t", (0, 0, 160, 90)),
416 ("<div id='t'></div>", "#t{height:50px;width:auto;aspect-ratio:2/1}", 400, "t", (0, 0, 100, 50)),
418 ("<div id='t'></div>", "#t{height:60px;width:auto;aspect-ratio:1/1;max-width:40px}", 400, "t", (0, 0, 40, 60)),
420 ("<div id='f'><div id='a'></div><div id='b'></div></div>",
423 "#f{display:flex;width:200px} #a{width:30px;height:10px} #b{width:40px;height:10px;margin-left:auto}", 200, "b", (160, 0, 40, 10)),
424 ("<div id='f'><div id='a'></div></div>",
426 "#f{display:flex;width:200px} #a{width:50px;height:10px;margin:0 auto}", 200, "a", (75, 0, 50, 10)),
427 ("<div id='f'><div id='a'></div><div id='b'></div></div>",
429 "#f{display:flex;flex-direction:column;height:100px} #a{width:10px;height:10px} #b{width:10px;height:20px;margin-top:auto}", 200, "b", (0, 80, 10, 20)),
430 ("<div id='f'><div id='a'></div><div id='b'></div></div>",
433 "#f{display:flex;width:200px;column-gap:10%} #a{width:30px;height:10px} #b{width:40px;height:10px}", 200, "b", (50, 0, 40, 10)),
434 ("<div id='f'><div id='a'></div><div id='b'></div></div>",
436 "#f{display:flex;width:200px;gap:25%} #a{width:20px;height:10px} #b{width:20px;height:10px}", 200, "b", (70, 0, 20, 10)),
437 ("<div id='g'><div id='a'></div><div id='b'></div></div>",
439 "#g{display:grid;width:200px;grid-template-columns:repeat(2,80px);column-gap:10%} #a{height:10px} #b{height:10px}", 200, "b", (100, 0, 80, 10)),
440 ("<div id='t'><span id='a'></span><span id='b'></span></div>",
443 "#t{max-width:min-content;line-height:10px} #a{display:inline-block;width:50px;height:10px} #b{display:inline-block;width:50px;height:10px}", 400, "t", (0, 0, 50, 20)),
444 ("<div id='t'><span id='a'></span><span id='b'></span></div>",
446 "#t{width:20px;min-width:max-content;line-height:10px} #a{display:inline-block;width:50px;height:10px} #b{display:inline-block;width:50px;height:10px}", 400, "t", (0, 0, 100, 10)),
447 ("<div id='g'><div id='a'></div><div id='b'></div></div>",
450 "#g{display:grid;grid-template-rows:minmax(50px,auto)} #a{height:10px} #b{height:10px}", 200, "b", (0, 50, 200, 10)),
451 ("<div id='g'><div id='a'></div><div id='b'></div></div>",
453 "#g{display:grid;grid-template-rows:minmax(10px,30px)} #a{height:60px} #b{height:10px}", 200, "b", (0, 30, 200, 10)),
454 ("<div id='g'><div id='a'></div><div id='b'></div></div>",
456 "#g{display:grid;grid-template-rows:minmax(20px,1fr) 1fr;height:100px} #a{height:10px} #b{height:10px}", 200, "b", (0, 50, 200, 10)),
457 ("<div id='g'><div id='a'></div><div id='b'></div></div>",
462 "#g{display:grid;height:100px;grid-template-rows:50% 50%} #a{height:10px} #b{height:10px}", 200, "b", (0, 50, 200, 10)),
463 ("<div id='g'><div id='a'></div><div id='b'></div><div id='c'></div></div>",
466 "#g{display:grid;grid-template-columns:200px;grid-auto-rows:40px} #a{height:10px} #b{height:10px} #c{height:10px}", 200, "c", (0, 80, 200, 10)),
467 ("<div id='g'><div id='a'></div><div id='b'></div><div id='c'></div></div>",
469 "#g{display:grid;grid-template-columns:200px;grid-auto-rows:30px 60px} #a{height:10px} #b{height:10px} #c{height:10px}", 200, "c", (0, 90, 200, 10)),
470 ("<div id='g'><div id='a'></div><div id='b'></div><div id='c'></div><div id='d'></div></div>",
473 "#g{display:grid;grid-template-columns:repeat(2,100px);grid-template-rows:50px 50px;grid-auto-flow:column} #a{height:10px} #b{height:10px} #c{height:10px} #d{height:10px}", 200, "c", (100, 0, 100, 10)),
474 ("<div id='g'><div id='a'></div><div id='b'></div><div id='c'></div><div id='d'></div></div>",
476 "#g{display:grid;grid-template-columns:repeat(2,100px);grid-template-rows:50px 50px;grid-auto-flow:column} #a{height:10px} #b{height:10px} #c{height:10px} #d{height:10px}", 200, "b", (0, 50, 100, 10)),
477 ("<div id='g'><div id='a'></div><div id='b'></div><div id='c'></div><div id='d'></div><div id='e'></div></div>",
481 "#g{display:grid;grid-template-columns:repeat(2,100px);grid-template-rows:50px 50px;grid-auto-flow:column;grid-auto-columns:80px} #a{height:10px} #b{height:10px} #c{height:10px} #d{height:10px} #e{height:10px}", 300, "e", (200, 0, 80, 10)),
482 ("<div id='p'><div id='a'></div><div id='b'></div></div>",
485 "#p{width:200px} #a{float:left;width:50px;height:30px} #b{width:100px;height:10px}", 200, "b", (50, 0, 100, 10)),
486 ("<div id='p'><div id='a'></div></div>",
488 "#p{width:200px} #a{float:right;width:50px;height:30px}", 200, "a", (150, 0, 50, 30)),
489 ("<div id='p'><div id='a'></div><div id='c'></div></div>",
491 "#p{width:200px} #a{float:left;width:50px;height:30px} #c{clear:left;width:50px;height:10px}", 200, "c", (0, 30, 50, 10)),
492 ("<div id='p'><div id='a'></div><div id='b'></div></div>",
494 "#p{width:200px} #a{float:left;width:50px;height:10px} #b{width:100px;height:20px}", 200, "p", (0, 0, 200, 20)),
495 ("<div id='p'><div id='a'></div><div id='b'></div></div>",
498 "#p{width:200px} #a{float:inline-start;width:50px;height:30px} #b{width:100px;height:10px}", 200, "b", (50, 0, 100, 10)),
499 ("<div id='p'><div id='a'></div></div>",
501 "#p{width:200px;direction:rtl} #a{float:inline-start;width:50px;height:30px}", 200, "a", (150, 0, 50, 30)),
502 ("<div id='p'><div id='a'></div><div id='b'></div></div>",
504 "#p{width:200px;direction:rtl} #a{float:inline-end;width:50px;height:30px} #b{width:100px;height:10px}", 200, "b", (50, 0, 100, 10)),
505 ("<div id='g'><div id='h'></div><div id='s'></div><div id='c'></div></div>",
508 "#g{display:grid;grid-template-columns:100px 100px;grid-template-rows:20px 30px;grid-template-areas:'header header' 'sidebar content'} #h{grid-area:header} #s{grid-area:sidebar} #c{grid-area:content}",
509 200, "h", (0, 0, 200, 20)),
510 ("<div id='g'><div id='h'></div><div id='s'></div><div id='c'></div></div>",
512 "#g{display:grid;grid-template-columns:100px 100px;grid-template-rows:20px 30px;grid-template-areas:'header header' 'sidebar content'} #h{grid-area:header} #s{grid-area:sidebar} #c{grid-area:content}",
513 200, "s", (0, 20, 100, 30)),
514 ("<div id='g'><div id='h'></div><div id='s'></div><div id='c'></div></div>",
516 "#g{display:grid;grid-template-columns:100px 100px;grid-template-rows:20px 30px;grid-template-areas:'header header' 'sidebar content'} #h{grid-area:header} #s{grid-area:sidebar} #c{grid-area:content}",
517 200, "c", (100, 20, 100, 30)),
518 ("<div id='t'></div>", "#t{width:calc(100px + 50px);height:10px}", 400, "t", (0, 0, 150, 10)),
521 ("<div id='t'></div>", "#t{width:calc(50% - 20px);height:10px}", 400, "t", (0, 0, 180, 10)),
523 ("<div id='t'></div>", "#t{width:min(300px, 50%);height:10px}", 400, "t", (0, 0, 200, 10)),
525 ("<div id='t'></div>", "#t{width:max(300px, 50%);height:10px}", 400, "t", (0, 0, 300, 10)),
527 ("<div id='t'></div>", "#t{width:clamp(100px, 50%, 300px);height:10px}", 400, "t", (0, 0, 200, 10)),
529 ("<div id='t'></div>", "#t{width:clamp(100px, 10%, 300px);height:10px}", 400, "t", (0, 0, 100, 10)),
531 ("<div id='t'></div>", "#t{width:clamp(100px, 90%, 300px);height:10px}", 400, "t", (0, 0, 300, 10)),
533 ("<div id='a'></div><div id='b'></div>",
536 "#a{width:20px;height:10px} #b{width:20px;height:10px;margin-left:calc(10px * 3)}", 400, "b", (30, 10, 20, 10)),
537 ("<table><tr><td id='a'></td><td class='c'><div id='t'></div></td></tr></table>",
540 "table{border-spacing:0} td{padding:0} #a{width:50px;height:100px} .c{vertical-align:middle} #t{height:10px}", 400, "t", (200, 45, 200, 10)),
541 ("<table><tr><td id='a'></td><td class='c'><div id='t'></div></td></tr></table>",
543 "table{border-spacing:0} td{padding:0} #a{width:50px;height:100px} .c{vertical-align:bottom} #t{height:10px}", 400, "t", (200, 90, 200, 10)),
544 ("<table><tr><td id='a'></td><td><div id='t'></div></td></tr></table>",
546 "table{border-spacing:0} td{padding:0} #a{width:50px;height:100px} #t{height:10px}", 400, "t", (200, 0, 200, 10)),
547 ("<table><tr><td id='a'></td><td id='t' class='c'></td></tr></table>",
549 "table{border-spacing:0} td{padding:0} #a{width:50px;height:100px} .c{vertical-align:middle}", 400, "t", (200, 0, 200, 100)),
550 ("<table id='tbl'><tr><td id='a'></td><td id='t'></td></tr></table>",
553 "td{padding:0} #tbl{border-spacing:10px} #a{width:50px;height:20px} #t{width:50px;height:20px}", 400, "t", (205, 10, 185, 20)),
554 ("<table id='tbl'><tr><td id='a'></td></tr><tr><td id='t'></td></tr></table>",
556 "td{padding:0} #tbl{border-spacing:10px 5px} #a{height:20px} #t{height:20px}", 400, "t", (10, 30, 380, 20)),
557 ("<table id='tbl'><tr><td id='a'></td><td id='t'></td></tr></table>",
559 "table{border-spacing:0} td{padding:0} #tbl{border-collapse:collapse;border-spacing:10px} #a{width:50px;height:20px} #t{width:50px;height:20px}", 400, "t", (199, 0, 200, 20)),
560 ("<div id='wrap'><table id='tbl'><tr><td id='a'></td><td id='t'></td></tr></table></div>",
565 "table{border-spacing:0} td{padding:0} #wrap{border-collapse:collapse} #tbl{border-spacing:10px} #a{width:50px;height:20px} #t{width:50px;height:20px}", 400, "t", (199, 0, 200, 20)),
566 ("<table><caption id='cap' style='height:15px'></caption><tr><td id='t' style='height:20px'></td></tr></table>",
568 "table{border-spacing:0} td{padding:0} ", 400, "t", (0, 15, 400, 20)),
569 ("<table><caption id='cap' style='height:15px'></caption><tr><td id='t' style='height:20px'></td></tr></table>",
571 "table{border-spacing:0} td{padding:0} caption{caption-side:bottom}", 400, "t", (0, 0, 400, 20)),
572 ("<table><caption id='cap' style='height:15px'></caption><tr><td id='t' style='height:20px'></td></tr></table>",
574 "table{border-spacing:0} td{padding:0} caption{caption-side:bottom}", 400, "cap", (0, 20, 400, 15)),
575 ("<div id='d'><span id='t'>x</span></div>",
577 "#d{direction:rtl;width:100px} #t{width:30px;height:10px}", 400, "t", (70, 0, 30, 10)),
578 ("<div id='d'><span id='t'>x</span></div>",
580 "#d{direction:rtl;text-align:left;width:100px} #t{width:30px;height:10px}", 400, "t", (0, 0, 30, 10)),
581 ("<table><tr><td style='height:10px'></td></tr><tr class='c'><td style='height:20px'></td></tr><tr><td id='t' style='height:15px'></td></tr></table>",
584 "table{border-spacing:0} td{padding:0} .c{visibility:collapse}", 400, "t", (0, 10, 400, 15)),
585 ("<table id='tbl'><tr><td style='width:100px;height:20px'></td><td id='t' style='height:20px'></td></tr></table>",
588 "table{border-spacing:0} td{padding:0} #tbl{table-layout:fixed}", 400, "t", (100, 0, 300, 20)),
589 ("<table id='tbl'><tr><td style='width:50px;height:10px'></td></tr><tr><td id='t' style='width:200px;height:20px'></td></tr></table>",
592 "table{border-spacing:0} td{padding:0} #tbl{table-layout:fixed}", 400, "t", (0, 10, 50, 20)),
593 ("<table id='tbl' style='width:100px'><tr><td id='t'></td></tr></table>",
596 "td{padding:23px}", 400, "t", (25, 25, 50, 0)),
597 ("<span id='wrap'><span id='a' style='display:inline-block;width:10px;height:30px'></span><span id='t' style='display:inline-block;width:10px;height:10px'></span></span>",
599 "", 400, "t", (10, 0, 10, 10)),
600 ("<span id='wrap'><span id='a' style='display:inline-block;width:10px;height:30px'></span><span id='t' style='display:inline-block;width:10px;height:10px;vertical-align:middle'></span></span>",
602 "", 400, "t", (10, 10, 10, 10)),
603 ("<span id='wrap'><span id='a' style='display:inline-block;width:10px;height:30px'></span><span id='t' style='display:inline-block;width:10px;height:10px;vertical-align:bottom'></span></span>",
605 "", 400, "t", (10, 20, 10, 10)),
606 ("<span id='wrap'><span id='a' style='display:inline-block;width:10px;height:30px'></span><span id='t' style='display:inline-block;width:10px;height:10px;vertical-align:middle'></span></span>",
608 "", 400, "a", (0, 0, 10, 30)),
609 ("<div id='c'><span id='a' style='display:inline-block;width:200px;height:10px'></span><span id='b' style='display:inline-block;width:200px;height:10px'></span></div>",
613 "#c{width:250px;text-align-last:right;line-height:10px}", 400, "a", (0, 0, 200, 10)),
614 ("<div id='c'><span id='a' style='display:inline-block;width:200px;height:10px'></span><span id='b' style='display:inline-block;width:200px;height:10px'></span></div>",
615 "#c{width:250px;text-align-last:right;line-height:10px}", 400, "b", (50, 10, 200, 10)),
616 ("<div id='c'><span id='t' style='display:inline-block;width:30px;height:10px'></span></div>",
619 "#c{width:100px;text-align:end}", 400, "t", (70, 0, 30, 10)),
620 ("<div id='c'><span id='t' style='display:inline-block;width:30px;height:10px'></span></div>",
622 "#c{width:100px;direction:rtl;text-align:start}", 400, "t", (70, 0, 30, 10)),
623 ("<div id='c'><span id='t' style='display:inline-block;width:30px;height:10px'></span></div>",
625 "#c{width:100px;direction:rtl;text-align:end}", 400, "t", (0, 0, 30, 10)),
626 ("<div id='a' hidden style='height:10px'></div><div id='b' style='height:10px'></div>",
630 "", 200, "b", (0, 0, 200, 10)),
631 ("<div id='a' hidden style='display:block;height:10px'></div><div id='b' style='height:10px'></div>",
634 "", 200, "b", (0, 10, 200, 10)),
635 ("<div id='d' dir='rtl'><span id='t' style='width:30px;height:10px'></span></div>",
639 "#d{width:100px}", 400, "t", (70, 0, 30, 10)),
640 ("<div id='d' dir='rtl'><span id='t' style='width:30px;height:10px'></span></div>",
643 "#d{width:100px;direction:ltr}", 400, "t", (0, 0, 30, 10)),
644 ("<div id='c'><span id='a' style='display:inline-block;width:100px;height:10px'></span><span id='b' style='display:inline-block;width:10px;height:10px'></span><span id='c2' style='display:inline-block;width:150px;height:10px'></span><span id='d' style='display:inline-block;width:50px;height:10px'></span></div>",
647 "#c{width:200px;text-align:justify;line-height:10px}", 400, "a", (0, 0, 100, 10)),
648 ("<div id='c'><span id='a' style='display:inline-block;width:100px;height:10px'></span><span id='b' style='display:inline-block;width:10px;height:10px'></span><span id='c2' style='display:inline-block;width:150px;height:10px'></span><span id='d' style='display:inline-block;width:50px;height:10px'></span></div>",
649 "#c{width:200px;text-align:justify;line-height:10px}", 400, "b", (190, 0, 10, 10)),
650 ("<div id='c'><span id='a' style='display:inline-block;width:100px;height:10px'></span><span id='b' style='display:inline-block;width:10px;height:10px'></span><span id='c2' style='display:inline-block;width:150px;height:10px'></span><span id='d' style='display:inline-block;width:50px;height:10px'></span></div>",
653 "#c{width:200px;text-align:justify;line-height:10px}", 400, "c2", (0, 10, 150, 10)),
654 ("<div id='c'><span id='a' style='display:inline-block;width:100px;height:10px'></span><span id='b' style='display:inline-block;width:10px;height:10px'></span><span id='c2' style='display:inline-block;width:150px;height:10px'></span><span id='d' style='display:inline-block;width:50px;height:10px'></span></div>",
655 "#c{width:200px;text-align:justify;line-height:10px}", 400, "d", (150, 10, 50, 10)),
656 ("<template id='a'><div style='height:10px'></div></template><div id='b' style='height:10px'></div>",
662 "", 200, "b", (0, 0, 200, 10)),
663 ("<noscript>plain text fallback</noscript><div id='b' style='height:10px'></div>",
666 "", 200, "b", (0, 0, 200, 10)),
667 ("<article id='a' style='height:10px'></article><div id='b' style='height:10px'></div>",
671 "", 200, "b", (0, 10, 200, 10)),
672 ("<figure id='a' style='height:10px'></figure><div id='b' style='height:10px'></div>",
674 "", 200, "b", (0, 10, 200, 10)),
675 ("<details id='d'><summary style='height:10px'></summary><div id='c' style='height:20px'></div></details><div id='b' style='height:10px'></div>",
683 "", 200, "b", (0, 10, 200, 10)),
684 ("<details id='d' open><summary style='height:10px'></summary><div id='c' style='height:20px'></div></details><div id='b' style='height:10px'></div>",
687 "", 200, "b", (0, 30, 200, 10)),
688 ("<details id='d' open><summary style='height:10px'></summary><div id='c' style='height:20px'></div></details>",
690 "", 200, "c", (0, 10, 200, 20)),
691 ("<iframe id='f' width='300' height='150'></iframe>",
697 "", 400, "f", (0, 0, 300, 150)),
698 ("<div id='p' style='width:400px'><iframe id='f' width='50%' height='100'></iframe></div>",
700 "", 400, "f", (0, 0, 200, 100)),
701 ("<iframe id='f' width='300' height='150' style='width:50px;height:20px'></iframe>",
704 "", 400, "f", (0, 0, 50, 20)),
705 ];
706 let mut passed = 0;
707 let total = cases.len();
708 for (html, css, vw, id, exp) in cases {
709 match measure(html, css, *vw, id) {
710 Some(d) if d == *exp => passed += 1,
711 Some(d) => crate::println!(
712 "LAYOUT_SELFTEST FAIL: #{} => ({},{},{},{}) want ({},{},{},{})",
713 id,
714 d.0,
715 d.1,
716 d.2,
717 d.3,
718 exp.0,
719 exp.1,
720 exp.2,
721 exp.3
722 ),
723 None => crate::println!("LAYOUT_SELFTEST FAIL: #{} NOT FOUND", id),
724 }
725 }
726
727 let mut extra_passed = 0usize;
734 let mut extra_total = 0usize;
735
736 let det_html = "<div id='c'><div id='a'></div><div id='b'></div></div>";
738 let det_css = "#c{display:flex} #a{width:30px;height:10px} #b{width:40px;height:10px}";
739 extra_total += 1;
740 let r1 = measure(det_html, det_css, 200, "b");
741 let r2 = measure(det_html, det_css, 200, "b");
742 if r1.is_some() && r1 == r2 {
743 extra_passed += 1;
744 } else {
745 crate::println!("LAYOUT_SELFTEST FAIL: determinism r1={:?} r2={:?}", r1, r2);
746 }
747
748 extra_total += 1;
750 {
751 let dom = super::super::dom::parse_html(det_html);
752 let sheet_fresh = super::super::css::parse_css(det_css);
753 let sheet_cached = sheet_fresh.clone(); set_viewport_hint(200, 600);
755 let icb = || Dimensions {
756 content: Rect {
757 x: 0,
758 y: 0,
759 width: 200,
760 height: 0,
761 },
762 ..Default::default()
763 };
764 let styled_a = super::super::css::style_tree(&dom, &sheet_fresh);
765 let styled_b = super::super::css::style_tree(&dom, &sheet_cached);
766 let ta = layout_tree(&styled_a, icb());
767 let tb = layout_tree(&styled_b, icb());
768 let da = find(&ta, "b").map(|b| {
769 let c = &b.dimensions.content;
770 (c.x, c.y, c.width, c.height)
771 });
772 let db = find(&tb, "b").map(|b| {
773 let c = &b.dimensions.content;
774 (c.x, c.y, c.width, c.height)
775 });
776 if da.is_some() && da == db {
777 extra_passed += 1;
778 } else {
779 crate::println!(
780 "LAYOUT_SELFTEST FAIL: css cache equiv da={:?} db={:?}",
781 da,
782 db
783 );
784 }
785 }
786
787 extra_total += 1;
789 {
790 let root = super::super::dom::Node::empty_root();
791 let is_html = matches!(
792 &root.node_type,
793 super::super::dom::NodeType::Element { tag_name, .. } if tag_name == "html"
794 );
795 if is_html && root.children.is_empty() {
796 extra_passed += 1;
797 } else {
798 crate::println!("LAYOUT_SELFTEST FAIL: empty_root shape");
799 }
800 }
801
802 {
806 use crate::kernel::vector_font::{get_vector_string_width, get_vector_string_width_ls};
807 let s = "ABCDE"; let nchars = s.chars().count() as i32;
809 let base = get_vector_string_width(s, 16) as i32;
810
811 extra_total += 1;
813 if get_vector_string_width_ls(s, 16, 0) as i32 == base {
814 extra_passed += 1;
815 } else {
816 crate::println!("LAYOUT_SELFTEST FAIL: letter-spacing ls=0 != base");
817 }
818
819 extra_total += 1;
821 if get_vector_string_width_ls(s, 16, 2) as i32 == base + nchars * 2 {
822 extra_passed += 1;
823 } else {
824 crate::println!("LAYOUT_SELFTEST FAIL: letter-spacing ls=2 width");
825 }
826
827 extra_total += 1;
829 if get_vector_string_width_ls(s, 16, -1) as i32 == (base - nchars).max(0) {
830 extra_passed += 1;
831 } else {
832 crate::println!("LAYOUT_SELFTEST FAIL: letter-spacing ls=-1 width");
833 }
834
835 extra_total += 1;
837 if parse_letter_spacing(Some("normal")) == 0
838 && parse_letter_spacing(Some("3px")) == 3
839 && parse_letter_spacing(Some("-2px")) == -2
840 && parse_letter_spacing(None) == 0
841 && parse_letter_spacing(Some("4")) == 4
842 {
843 extra_passed += 1;
844 } else {
845 crate::println!("LAYOUT_SELFTEST FAIL: parse_letter_spacing");
846 }
847
848 extra_total += 1;
851 if parse_letter_spacing_ctx(Some("calc(1px + 1px)"), 0) == 2
852 && parse_letter_spacing_ctx(Some("min(3px, 5px)"), 0) == 3
853 && parse_letter_spacing_ctx(Some("max(3px, 5px)"), 0) == 5
854 && parse_letter_spacing_ctx(Some("clamp(1px, 10px, 5px)"), 0) == 5
855 {
856 extra_passed += 1;
857 } else {
858 crate::println!("LAYOUT_SELFTEST FAIL: parse_letter_spacing_ctx calc/min/max/clamp");
859 }
860 }
861
862 {
864 use crate::kernel::vector_font::{get_vector_string_width, get_vector_string_width_ls_ws};
865 let s = "AB CD EF"; let base = get_vector_string_width(s, 16) as i32;
867
868 extra_total += 1;
869 if get_vector_string_width_ls_ws(s, 16, 0, 0) as i32 == base {
870 extra_passed += 1;
871 } else {
872 crate::println!("LAYOUT_SELFTEST FAIL: word-spacing ws=0 != base");
873 }
874
875 extra_total += 1;
876 if get_vector_string_width_ls_ws(s, 16, 0, 5) as i32 == base + 2 * 5 {
877 extra_passed += 1;
878 } else {
879 crate::println!("LAYOUT_SELFTEST FAIL: word-spacing ws=5 width");
880 }
881
882 extra_total += 1;
883 if parse_word_spacing(Some("normal")) == 0
884 && parse_word_spacing(Some("3px")) == 3
885 && parse_word_spacing(Some("-2px")) == -2
886 && parse_word_spacing(None) == 0
887 {
888 extra_passed += 1;
889 } else {
890 crate::println!("LAYOUT_SELFTEST FAIL: parse_word_spacing");
891 }
892 }
893
894 {
899 let orig_w = VIEWPORT_HINT_W.load(AtomicOrdering::Relaxed);
904 let orig_h = VIEWPORT_HINT_H.load(AtomicOrdering::Relaxed);
905 set_viewport_hint(1000, 500);
906 let translate_cases: &[(&str, i32, i32)] = &[
907 ("10px", 0, 10),
908 ("50%", 200, 100),
909 ("2rem", 0, 32),
910 ("50vh", 0, 250),
911 ("50vw", 0, 500),
912 ];
913 for (tok, base, want) in translate_cases {
914 extra_total += 1;
915 let got = resolve_translate_len(tok, *base);
916 if got == *want {
917 extra_passed += 1;
918 } else {
919 crate::println!(
920 "LAYOUT_SELFTEST FAIL: resolve_translate_len(`{}`, {}) => {} (want {})",
921 tok, base, got, want
922 );
923 }
924 }
925 VIEWPORT_HINT_W.store(orig_w, AtomicOrdering::Relaxed);
926 VIEWPORT_HINT_H.store(orig_h, AtomicOrdering::Relaxed);
927 }
928
929 (passed + extra_passed, total + extra_total)
930}