cuno-tools 0.3.0

cuno fmt and cuno lint (clang-format / clang-tidy).
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
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
//! clang-format's configuration from `[fmt]`
//! (`docs/en/specs/dev-tools.md`, "`[fmt]`").

use std::ffi::OsStr;
use std::fmt;
use std::path::{Path, PathBuf};
use std::sync::Mutex;
use std::sync::atomic::{AtomicUsize, Ordering};

use cuno_core::{CunoError, Env, ExitClass};
use cuno_manifest::{Fmt, FmtStyle, Lang};
use cuno_toolchain::Runner;

/// clang-format, and what it is run with.
pub struct ClangFormat<'a> {
    /// The executable selection chose.
    pub program: &'a Path,
    /// The `.clang-format` to format with, whatever is at the root.
    pub style: &'a Path,
    /// The environment it runs in.
    pub env: &'a Env,
    /// How many files at once.
    pub jobs: usize,
}

/// A file clang-format could not format, or cuno could not read or write.
#[derive(Debug)]
pub struct FormatError {
    /// The file.
    pub file: PathBuf,
    /// What went wrong: clang-format's own message, or the I/O error.
    pub reason: String,
}

impl fmt::Display for FormatError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(
            f,
            "could not format {}: {}",
            self.file.display(),
            self.reason
        )
    }
}

impl std::error::Error for FormatError {}

impl CunoError for FormatError {
    fn exit_class(&self) -> ExitClass {
        ExitClass::Failure
    }
}

/// clang-format refused the configuration written from `[fmt]`: a
/// settings problem, not one in the code.
#[derive(Debug)]
pub struct StyleRefused {
    /// What clang-format said, with the scratch file's path left out.
    pub reason: String,
}

impl fmt::Display for StyleRefused {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(
            f,
            "clang-format refuses the configuration from [fmt] in Cuno.toml: {}",
            self.reason
        )
    }
}

impl std::error::Error for StyleRefused {}

impl CunoError for StyleRefused {
    fn exit_class(&self) -> ExitClass {
        ExitClass::Setup
    }

    fn help(&self) -> Option<String> {
        Some("correct [fmt.clang-format] in Cuno.toml".to_owned())
    }
}

/// Whether clang-format reads `tool`'s configuration, before any file is
/// formatted with it, so a key it does not know is reported as the
/// settings' problem rather than as the first file's.
pub fn check_style(tool: &ClangFormat<'_>, runner: &dyn Runner) -> Result<(), StyleRefused> {
    let style = format!("--style=file:{}", tool.style.display());
    let args: [&OsStr; 2] = ["--dump-config".as_ref(), style.as_ref()];
    let output = runner
        .run(tool.program, &args, tool.env)
        .map_err(|e| StyleRefused {
            reason: e.to_string(),
        })?;
    if output.success {
        return Ok(());
    }
    let said = String::from_utf8_lossy(&output.stderr);
    let shown = tool.style.display().to_string();
    let reason = said
        .lines()
        .find(|line| line.contains("error:"))
        .unwrap_or(said.trim())
        .replace(&format!("{shown}:"), "line ")
        .replace(&shown, "the configuration");
    Err(StyleRefused { reason })
}

/// What formatting found: the files whose formatting differs (rewritten
/// unless `check`), and those that could not be formatted, each in the
/// order given.
#[derive(Debug, Default)]
pub struct Formatted {
    /// Differed, and were rewritten unless `check`.
    pub changed: Vec<PathBuf>,
    /// Could not be formatted; left as they were.
    pub failed: Vec<FormatError>,
}

/// Formats `files` with `tool`: each is run through clang-format and
/// compared with what it holds; one that differs is rewritten unless
/// `check` (`docs/en/specs/commands.md`, "`cuno fmt`"). A file is never
/// rewritten with empty output, nor when it changed while clang-format
/// ran, and is replaced whole, never truncated in place.
pub fn format(
    files: &[PathBuf],
    tool: &ClangFormat<'_>,
    check: bool,
    runner: &(dyn Runner + Sync),
) -> Formatted {
    let next = AtomicUsize::new(0);
    let results: Mutex<Vec<(usize, Result<bool, FormatError>)>> = Mutex::new(Vec::new());
    std::thread::scope(|scope| {
        for _ in 0..tool.jobs.clamp(1, files.len().max(1)) {
            scope.spawn(|| {
                loop {
                    let i = next.fetch_add(1, Ordering::SeqCst);
                    let Some(file) = files.get(i) else { break };
                    let result = format_one(file, tool, check, runner);
                    results.lock().unwrap().push((i, result));
                }
            });
        }
    });
    let mut results = results.into_inner().unwrap();
    results.sort_by_key(|(i, _)| *i);
    let mut formatted = Formatted::default();
    for (i, result) in results {
        match result {
            Ok(true) => formatted.changed.push(files[i].clone()),
            Ok(false) => {}
            Err(e) => formatted.failed.push(e),
        }
    }
    formatted
}

/// Whether `file` differs from its formatting, writing it unless `check`.
fn format_one(
    file: &Path,
    tool: &ClangFormat<'_>,
    check: bool,
    runner: &(dyn Runner + Sync),
) -> Result<bool, FormatError> {
    let failed = |reason: String| FormatError {
        file: file.to_owned(),
        reason,
    };
    let held = std::fs::read(file).map_err(|e| failed(e.to_string()))?;
    let style = format!("--style=file:{}", tool.style.display());
    let args: [&OsStr; 2] = [style.as_ref(), file.as_os_str()];
    let output = runner
        .run(tool.program, &args, tool.env)
        .map_err(|e| failed(e.to_string()))?;
    if !output.success {
        let said = String::from_utf8_lossy(&output.stderr).trim().to_owned();
        return Err(failed(if said.is_empty() {
            "clang-format failed and said nothing".to_owned()
        } else {
            said
        }));
    }
    if output.stdout == held {
        return Ok(false);
    }
    // Formatting never empties a file; a clang-format that printed nothing
    // failed without saying so, and its output would erase the source.
    if output.stdout.is_empty() {
        return Err(failed("clang-format printed nothing for it".to_owned()));
    }
    if !check {
        replace(file, &held, &output.stdout).map_err(failed)?;
    }
    Ok(true)
}

/// Replaces `file`, which held `held` when it was read, with `content`:
/// written beside it and renamed over it, so the file is never left
/// half-written; not at all when it has changed since, so an edit made
/// meanwhile is not lost.
fn replace(file: &Path, held: &[u8], content: &[u8]) -> Result<(), String> {
    let mut beside = file.as_os_str().to_owned();
    beside.push(format!(".cuno-fmt-{}", std::process::id()));
    let beside = PathBuf::from(beside);
    std::fs::write(&beside, content).map_err(|e| e.to_string())?;
    let now = std::fs::read(file).map_err(|e| e.to_string());
    let result = match now {
        Ok(now) if now != held => {
            Err("it changed while it was being formatted; run cuno fmt again".to_owned())
        }
        Ok(_) => std::fs::rename(&beside, file).map_err(|e| e.to_string()),
        Err(e) => Err(e),
    };
    if result.is_err() {
        let _ = std::fs::remove_file(&beside);
    }
    result
}

/// The file editors read, at the project root.
pub const FILE: &str = ".clang-format";

/// The first line of every `.clang-format` cuno writes: a file that does
/// not start with it is the user's, and is not overwritten
/// (`docs/en/specs/dev-tools.md`, "Configuration").
pub const MARKER: &str =
    "# Generated by cuno from [fmt] in Cuno.toml, and overwritten: edit Cuno.toml instead.";

/// `.clang-format` for `fmt` in a package of `lang`. One section with no
/// `Language` key, so every file takes it: every file is styled in the
/// package's language (`dev-tools.md`, "Target files"). A key written in
/// `[fmt.clang-format]` replaces cuno's own, since clang-format refuses a
/// key given twice.
pub fn clang_format_config(fmt: &Fmt, lang: Lang) -> String {
    let mut keys: Vec<(&str, String)> = Vec::new();
    match fmt.style {
        FmtStyle::Cuno => {
            keys.push(("BasedOnStyle", "LLVM".to_owned()));
            keys.push(("IndentWidth", "4".to_owned()));
            keys.push(("ColumnLimit", "100".to_owned()));
            keys.push(("BreakBeforeBraces", "Attach".to_owned()));
            let pointers = match lang {
                Lang::C => "Right",
                Lang::Cxx => "Left",
            };
            keys.push(("PointerAlignment", pointers.to_owned()));
            keys.push(("DerivePointerAlignment", "false".to_owned()));
            keys.push(("SortIncludes", "CaseSensitive".to_owned()));
            // A blank line keeps headers whose order matters apart.
            keys.push(("IncludeBlocks", "Preserve".to_owned()));
        }
        other => keys.push(("BasedOnStyle", based_on(other).to_owned())),
    }
    if let Some(width) = fmt.indent_width {
        set(&mut keys, "IndentWidth", width.to_string());
    }
    if let Some(limit) = fmt.column_limit {
        set(&mut keys, "ColumnLimit", limit.to_string());
    }
    if let Some(tabs) = fmt.use_tabs {
        set(
            &mut keys,
            "UseTab",
            if tabs { "ForIndentation" } else { "Never" }.to_owned(),
        );
        // A tab as wide as one level, or levels mix tabs and spaces: the
        // indent written last, `[fmt.clang-format]`'s, wins.
        if tabs {
            let width = match fmt.clang_format.get("IndentWidth") {
                Some(toml::Value::Integer(width)) => width.to_string(),
                _ => fmt
                    .indent_width
                    .unwrap_or_else(|| style_indent(fmt.style))
                    .to_string(),
            };
            set(&mut keys, "TabWidth", width);
        }
    }
    keys.retain(|(k, _)| !fmt.clang_format.contains_key(*k));
    let mut text = format!("{MARKER}\n");
    for (key, value) in keys {
        text.push_str(&format!("{key}: {value}\n"));
    }
    for (key, value) in &fmt.clang_format {
        text.push_str(&format!("{key}: {}\n", flow(value)));
    }
    text
}

/// Sets `key` to `value`, in place of any earlier value.
fn set(keys: &mut Vec<(&str, String)>, key: &'static str, value: String) {
    keys.retain(|(k, _)| *k != key);
    keys.push((key, value));
}

/// A base style's own indent width, which a tab has to match.
fn style_indent(style: FmtStyle) -> u32 {
    match style {
        FmtStyle::Cuno | FmtStyle::Microsoft | FmtStyle::Webkit => 4,
        FmtStyle::Llvm
        | FmtStyle::Google
        | FmtStyle::Mozilla
        | FmtStyle::Chromium
        | FmtStyle::Gnu => 2,
    }
}

/// clang-format's name for a base style.
fn based_on(style: FmtStyle) -> &'static str {
    // A match, so a new style has to say what clang-format calls it.
    match style {
        FmtStyle::Cuno | FmtStyle::Llvm => "LLVM",
        FmtStyle::Google => "Google",
        FmtStyle::Microsoft => "Microsoft",
        FmtStyle::Mozilla => "Mozilla",
        FmtStyle::Webkit => "WebKit",
        FmtStyle::Chromium => "Chromium",
        FmtStyle::Gnu => "GNU",
    }
}

/// A TOML value as YAML flow syntax, which clang-format reads.
fn flow(value: &toml::Value) -> String {
    match value {
        toml::Value::String(s) => format!("'{}'", s.replace('\'', "''")),
        toml::Value::Integer(i) => i.to_string(),
        toml::Value::Float(f) => f.to_string(),
        toml::Value::Boolean(b) => b.to_string(),
        toml::Value::Datetime(d) => format!("'{d}'"),
        toml::Value::Array(items) => {
            let items: Vec<String> = items.iter().map(flow).collect();
            format!("[{}]", items.join(", "))
        }
        toml::Value::Table(table) => {
            let entries: Vec<String> = table
                .iter()
                .map(|(k, v)| format!("{k}: {}", flow(v)))
                .collect();
            format!("{{{}}}", entries.join(", "))
        }
    }
}

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

    fn fmt(extra: &str) -> Fmt {
        let toml = format!("[package]\nname = \"app\"\nversion = \"0.1.0\"\n{extra}");
        let root = std::path::Path::new("/p");
        cuno_manifest::parse_manifest(&toml, &root.join("Cuno.toml"), root)
            .unwrap()
            .value
            .fmt
    }

    /// A clang-format that answers each file as `answer` says: its output,
    /// or `None` to fail; `during` runs while it "formats".
    struct Fake<'a> {
        answer: &'a (dyn Fn(&Path) -> Option<Vec<u8>> + Sync),
        during: &'a (dyn Fn(&Path) + Sync),
    }

    impl Runner for Fake<'_> {
        fn run(
            &self,
            _program: &Path,
            args: &[&OsStr],
            _env: &Env,
        ) -> std::io::Result<cuno_toolchain::Output> {
            let file = Path::new(args[1]);
            (self.during)(file);
            Ok(match (self.answer)(file) {
                Some(stdout) => cuno_toolchain::Output {
                    success: true,
                    stdout,
                    stderr: Vec::new(),
                },
                None => cuno_toolchain::Output {
                    success: false,
                    stdout: Vec::new(),
                    stderr: b"boom".to_vec(),
                },
            })
        }
    }

    fn run_fake(files: &[PathBuf], fake: &Fake<'_>, check: bool) -> Formatted {
        let env = Env::from_pairs([], cuno_core::NameCase::Insensitive);
        let tool = ClangFormat {
            program: Path::new("clang-format"),
            style: Path::new("style"),
            env: &env,
            jobs: 4,
        };
        format(files, &tool, check, fake)
    }

    /// Every file that fails is reported and left as it was; the others
    /// are still formatted; an unchanged file is not counted, and `check`
    /// writes nothing.
    ///
    /// Mutation: stop at the first failure, count an unchanged file, or
    /// write under `check`; this test fails.
    #[test]
    fn failures_are_collected_and_the_rest_formatted() {
        let dir = tempfile::tempdir().unwrap();
        let files: Vec<PathBuf> = ["a.c", "bad1.c", "b.c", "bad2.c", "same.c"]
            .iter()
            .map(|n| dir.path().join(n))
            .collect();
        for f in &files {
            std::fs::write(f, "x\n").unwrap();
        }
        let answer = |f: &Path| {
            let name = f.file_name().unwrap().to_str().unwrap();
            match name {
                n if n.starts_with("bad") => None,
                "same.c" => Some(b"x\n".to_vec()),
                _ => Some(b"y\n".to_vec()),
            }
        };
        let nothing = |_: &Path| {};
        let fake = Fake {
            answer: &answer,
            during: &nothing,
        };
        let checked = run_fake(&files, &fake, true);
        assert_eq!(checked.changed, [files[0].clone(), files[2].clone()]);
        assert_eq!(std::fs::read_to_string(&files[0]).unwrap(), "x\n");
        let done = run_fake(&files, &fake, false);
        assert_eq!(done.changed, [files[0].clone(), files[2].clone()]);
        assert_eq!(
            done.failed
                .iter()
                .map(|e| e.file.clone())
                .collect::<Vec<_>>(),
            [files[1].clone(), files[3].clone()]
        );
        assert_eq!(std::fs::read_to_string(&files[0]).unwrap(), "y\n");
        assert_eq!(std::fs::read_to_string(&files[1]).unwrap(), "x\n");
        let left: Vec<_> = std::fs::read_dir(dir.path()).unwrap().collect();
        assert_eq!(left.len(), files.len(), "no file left beside");
    }

    /// A source is not rewritten with empty output, nor when it changed
    /// while clang-format ran: either would lose the user's code.
    ///
    /// Mutation: write empty output, or write without reading the file
    /// again; this test fails.
    #[test]
    fn a_source_is_never_lost() {
        let dir = tempfile::tempdir().unwrap();
        let file = dir.path().join("a.c");
        std::fs::write(&file, "int  x;\n").unwrap();
        let empty = |_: &Path| Some(Vec::new());
        let nothing = |_: &Path| {};
        let done = run_fake(
            std::slice::from_ref(&file),
            &Fake {
                answer: &empty,
                during: &nothing,
            },
            false,
        );
        assert_eq!(done.failed.len(), 1);
        assert_eq!(std::fs::read_to_string(&file).unwrap(), "int  x;\n");

        let tidy = |_: &Path| Some(b"int x;\n".to_vec());
        let edit = |f: &Path| std::fs::write(f, "int  x; // mine\n").unwrap();
        let done = run_fake(
            std::slice::from_ref(&file),
            &Fake {
                answer: &tidy,
                during: &edit,
            },
            false,
        );
        assert!(
            done.failed[0].reason.contains("changed while"),
            "{:?}",
            done.failed
        );
        assert_eq!(std::fs::read_to_string(&file).unwrap(), "int  x; // mine\n");
    }

    fn lines(text: &str) -> Vec<&str> {
        text.lines().filter(|l| !l.starts_with('#')).collect()
    }

    /// The cuno style is LLVM with the spec's indent, width, braces and
    /// include sorting, and each language's pointer side
    /// (`dev-tools.md`, the section on the cuno default style).
    ///
    /// Mutation: drop or change any of these keys, or give C the C++
    /// pointer side; this test fails.
    #[test]
    fn the_cuno_style_is_the_spec_s() {
        let cxx = clang_format_config(&fmt(""), Lang::Cxx);
        assert_eq!(
            lines(&cxx),
            [
                "BasedOnStyle: LLVM",
                "IndentWidth: 4",
                "ColumnLimit: 100",
                "BreakBeforeBraces: Attach",
                "PointerAlignment: Left",
                "DerivePointerAlignment: false",
                "SortIncludes: CaseSensitive",
                "IncludeBlocks: Preserve",
            ]
        );
        let c = clang_format_config(&fmt(""), Lang::C);
        assert!(lines(&c).contains(&"PointerAlignment: Right"), "{c}");
        assert!(cxx.starts_with("# Generated by cuno"), "{cxx}");
    }

    /// Every other style is clang-format's own, by its name.
    ///
    /// Mutation: map a style to another name; this test fails.
    #[test]
    fn a_named_style_is_clang_format_s() {
        for (style, name) in [
            ("llvm", "LLVM"),
            ("google", "Google"),
            ("microsoft", "Microsoft"),
            ("mozilla", "Mozilla"),
            ("webkit", "WebKit"),
            ("chromium", "Chromium"),
            ("gnu", "GNU"),
        ] {
            let text =
                clang_format_config(&fmt(&format!("[fmt]\nstyle = \"{style}\"\n")), Lang::Cxx);
            assert_eq!(
                lines(&text),
                [format!("BasedOnStyle: {name}").as_str()],
                "{style}"
            );
        }
    }

    /// `indent-width`, `column-limit` and `use-tabs` replace the style's
    /// values only when written; tabs are as wide as the indent.
    ///
    /// Mutation: drop a key, write it twice, or leave `TabWidth` out; this
    /// test fails.
    #[test]
    fn written_keys_replace_the_style_s() {
        let text = clang_format_config(
            &fmt("[fmt]\nindent-width = 3\ncolumn-limit = 90\nuse-tabs = true\n"),
            Lang::Cxx,
        );
        let l = lines(&text);
        for key in [
            "IndentWidth: 3",
            "ColumnLimit: 90",
            "UseTab: ForIndentation",
            "TabWidth: 3",
        ] {
            assert_eq!(l.iter().filter(|x| **x == key).count(), 1, "{key}: {text}");
        }
        assert!(!text.contains("IndentWidth: 4"), "{text}");
        let spaces = clang_format_config(
            &fmt("[fmt]\nstyle = \"google\"\nuse-tabs = false\n"),
            Lang::Cxx,
        );
        assert_eq!(lines(&spaces), ["BasedOnStyle: Google", "UseTab: Never"]);
    }

    /// With tabs on, a tab is one level wide whatever sets the level: a
    /// named style's own indent, or `[fmt.clang-format]`'s.
    ///
    /// Mutation: leave `TabWidth` out without `indent-width`, or take it
    /// from cuno's indent when `[fmt.clang-format]` sets another; this test
    /// fails.
    #[test]
    fn a_tab_is_one_level_wide() {
        for (style, width) in [("webkit", "4"), ("google", "2"), ("microsoft", "4")] {
            let text = clang_format_config(
                &fmt(&format!("[fmt]\nstyle = \"{style}\"\nuse-tabs = true\n")),
                Lang::Cxx,
            );
            assert!(
                lines(&text).contains(&format!("TabWidth: {width}").as_str()),
                "{text}"
            );
        }
        let text = clang_format_config(
            &fmt("[fmt]\nuse-tabs = true\n[fmt.clang-format]\nIndentWidth = 2\n"),
            Lang::Cxx,
        );
        assert!(lines(&text).contains(&"TabWidth: 2"), "{text}");
    }

    /// `[fmt.clang-format]` is passed as written, in YAML flow syntax, and
    /// replaces a key cuno would have written, which clang-format would
    /// refuse twice.
    ///
    /// Mutation: keep cuno's key beside the user's, or quote a value
    /// wrongly; this test fails.
    #[test]
    fn the_escape_hatch_replaces_cuno_s_keys() {
        let text = clang_format_config(
            &fmt(
                "[fmt.clang-format]\nPointerAlignment = \"Right\"\nIndentCaseLabels = true\n\
                 BraceWrapping = { AfterFunction = true }\nMacros = [\"A=x\", \"it's\"]\n",
            ),
            Lang::Cxx,
        );
        let l = lines(&text);
        assert_eq!(
            l.iter()
                .filter(|x| x.starts_with("PointerAlignment"))
                .count(),
            1
        );
        assert!(l.contains(&"PointerAlignment: 'Right'"), "{text}");
        assert!(l.contains(&"IndentCaseLabels: true"), "{text}");
        assert!(
            l.contains(&"BraceWrapping: {AfterFunction: true}"),
            "{text}"
        );
        assert!(l.contains(&"Macros: ['A=x', 'it''s']"), "{text}");
    }
}