pdf-untangle 0.3.0

Untangle garbled PDF text: layout-aware extraction that reconstructs reading order, strips page furniture, and splits documents into structured, citable sections
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
569
//! Declarative document-family profiles (TOML). All jurisdiction knowledge is
//! data, not code: adding a new document family means writing a profile.
//!
//! `jurisdiction`, `kind`, and `citation_template` are REQUIRED — the first
//! two are the resolution routing keys downstream databases join on, and the
//! template is the single source of truth for the citation strings this
//! profile emits (signed off with the consuming system before a profile is
//! considered final; see docs/DESIGN.md §3).

use std::path::Path;

use anyhow::{Context, Result};
use serde::Deserialize;

/// Built-in profiles compiled into the crate (name → TOML source).
/// Drafts stay here until their citation template is signed off.
const BUILTINS: &[(&str, &str)] = &[
    ("cnmi-rules", include_str!("../profiles/cnmi-rules.toml")),
    (
        "cnmi-statutes",
        include_str!("../profiles/cnmi-statutes.toml"),
    ),
    (
        "connecticut-practice-book",
        include_str!("../profiles/connecticut-practice-book.toml"),
    ),
    ("guam-gca", include_str!("../profiles/guam-gca.toml")),
    ("guam-rules", include_str!("../profiles/guam-rules.toml")),
    (
        "kentucky-krs",
        include_str!("../profiles/kentucky-krs.toml"),
    ),
    ("maine-rules", include_str!("../profiles/maine-rules.toml")),
    (
        "north-carolina-appellate-rules",
        include_str!("../profiles/north-carolina-appellate-rules.toml"),
    ),
    (
        "north-carolina-general-practice-rules",
        include_str!("../profiles/north-carolina-general-practice-rules.toml"),
    ),
    (
        "north-dakota-century-code",
        include_str!("../profiles/north-dakota-century-code.toml"),
    ),
    ("pr-rules", include_str!("../profiles/pr-rules.toml")),
    (
        "wyoming-statutes",
        include_str!("../profiles/wyoming-statutes.toml"),
    ),
];

/// A document-family profile: how to find provisions in one family of PDFs.
#[derive(Debug, Clone, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct Profile {
    /// Human-readable profile name (matches the file stem for built-ins).
    pub name: String,
    /// Routing key: jurisdiction slug exactly as the consumer stores it
    /// (e.g. "northern_mariana_islands"). A wrong slug silently breaks
    /// downstream resolution, which is why it is declared here as data.
    pub jurisdiction: String,
    /// Routing key: "rule" or "statute".
    pub kind: String,
    /// Citation string template. `{num}` (required) is replaced by the
    /// provision number; `{title}` (optional) by the code title resolved from
    /// [`Profile::title_patterns`] or a `title` capture in a heading pattern
    /// (e.g. `"{title} CMC § {num}"`). No other placeholders exist.
    pub citation_template: String,
    /// DRAFT profiles have not had their citation template signed off yet.
    #[serde(default)]
    pub draft: bool,
    /// BCP-47-ish language tag of the text this family publishes ("en", "es").
    #[serde(default = "default_language")]
    pub language: String,
    /// Regexes that recognize a provision-start heading line. Each must carry
    /// a `num` named capture; `heading` and `title` captures are optional.
    pub heading_patterns: Vec<String>,
    /// Regexes that recognize history/credit lines (feed date parsing).
    #[serde(default)]
    pub history_patterns: Vec<String>,
    /// Date formats to try on history lines, in order (strftime-style).
    #[serde(default)]
    pub date_formats: Vec<String>,
    /// Regexes that start a skipped region (committee notes, TOC, front
    /// matter). A match ends the current provision's text; lines are recorded
    /// as skipped — never lost — until the next accepted provision heading.
    #[serde(default)]
    pub skip_patterns: Vec<String>,
    /// Regexes matched against the FIRST line of each Layer-2 block; a match
    /// skips exactly that block (recorded, never lost). For non-provision
    /// content that interleaves with provision text mid-page — e.g. the
    /// Connecticut Practice Book sets each chapter's section index in a
    /// column beside running body text, where a region skip (which runs to
    /// the next accepted heading) would swallow real provision text.
    #[serde(default)]
    pub skip_block_patterns: Vec<String>,
    /// Stop markers: a match ends provision detection for good. The current
    /// provision is finalized and every remaining line is recorded as
    /// skipped — headings are no longer accepted and history lines no longer
    /// feed the date chain. For trailing back matter (appendices of forms,
    /// renumbering tables, indexes) whose credit lines would otherwise
    /// attach to the document's final provision.
    #[serde(default)]
    pub stop_patterns: Vec<String>,
    /// Regexes that recognize an intentionally-empty document: a whole
    /// chapter/part published as a disposition stub with no sections in it
    /// (North Dakota prints "[Repealed by S.L. 1947, ch. 1, § 18]" under the
    /// chapter heading and nothing else). Scanned over every line, furniture
    /// included, but ONLY when zero provisions were detected: a match marks
    /// the document as a recognized empty document ([`crate::output::Document::empty_doc_marker`])
    /// and `pdf-untangle check` passes instead of failing with "no provisions
    /// detected". A document that yields provisions never consults these.
    #[serde(default)]
    pub empty_doc_patterns: Vec<String>,
    /// Regexes that detect the document-level adoption/effective date, the
    /// middle link of the never-null date chain (parsed history date →
    /// adoption date → sentinel). Scanned over every line, including page
    /// furniture; an optional `date` named capture narrows the text handed to
    /// the date scanner. First parseable hit wins.
    #[serde(default)]
    pub adoption_patterns: Vec<String>,
    /// Static document-level adoption date (`YYYY-MM-DD`), used when
    /// [`Profile::adoption_patterns`] finds nothing.
    #[serde(default)]
    pub adoption_date: Option<String>,
    /// Regexes resolving the `{title}` citation placeholder (first match of a
    /// `title` named capture, scanned over every line including furniture —
    /// running heads like "TITLE 1: GOVERNMENT" are usually where it lives).
    #[serde(default)]
    pub title_patterns: Vec<String>,
    /// Provision numbers that are intentionally absent (reserved), so the
    /// structure-integrity sequence check does not flag them as gaps.
    #[serde(default)]
    pub expected_gaps: Vec<String>,
    /// Require provision numbers to strictly increase: a heading candidate
    /// whose number is not greater than the last accepted one is treated as
    /// body text (rejects TOC entries and in-text cross-references). Disable
    /// for document families whose numbering legitimately restarts.
    #[serde(default = "default_true")]
    pub monotonic_numbers: bool,
    /// Handle a table of contents whose entries are typographically identical
    /// to real provision headings (same text, left edge, and size — Guam GCA
    /// chapters, the consolidated Maine rules). When the FIRST accepted
    /// provision number reappears and `monotonic_numbers` would reject it,
    /// everything accepted so far is reclassified as a skipped
    /// table-of-contents pass and detection restarts at that line, with a
    /// document warning. At most one restart per document, so a later
    /// in-text repeat of the first number cannot discard the real body.
    #[serde(default)]
    pub toc_restart: bool,
    /// Keep only heading candidates near the dominant heading line-start x0
    /// (headings share a left edge; wrapped cross-references sit at body
    /// indents). Applied when three or more candidates exist. Works on every
    /// backend — it keys on `Line::x0`, which is always reliable.
    #[serde(default = "default_true")]
    pub heading_x0_cluster: bool,
    /// Optional style requirements for heading lines. Hints that need
    /// backend-dependent facts degrade gracefully: `bold` is only enforced
    /// when the extraction backend reported bold anywhere in the document.
    #[serde(default)]
    pub heading_style: Option<HeadingStyle>,
}

/// Style hints for heading lines (all optional; see [`Profile::heading_style`]).
#[derive(Debug, Clone, Default, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct HeadingStyle {
    /// Heading lines must be bold. Ignored (with graceful degradation) when
    /// the backend exposes no bold flags at all (the pure backend never does).
    #[serde(default)]
    pub bold: Option<bool>,
    /// Heading lines must (or must not) be centered.
    #[serde(default)]
    pub centered: Option<bool>,
    /// Minimum dominant font size of a heading line, in points.
    #[serde(default)]
    pub min_size: Option<f32>,
    /// Maximum dominant font size of a heading line, in points.
    #[serde(default)]
    pub max_size: Option<f32>,
}

fn default_language() -> String {
    "en".to_string()
}

fn default_true() -> bool {
    true
}

impl Profile {
    /// Parse a profile from TOML source.
    pub fn from_toml(src: &str) -> Result<Self> {
        let p: Profile = toml::from_str(src).context("invalid profile TOML")?;
        p.validate()?;
        Ok(p)
    }

    /// Load a profile from a TOML file on disk.
    pub fn from_path(path: &Path) -> Result<Self> {
        let src = std::fs::read_to_string(path)
            .with_context(|| format!("reading profile {}", path.display()))?;
        Self::from_toml(&src)
    }

    /// Load a built-in profile by name.
    pub fn builtin(name: &str) -> Result<Self> {
        let src = BUILTINS
            .iter()
            .find(|(n, _)| *n == name)
            .map(|(_, s)| *s)
            .with_context(|| {
                format!(
                    "no built-in profile {name:?} (known: {})",
                    builtin_names().join(", ")
                )
            })?;
        Self::from_toml(src)
    }

    fn validate(&self) -> Result<()> {
        anyhow::ensure!(
            !self.jurisdiction.is_empty(),
            "profile: jurisdiction must not be empty"
        );
        anyhow::ensure!(
            self.kind == "rule" || self.kind == "statute",
            "profile: kind must be \"rule\" or \"statute\", got {:?}",
            self.kind
        );
        anyhow::ensure!(
            !self.language.is_empty(),
            "profile: language must not be empty"
        );
        self.validate_template()?;
        anyhow::ensure!(
            !self.heading_patterns.is_empty(),
            "profile: at least one heading pattern is required"
        );
        for pat in &self.heading_patterns {
            let re =
                regex::Regex::new(pat).with_context(|| format!("invalid profile regex {pat:?}"))?;
            anyhow::ensure!(
                re.capture_names().flatten().any(|n| n == "num"),
                "profile: heading pattern {pat:?} lacks the required (?P<num>…) capture"
            );
        }
        for pat in self
            .history_patterns
            .iter()
            .chain(&self.skip_patterns)
            .chain(&self.skip_block_patterns)
            .chain(&self.stop_patterns)
            .chain(&self.empty_doc_patterns)
            .chain(&self.adoption_patterns)
            .chain(&self.title_patterns)
        {
            regex::Regex::new(pat).with_context(|| format!("invalid profile regex {pat:?}"))?;
        }
        for pat in &self.title_patterns {
            let re = regex::Regex::new(pat).expect("validated above");
            anyhow::ensure!(
                re.capture_names().flatten().any(|n| n == "title"),
                "profile: title pattern {pat:?} lacks the required (?P<title>…) capture"
            );
        }
        if let Some(date) = &self.adoption_date {
            chrono::NaiveDate::parse_from_str(date, "%Y-%m-%d").with_context(|| {
                format!("profile: adoption_date {date:?} is not a YYYY-MM-DD date")
            })?;
        }
        // Date formats must derive a finder (see structure::dates).
        crate::structure::dates::DateScanner::new(&self.date_formats)
            .context("profile: date_formats")?;
        Ok(())
    }

    fn validate_template(&self) -> Result<()> {
        anyhow::ensure!(
            self.citation_template.contains("{num}"),
            "profile: citation_template must contain {{num}}"
        );
        let placeholder = regex::Regex::new(r"\{([a-zA-Z_]+)\}").expect("static regex");
        for cap in placeholder.captures_iter(&self.citation_template) {
            let name = &cap[1];
            match name {
                "num" => {}
                "title" => {
                    let heading_has_title = self.heading_patterns.iter().any(|p| {
                        regex::Regex::new(p)
                            .map(|re| re.capture_names().flatten().any(|n| n == "title"))
                            .unwrap_or(false)
                    });
                    anyhow::ensure!(
                        !self.title_patterns.is_empty() || heading_has_title,
                        "profile: citation_template uses {{title}} but the profile declares \
                         no title_patterns and no heading pattern captures (?P<title>…)"
                    );
                }
                other => anyhow::bail!(
                    "profile: citation_template has unknown placeholder {{{other}}} \
                     (only {{num}} and {{title}} exist)"
                ),
            }
        }
        Ok(())
    }
}

/// Names of all built-in profiles.
pub fn builtin_names() -> Vec<&'static str> {
    BUILTINS.iter().map(|(n, _)| *n).collect()
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn builtin_cnmi_rules_parses() {
        let p = Profile::builtin("cnmi-rules").expect("built-in must parse");
        assert_eq!(p.jurisdiction, "northern_mariana_islands");
        assert_eq!(p.kind, "rule");
        assert_eq!(p.language, "en");
        assert!(p.citation_template.contains("{num}"));
        assert!(!p.draft, "template signed off 2026-07-03");
        assert!(p.monotonic_numbers && p.heading_x0_cluster);
    }

    #[test]
    fn builtin_cnmi_statutes_parses() {
        let p = Profile::builtin("cnmi-statutes").expect("built-in must parse");
        assert_eq!(p.jurisdiction, "northern_mariana_islands");
        assert_eq!(p.kind, "statute");
        assert!(p.citation_template.contains("{title}"));
        assert!(
            !p.title_patterns.is_empty(),
            "{{title}} needs a title source"
        );
        assert!(!p.draft, "template signed off 2026-07-03");
    }

    #[test]
    fn unknown_builtin_errors() {
        assert!(Profile::builtin("nope").is_err());
    }

    #[test]
    fn every_builtin_parses_and_is_signed_off() {
        for name in builtin_names() {
            let p = Profile::builtin(name).unwrap_or_else(|e| panic!("{name}: {e:#}"));
            assert_eq!(p.name, name, "profile name must match the builtin key");
            assert!(
                !p.draft,
                "{name}: wave-1 templates were signed off 2026-07-03"
            );
        }
    }

    #[test]
    fn wave1_builtins_carry_the_signed_off_templates() {
        // The templates the resolution engine signed off 2026-07-03 — the
        // one seam where the two halves can drift, so they are pinned
        // byte-for-byte (docs/DESIGN.md §3).
        let expected = [
            ("cnmi-statutes", "{title} CMC § {num}"),
            ("cnmi-rules", "NMI R. Civ. P. {num}"),
            ("guam-gca", "{title} GCA § {num}"),
            ("guam-rules", "Guam R. Civ. P. {num}"),
            ("maine-rules", "M.R. Civ. P. {num}"),
            ("connecticut-practice-book", "Conn. Practice Book § {num}"),
            ("kentucky-krs", "KRS {num}"),
            ("pr-rules", "32 L.P.R.A. Ap. V, R. {num}"),
            ("north-dakota-century-code", "N.D. Cent. Code § {num}"),
            ("wyoming-statutes", "Wyo. Stat. § {num}"),
            ("north-carolina-appellate-rules", "N.C. R. App. P. {num}"),
            (
                "north-carolina-general-practice-rules",
                "N.C. Gen. R. Prac. Super. & Dist. Ct. {num}",
            ),
        ];
        for (name, template) in expected {
            let p = Profile::builtin(name).expect(name);
            assert_eq!(p.citation_template, template, "{name}");
        }
    }

    #[test]
    fn builtin_north_dakota_century_code_parses() {
        let p = Profile::builtin("north-dakota-century-code").expect("built-in must parse");
        assert_eq!(p.jurisdiction, "north_dakota");
        assert_eq!(p.kind, "statute");
        assert_eq!(p.citation_template, "N.D. Cent. Code § {num}");
        assert!(!p.draft);
        // Full title-chapter-section rides in {num}; no {title} placeholder.
        assert!(!p.citation_template.contains("{title}"));
    }

    #[test]
    fn builtin_north_dakota_recognizes_repealed_chapter_stubs() {
        // 602 of the 1529 Century Code chapter PDFs are whole-chapter
        // disposition stubs; the profile must declare them as valid empty
        // documents or a full-code crawl fails on every one.
        let p = Profile::builtin("north-dakota-century-code").unwrap();
        assert!(!p.empty_doc_patterns.is_empty());
        let re = regex::Regex::new(&p.empty_doc_patterns[0]).unwrap();
        // Every disposition shape found in the 2026-07 crawl of all 1529
        // chapter PDFs (602 stubs), including mid-sentence verbs.
        for marker in [
            "[Repealed by S.L. 1947, ch. 1, § 18]",
            "[Repealed by omission from this code]",
            "[Superseded by North Dakota Rules of Civil Procedure, Rule 16]",
            "[Expired under S.L. 2017, ch. 341, § 22]",
            "[Referred and disapproved at election of June 28, 1950]",
            "[Unconstitutional - Scott v. Donnelly, 133 N.W.2d 418]",
            "[Title 26 was repealed and replaced by S.L. 1983,",
            "[Each section of this chapter has been repealed or omitted as not of a general or permanent",
        ] {
            assert!(re.is_match(marker), "must match {marker:?}");
        }
        // Per-section repeals are unbracketed body text — never a marker.
        assert!(!re.is_match("Repealed by S.L. 1985, ch. 103, § 10."));
    }

    #[test]
    fn builtin_wyoming_statutes_parses() {
        let p = Profile::builtin("wyoming-statutes").expect("built-in must parse");
        assert_eq!(p.jurisdiction, "wyoming");
        assert_eq!(p.kind, "statute");
        assert_eq!(p.citation_template, "Wyo. Stat. § {num}");
        assert!(!p.draft);
        assert!(!p.citation_template.contains("{title}"));
    }

    #[test]
    fn builtin_north_carolina_appellate_rules_parses() {
        let p = Profile::builtin("north-carolina-appellate-rules").expect("built-in must parse");
        assert_eq!(p.jurisdiction, "north_carolina");
        assert_eq!(p.kind, "rule");
        assert_eq!(p.citation_template, "N.C. R. App. P. {num}");
        assert!(!p.draft);
        assert!(p.toc_restart, "consolidated TOC mirrors the headings");
        assert!(!p.stop_patterns.is_empty(), "appendixes must not attach");
    }

    #[test]
    fn builtin_north_carolina_general_practice_rules_parses() {
        let p =
            Profile::builtin("north-carolina-general-practice-rules").expect("built-in must parse");
        assert_eq!(p.jurisdiction, "north_carolina");
        assert_eq!(p.kind, "rule");
        assert_eq!(
            p.citation_template,
            "N.C. Gen. R. Prac. Super. & Dist. Ct. {num}"
        );
        assert!(!p.draft);
        assert!(p.toc_restart, "consolidated TOC mirrors the headings");
        assert!(!p.stop_patterns.is_empty(), "forms must not attach");
    }

    #[test]
    fn pr_rules_is_spanish() {
        let p = Profile::builtin("pr-rules").unwrap();
        assert_eq!(p.language, "es");
        assert_eq!(p.jurisdiction, "puerto_rico");
        assert_eq!(p.kind, "rule");
    }

    fn minimal() -> String {
        r#"
name = "x"
jurisdiction = "guam"
kind = "rule"
citation_template = "X {num}"
heading_patterns = ['^RULE (?P<num>\d+)']
"#
        .to_string()
    }

    #[test]
    fn minimal_profile_gets_defaults() {
        let p = Profile::from_toml(&minimal()).unwrap();
        assert_eq!(p.language, "en");
        assert!(p.monotonic_numbers);
        assert!(p.heading_x0_cluster);
        assert!(p.heading_style.is_none());
        assert!(p.adoption_date.is_none());
    }

    #[test]
    fn missing_routing_keys_rejected() {
        let err = Profile::from_toml(&minimal().replace("\"rule\"", "\"regulation\"")).unwrap_err();
        assert!(err.to_string().contains("kind"));
    }

    #[test]
    fn bad_regex_rejected() {
        let err = Profile::from_toml(&minimal().replace(r"^RULE (?P<num>\d+)", "(")).unwrap_err();
        assert!(err.to_string().contains("invalid profile regex"));
    }

    #[test]
    fn heading_pattern_without_num_capture_rejected() {
        let err = Profile::from_toml(&minimal().replace(r"(?P<num>\d+)", r"\d+")).unwrap_err();
        assert!(err.to_string().contains("(?P<num>"));
    }

    #[test]
    fn unknown_template_placeholder_rejected() {
        let err =
            Profile::from_toml(&minimal().replace("X {num}", "X {num} {volume}")).unwrap_err();
        assert!(err.to_string().contains("{volume}"));
    }

    #[test]
    fn title_placeholder_requires_a_title_source() {
        let err = Profile::from_toml(&minimal().replace("X {num}", "{title} X {num}")).unwrap_err();
        assert!(err.to_string().contains("{title}"));

        // With title_patterns declared, the same template is fine.
        let src = format!(
            "{}\ntitle_patterns = ['^TITLE (?P<title>\\d+)']",
            minimal().replace("X {num}", "{title} X {num}")
        );
        Profile::from_toml(&src).expect("title_patterns satisfies {title}");
    }

    #[test]
    fn title_pattern_must_capture_title() {
        let src = format!("{}\ntitle_patterns = ['^TITLE \\d+']", minimal());
        let err = Profile::from_toml(&src).unwrap_err();
        assert!(err.to_string().contains("(?P<title>"));
    }

    #[test]
    fn bad_empty_doc_regex_rejected() {
        let src = format!("{}\nempty_doc_patterns = ['(']", minimal());
        let err = Profile::from_toml(&src).unwrap_err();
        assert!(err.to_string().contains("invalid profile regex"));
    }

    #[test]
    fn malformed_adoption_date_rejected() {
        let src = format!("{}\nadoption_date = \"Feb 13, 2002\"", minimal());
        let err = Profile::from_toml(&src).unwrap_err();
        assert!(err.to_string().contains("YYYY-MM-DD"));
    }

    #[test]
    fn unsupported_date_format_rejected() {
        let src = format!("{}\ndate_formats = [\"%H:%M\"]", minimal());
        let err = Profile::from_toml(&src).unwrap_err();
        assert!(format!("{err:#}").contains("unsupported strftime specifier"));
    }

    #[test]
    fn heading_style_parses() {
        let src = format!(
            "{}\n[heading_style]\nbold = true\nmin_size = 10.5",
            minimal()
        );
        let p = Profile::from_toml(&src).unwrap();
        let style = p.heading_style.expect("style table");
        assert_eq!(style.bold, Some(true));
        assert_eq!(style.min_size, Some(10.5));
        assert!(style.centered.is_none());
    }
}