lini 1.0.0-alpha.0

Pretty diagrams, charts, and technical drawings from plain text, with fine-grained control. Compiles to clean, themeable SVG.
Documentation
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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
use super::super::testutil::{by_id, laid, layout_err, text_at, texts};
use crate::ledger::consts::{DIM_OFFSET, DIM_PITCH};
use crate::resolve::{MarkerKind, NodeKind, ResolvedValue};

// ── Linear dims & chains [SPEC 15.6] ──

#[test]
fn a_chain_shares_one_row_and_the_next_dim_packs_outside() {
    // Plate −75..75, holes at −50 and 10, at 2 px/unit: hops 25 · 60 · 65
    // all fit their spans and share one row; the overall 150 overlaps
    // them and takes the next.
    let l = laid(
        "{ layout: drawing; scale: 2; density: 1 }\n|rect#plate| { width: 150; height: 40 }\n|hole#a| { width: 8; translate: -50 0 }\n|hole#b| { width: 8; translate: 10 0 }\nplate:left (-) a (-) b (-) plate:right { side: bottom }\nplate:left (-) plate:right { side: bottom }\n",
    );
    let (_, y25, _) = text_at(&l.nodes, "25");
    let (_, y60, _) = text_at(&l.nodes, "60");
    let (_, y65, _) = text_at(&l.nodes, "65");
    let (_, y150, _) = text_at(&l.nodes, "150");
    assert!(
        (y25 - y60).abs() < 1e-6 && (y60 - y65).abs() < 1e-6,
        "hops share the row: {y25} / {y60} / {y65}"
    );
    assert!(
        (y150 - y60 - DIM_PITCH).abs() < 0.01,
        "the 150 packs one pitch out: {y150} vs {y60}"
    );
    // First row sits DIM_OFFSET past the plate's paint extent (41 + 18),
    // text lifted 7.5 above the line.
    assert!((y60 - (41.0 + DIM_OFFSET - 7.5)).abs() < 0.6, "y60={y60}");
}

#[test]
fn iso_text_turns_with_a_vertical_dim() {
    let l = laid(
        "{ layout: drawing; density: 1 }\n|rect#a| { width: 60; height: 40 }\na:top (-) a:bottom { side: right }\n",
    );
    let (x, _, rot) = text_at(&l.nodes, "40");
    assert_eq!(rot, -90.0, "reads from the right");
    let a = by_id(&l.nodes, "a");
    assert!(x > a.cx + 30.0, "stacked right of the geometry: x={x}");
}

#[test]
fn a_narrow_span_flips_arrows_out_but_keeps_a_fitting_value_inside() {
    // A 20-wide span can't hold text + arrows, but the bare "20" still
    // reads between the extension lines: arrows flip out, value centred
    // inside — drafting's middle form [SPEC 15.6].
    let l = laid(
        "{ layout: drawing; density: 1 }\n|rect#a| { width: 20; height: 10 }\na:left (-) a:right { side: bottom }\n",
    );
    let (x, _, _) = text_at(&l.nodes, "20");
    assert!(x.abs() < 1e-6, "value centred inside the span: x={x}");
}

#[test]
fn a_span_too_tight_for_its_value_slides_the_text_past() {
    // A 10-wide span can't even hold "10" — the text slides rightward,
    // past the higher-u extension line.
    let l = laid(
        "{ layout: drawing; density: 1 }\n|rect#a| { width: 10; height: 8 }\na:left (-) a:right { side: bottom }\n",
    );
    let (x, _, _) = text_at(&l.nodes, "10");
    assert!(x > 5.0, "text outside the span: x={x}");
}

#[test]
fn corner_anchors_on_one_edge_pull_the_dim_there() {
    let l = laid(
        "{ layout: drawing; density: 1 }\n|rect#a| { width: 40; height: 20 }\n|rect#b| { width: 40; height: 20; translate: 70 0 }\na:top-left (-) b:top-right\n",
    );
    let (_, y, _) = text_at(&l.nodes, "110");
    let a = by_id(&l.nodes, "a");
    assert!(y < a.cy - 10.0, "pulled to the top: y={y}");
}

#[test]
fn a_two_ended_label_replaces_the_number() {
    let l = laid(
        "{ layout: drawing; density: 1 }\n|rect#a| { width: 40; height: 20 }\na:left (-) a:right \"180\"\n",
    );
    text_at(&l.nodes, "180");
    assert!(
        !texts(&l.nodes).iter().any(|(t, ..)| t == "40"),
        "the measured 40 is replaced"
    );
}

#[test]
fn measured_values_read_bare_pre_scale_numbers() {
    // `unit:` is the semantic quantity only [SPEC 15.1]: no per-value suffix
    // (drafting states units once, in the title block), and the value is
    // pre-scale — 40 units at `unit: mm` reads `40`, whatever the density.
    let l = laid(
        "{ layout: drawing; unit: mm }\n|rect#a| { width: 40; height: 20 }\n|hole#h| { width: 12 }\na:left (-) a:right { side: bottom }\nh (o)\n",
    );
    text_at(&l.nodes, "40");
    text_at(&l.nodes, "⌀12");
}

#[test]
fn dim_errors_speak_spec() {
    assert_eq!(
        layout_err(
            "{ layout: drawing; density: 1 }\n|rect#a| { width: 40; height: 20 }\n|rect#b| { width: 40; height: 20 }\na:left (-) b:top\n"
        ),
        "'a:left (-) b:top' mixes axes — anchor one axis"
    );
    assert_eq!(
        layout_err(
            "{ layout: drawing; density: 1 }\n|rect#a| { width: 40; height: 20 }\na:left (-) a:right { side: left }\n"
        ),
        "a horizontal dimension stacks on top or bottom"
    );
    assert_eq!(
        layout_err(
            "{ layout: drawing; density: 1 }\n|rect#a| { width: 40; height: 20 }\na:top (-) a:bottom { side: top }\n"
        ),
        "a vertical dimension stacks on left or right"
    );
    assert_eq!(
        layout_err(
            "{ layout: drawing; density: 1 }\n|rect#a| { width: 40; height: 20 }\na:left (-) a:right { tol: \"x\" }\n"
        ),
        "'tol' takes a number, '+upper -lower', or a fit ident"
    );
}

// ── Tolerances [SPEC 15.6] ──

#[test]
fn tol_composes_its_three_forms() {
    let sym = laid(
        "{ layout: drawing; density: 1 }\n|rect#a| { width: 40; height: 20 }\na:left (-) a:right { tol: 0.1 }\n",
    );
    text_at(&sym.nodes, "40±0.1");

    let fit = laid(
        "{ layout: drawing; density: 1 }\n|rect#a| { width: 40; height: 20 }\na:left (-) a:right { tol: H7 }\n",
    );
    text_at(&fit.nodes, "40 H7");

    // Stacked deviations: raised / lowered beside the value, 0.7 × font.
    let dev = laid(
        "{ layout: drawing; density: 1 }\n|rect#a| { width: 40; height: 20 }\na:left (-) a:right { tol: +0.2 -0.05 }\n",
    );
    let (_, yu, _) = text_at(&dev.nodes, "+0.2");
    let (_, yl, _) = text_at(&dev.nodes, "-0.05");
    let (_, ym, _) = text_at(&dev.nodes, "40");
    assert!(
        yu < ym && ym < yl,
        "raised {yu} / value {ym} / lowered {yl}"
    );
}

// ── The `(o)` readings [SPEC 15.6] ──

#[test]
fn a_named_arc_reads_its_radius() {
    let l = laid(
        "{ layout: drawing; scale: 2; density: 1 }\n|sketch#s| { draw: move(0, 0) right(30) fillet(3):r1 up(20) left(30) down(20) close() }\ns:r1 (o)\n",
    );
    text_at(&l.nodes, "R3");
}

#[test]
fn a_circle_segment_reads_its_diameter() {
    let l = laid(
        "{ layout: drawing; density: 1 }\n|sketch#s| { draw: move(0, 0) right(40) up(20) left(40) close() move(20, -10) circle(5):c }\ns:c (o)\n",
    );
    text_at(&l.nodes, "⌀10");
}

#[test]
fn a_bare_round_node_leaders_its_diameter_with_the_copy_count() {
    let l = laid(
        "{ layout: drawing; density: 1 }\n|rect#plate| { width: 120; height: 60 } [\n  |hole#pin| { width: 10; translate: -35 0; pattern: grid(2, 1, 70, 0) }\n]\nplate.pin (o) \"H7\"\n",
    );
    text_at(&l.nodes, "2× ⌀10 H7");
}

#[test]
fn a_side_anchor_on_a_round_node_draws_the_diametral_line() {
    // The value doesn't fit inside ⌀16 — the line overruns the anchored
    // rim and the text spills upward, turned with the vertical line.
    let l = laid(
        "{ layout: drawing; density: 1 }\n|rect#plate| { width: 80; height: 40 }\n|hole#eye| { width: 16 }\neye:top (o)\n",
    );
    let (_, y, rot) = text_at(&l.nodes, "⌀16");
    assert_eq!(rot, -90.0, "turned with the line");
    assert!(y < -8.0, "spills past the top rim: y={y}");
}

#[test]
fn a_side_anchor_on_any_node_spans_to_the_opposite_side() {
    let l = laid(
        "{ layout: drawing; density: 1 }\n|rect#bore| { width: 60; height: 16 }\nbore:top (o) { side: right }\n",
    );
    let (x, _, _) = text_at(&l.nodes, "⌀16");
    assert!(x > 30.0, "stacked on the right: x={x}");
}

#[test]
fn a_revolved_name_spans_its_station_across_the_axis() {
    let l = laid(
        "{ layout: drawing; scale: 2; density: 1 }\n|sketch#bar| { draw: move(-150, 0) up(10) right(40):thread right(260) down(10); revolve: x-axis }\nbar:thread (o) { side: left; tol: h6 }\n",
    );
    text_at(&l.nodes, "⌀20 h6");
}

#[test]
fn a_station_diameter_requires_a_revolve() {
    // A merely mirrored profile's span is a width, not a diameter
    // [SPEC 15.6] — the reading asks for the revolve.
    assert_eq!(
        layout_err(
            "{ layout: drawing; scale: 2; density: 1 }\n|sketch#bar| { draw: move(-150, 0) up(10) right(40):thread right(260) down(10); mirror: x-axis }\nbar:thread (o) { side: left }\n"
        ),
        "a station '⌀' reads a revolved profile — 'revolve: x-axis'"
    );
}

#[test]
fn a_bare_round_measure_needs_an_axis() {
    assert_eq!(
        layout_err(
            "{ layout: drawing; density: 1 }\n|rect#block| { width: 40; height: 20 }\nblock (o)\n"
        ),
        "'(o)' can't pick an axis on 'block' — anchor a side ('block:top (o)') or a segment"
    );
}

// ── `(<)` — the angle [SPEC 15.6] ──

#[test]
fn an_angle_reads_two_edges_and_rides_its_arc() {
    // rise 120 over run 160 → atan = 36.87°.
    let l = laid(
        "{ layout: drawing; scale: 2; density: 1 }\n|sketch#g| { draw: move(-40, 30) right(80):base up(60) line(-80, 60):flank close() }\ng:flank (<) g:base\n",
    );
    text_at(&l.nodes, "36.87°");
}

#[test]
fn a_unary_angle_measures_the_included_taper() {
    // A 10-in-40 taper mirrored about x: included angle = 2 · atan(10/40)
    // = 28.07°.
    let l = laid(
        "{ layout: drawing; density: 1 }\n|sketch#cone| { draw: move(0, 0) line(40, -10):taper; mirror: x-axis }\ncone:taper (<)\n",
    );
    text_at(&l.nodes, "28.07°");
}

#[test]
fn angle_errors_speak_spec() {
    assert_eq!(
        layout_err(
            "{ layout: drawing; density: 1 }\n|oval#a| { width: 20; height: 20 }\n|oval#b| { width: 20; height: 20 }\na (<) b\n"
        ),
        "an angle reads two edges — a named segment, a '|line|', or a side"
    );
    assert_eq!(
        layout_err(
            "{ layout: drawing; density: 1 }\n|sketch#s| { draw: move(0, 0) line(40, -10):taper up(10) close() }\ns:taper (<)\n"
        ),
        "'(<)' on ':taper' needs 'mirror:' — no twin to measure against"
    );
    assert_eq!(
        layout_err(
            "{ layout: drawing; density: 1 }\n|rect#a| { width: 40; height: 20 }\n|rect#b| { width: 40; height: 20 }\na:top (<) b:bottom\n"
        ),
        "the angle's edges are parallel — they never meet"
    );
}

// ── Leaders [SPEC 15.7] ──

/// The slender arrowhead's exact tip — its poly's first point
/// (`dims::arrow` builds tip-first); word leaders carry it since the
/// ISO 129 unification [SPEC 15.7].
fn arrow_tip(nodes: &[crate::layout::PlacedNode]) -> (f64, f64) {
    nodes
        .iter()
        .find(|n| n.type_chain.iter().any(|t| t == "marker-dim"))
        .map(|n| {
            crate::layout::primitives::attr_points(&n.attrs, "points", n.span)
                .unwrap()
                .unwrap()[0]
        })
        .expect("a slender arrowhead")
}

#[test]
fn a_leader_tip_ray_casts_onto_the_outline_with_a_landing_elbow() {
    let l = laid(
        "{ layout: drawing; density: 1 }\n|oval#disc| { width: 40; height: 40 }\ndisc:top-right <- \"THRU\"\n",
    );
    let line = l
        .nodes
        .iter()
        .find(|n| n.type_chain.iter().any(|t| t == "dim-line"))
        .expect("the leader line");
    let pts = crate::layout::primitives::attr_points(&line.attrs, "points", line.span)
        .unwrap()
        .unwrap();
    assert_eq!(pts.len(), 3, "tip, elbow, landing");
    // The slender arrowhead's own tip sits on the circle (r = 20), not
    // the bbox corner — the line stops a stub short of it [SPEC 15.6/7].
    let tip = arrow_tip(&l.nodes);
    assert!(
        (tip.0.hypot(tip.1) - 20.0).abs() < 0.75,
        "tip on the rim: {tip:?}"
    );
    // The landing is horizontal.
    assert!((pts[1].1 - pts[2].1).abs() < 1e-9, "horizontal landing");
    // Text past the landing.
    let (tx, ty, _) = text_at(&l.nodes, "THRU");
    assert!(tx > pts[2].0, "text past the landing");
    assert!((ty - pts[2].1).abs() < 1e-6, "text rides the landing");
}

#[test]
fn a_word_leader_tips_the_rim_of_a_patterned_hole() {
    // The carrier's ray-cast recurses into a copy — the copy must not
    // still look like a carrier (the pattern attr made it return None
    // and the tip fell back to the hole's centre).
    let l = laid(
        "{ layout: drawing; density: 1 }\n|rect#plate| { width: 120; height: 60 } [\n  |hole#pin| { width: 10; translate: -35 0; pattern: grid(2, 1, 70, 0) }\n]\nplate.pin <- \"THRU\" { side: top }\n",
    );
    let tip = arrow_tip(&l.nodes);
    let d = ((tip.0 - -35.0).powi(2) + tip.1.powi(2)).sqrt();
    assert!((d - 5.0).abs() < 0.75, "tip on the seed's rim: {tip:?}");
}

#[test]
fn a_circle_diameter_runs_across_with_both_arrows() {
    // The ⌀ line is a diameter, not a word leader [SPEC 15.6]: it crosses
    // the circle, overshoots the far rim, and presses both rims inward.
    let l = laid(
        "{ layout: drawing; density: 1 }\n|rect#plate| { width: 80; height: 40 }\n|hole#eye| { width: 12 }\neye (o)\n",
    );
    let arrows: Vec<_> = l
        .nodes
        .iter()
        .filter(|n| n.type_chain.iter().any(|t| t == "marker-dim"))
        .collect();
    assert_eq!(arrows.len(), 2, "an arrowhead on each rim");
    let line = l
        .nodes
        .iter()
        .find(|n| n.type_chain.iter().any(|t| t == "dim-line"))
        .expect("the ⌀ line");
    let pts = crate::layout::primitives::attr_points(&line.attrs, "points", line.span)
        .unwrap()
        .unwrap();
    let start_r = (pts[0].0.powi(2) + pts[0].1.powi(2)).sqrt();
    assert!(
        start_r > 6.0 && start_r < 21.0,
        "the line overshoots the far rim: {pts:?}"
    );
}

#[test]
fn side_steers_a_leader() {
    let l = laid(
        "{ layout: drawing; density: 1 }\n|oval#disc| { width: 40; height: 40 }\ndisc <- \"A\" { side: left }\n",
    );
    let (tx, _, _) = text_at(&l.nodes, "A");
    assert!(tx < -20.0, "text left of the disc: {tx}");
}

#[test]
fn the_datum_triangle_seats_on_the_surface() {
    // `>-` on a directed feature: the GD&T triangle's base lies flush
    // with the drawn edge (y = 15), its apex out along the surface
    // normal — never tilted by the leader's approach angle [SPEC 15.7].
    let l = laid(
        "{ layout: drawing; density: 1 }\n|rect#block| { width: 60; height: 30 }\nblock:bottom >- \"A\"\n",
    );
    let tri = l
        .nodes
        .iter()
        .find(|n| n.type_chain.iter().any(|t| t == "marker-datum"))
        .expect("the seated datum triangle");
    let pts = crate::layout::primitives::attr_points(&tri.attrs, "points", tri.span)
        .unwrap()
        .unwrap();
    assert!(
        (pts[0].1 - 15.0).abs() < 1e-6 && (pts[1].1 - 15.0).abs() < 1e-6,
        "base on the bottom face: {pts:?}"
    );
    assert!(pts[2].1 > 15.0, "apex out along the normal: {pts:?}");
    // …and its leader leaves straight off the face — vertical to the
    // elbow, then the horizontal landing [SPEC 15.7].
    let line = l
        .nodes
        .iter()
        .find(|n| n.type_chain.iter().any(|t| t == "dim-line"))
        .expect("the datum leader");
    let lp = crate::layout::primitives::attr_points(&line.attrs, "points", line.span)
        .unwrap()
        .unwrap();
    assert!(
        (lp[0].0 - lp[1].0).abs() < 1e-6,
        "straight off the surface: {lp:?}"
    );
    // A point-anchored datum keeps the core marker, oriented by the line.
    let l = laid(
        "{ layout: drawing; density: 1 }\n|oval#pin| { width: 20; height: 20 }\npin >- \"B\"\n",
    );
    assert!(
        l.nodes
            .iter()
            .any(|n| n.kind == NodeKind::Line && n.markers.start == MarkerKind::Datum),
        "the fallback datum marker"
    );
}

#[test]
fn a_two_ended_arrow_trims_at_the_rim_and_dots_within() {
    // `b1 -* part`: the line springs from the balloon's rim (default
    // anchor → trimmed) and its dot lands at the part's origin (within).
    let l = laid(
        "{ layout: drawing; density: 1 }\n|rect#part| { width: 60; height: 30 }\n|balloon#b1| \"1\" { translate: 60 -40 }\nb1 -* part\n",
    );
    let line = l
        .nodes
        .iter()
        .find(|n| n.kind == NodeKind::Line && n.markers.end == MarkerKind::Dot)
        .expect("the wire");
    let pts = crate::layout::primitives::attr_points(&line.attrs, "points", line.span)
        .unwrap()
        .unwrap();
    let b1 = by_id(&l.nodes, "b1");
    assert!(
        (pts[0].0 - b1.cx).hypot(pts[0].1 - b1.cy) > 7.0,
        "start off the balloon's centre: {:?}",
        pts[0]
    );
    assert_eq!(pts[1], (0.0, 0.0), "the dot lands on the part's origin");
}

#[test]
fn a_leader_tip_lands_on_a_recessed_edge_not_the_box() {
    // The thread section sits below the profile's outer surface: the tip
    // must ray-cast onto the drawn edge (y = −63), not stop at the
    // geometry box (y = −75) — the floating-datum bug (`ray_line`'s
    // segment parameter accepted each segment's mirror about its start).
    let l = laid(
        "{ layout: drawing; scale: 3; density: 1 }\n|sketch#body| { draw: move(-80, 0) up(21) right(38):thread right(32):land up(4) right(90) down(25); mirror: x-axis }\nbody:thread <- \"M42\" { side: top }\nbody:land >- \"A\"\n",
    );
    let arrow_tip = arrow_tip(&l.nodes);
    assert!(
        (arrow_tip.1 + 63.0).abs() < 1e-6,
        "the arrow touches the drawn surface: {arrow_tip:?}"
    );
    let tri = l
        .nodes
        .iter()
        .find(|n| n.type_chain.iter().any(|t| t == "marker-datum"))
        .expect("the seated datum triangle");
    let pts = crate::layout::primitives::attr_points(&tri.attrs, "points", tri.span)
        .unwrap()
        .unwrap();
    assert!(
        (pts[0].1 + 63.0).abs() < 1e-6 && (pts[1].1 + 63.0).abs() < 1e-6,
        "the datum base sits on the drawn surface: {pts:?}"
    );
}

#[test]
fn a_dim_row_clears_leader_texts() {
    // A callout's text registers as an obstacle: a dim stacked on the
    // same side seats its row past it, never on top of it [SPEC 15.6].
    let l = laid(
        "{ layout: drawing; density: 1 }\n|rect#bar| { width: 200; height: 30 }\nbar:top <- \"M42\"\nbar:left (-) bar:right { side: top }\n",
    );
    let (_, ty, _) = text_at(&l.nodes, "M42");
    let (_, dy, _) = text_at(&l.nodes, "200");
    assert!(
        dy < ty - 8.0,
        "the 200 climbs past the callout text: dim {dy} vs callout {ty}"
    );
}

// ── The anatomy's class hooks [SPEC 17] ──

#[test]
fn dimension_anatomy_wears_its_classes() {
    // Paint states once per class: the dim line, the light extension
    // lines, the marker-classed arrowheads — no per-element inline style.
    let l = laid(
        "{ layout: drawing; density: 1 }\n|rect#a| { width: 60; height: 20 }\na:left (-) a:right { side: bottom }\n",
    );
    let with_chain = |name: &str| {
        l.nodes
            .iter()
            .filter(|n| n.type_chain.iter().any(|t| t == name))
            .collect::<Vec<_>>()
    };
    assert_eq!(with_chain("ext-line").len(), 2, "two extension springs");
    assert_eq!(with_chain("dim-line").len(), 1, "the dim line");
    assert_eq!(with_chain("marker-dim").len(), 2, "two arrowheads");
    // Extension lines take the light support tone [SPEC 15.6]…
    assert!(
        matches!(
            with_chain("ext-line")[0].attrs.get("stroke"),
            Some(ResolvedValue::LiveVar { name, .. }) if name == "stroke-light"
        ),
        "--stroke-light by default"
    );
    // …until the statement recolours — then the whole dim follows.
    let red = laid(
        "{ layout: drawing; density: 1 }\n|rect#a| { width: 60; height: 20 }\na:left (-) a:right { side: bottom; stroke: red }\n",
    );
    let ext = red
        .nodes
        .iter()
        .find(|n| n.type_chain.iter().any(|t| t == "ext-line"))
        .expect("extension line");
    assert!(
        matches!(ext.attrs.get("stroke"), Some(ResolvedValue::Ident(c)) if c == "red"),
        "a recoloured statement recolours its extension lines too"
    );
}

// ── The drawing's `|-|` weight [SPEC 15.1] ──

#[test]
fn drawing_links_thin_to_stroke_width_1() {
    let width_of = |src: &str| {
        let l = laid(src);
        let dim_line = l
            .nodes
            .iter()
            .find(|n| n.kind == NodeKind::Line)
            .expect("a dim line");
        match dim_line.attrs.get("stroke-width") {
            Some(ResolvedValue::Number(w)) => *w,
            other => panic!("stroke-width: {other:?}"),
        }
    };
    assert_eq!(
        width_of(
            "{ layout: drawing; density: 1 }\n|rect#a| { width: 40; height: 20 }\na:left (-) a:right\n"
        ),
        1.0,
        "the drawing-scope link default"
    );
    // A scope default, not a rule — a plain `|-|` rule overrides it.
    // And it is the *immediate* scope's default: a flow container nested
    // in a drawing owns ordinary routed links, weight 2.
    let l = laid(
        "|drawing#d| { scale: 0.25 } [\n  |rect#part| { width: 40; height: 20 }\n  |row#legend| { translate: 0 60 } [\n    |box#a| \"a\"\n    |box#b| \"b\"\n    a -> b\n  ]\n]\n",
    );
    let wire = l.links.first().expect("the routed flow link");
    assert!(
        wire.attrs.number("stroke-width").is_none_or(|w| w != 1.0),
        "a nested flow's links keep the flow weight: {:?}",
        wire.attrs.get("stroke-width")
    );
    assert_eq!(
        width_of(
            "{ layout: drawing; scale: 1;\n  |-| { stroke-width: 2 }\n}\n|rect#a| { width: 40; height: 20 }\na:left (-) a:right\n"
        ),
        2.0,
        "a user '|-|' rule wins over the scope default"
    );
}