gilt 0.5.0

A fast, rich terminal formatting library — Rust port of Python's rich
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
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
//! Box-drawing character sets for tables.
//!
//! Port of Python `rich/box.py`. Defines 19 built-in box styles for rendering
//! table borders and separators.

use std::sync::LazyLock;

/// Which level of row separator to render.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum RowLevel {
    /// Separator below the header row.
    Head,
    /// Separator between body rows.
    Row,
    /// Separator above the footer row.
    Foot,
    /// Mid-level separator (between header and body when there's a distinct mid section).
    Mid,
}

/// A set of box-drawing characters for rendering table borders.
///
/// Parsed from an 8-line definition string where each line has exactly 4 characters:
///
/// ```text
/// Line 1 (top):      top_left, top, top_divider, top_right
/// Line 2 (head):     head_left, _, head_vertical, head_right
/// Line 3 (head_row): head_row_left, head_row_horizontal, head_row_cross, head_row_right
/// Line 4 (mid):      mid_left, _, mid_vertical, mid_right
/// Line 5 (row):      row_left, row_horizontal, row_cross, row_right
/// Line 6 (foot_row): foot_row_left, foot_row_horizontal, foot_row_cross, foot_row_right
/// Line 7 (foot):     foot_left, _, foot_vertical, foot_right
/// Line 8 (bottom):   bottom_left, bottom_char, bottom_divider, bottom_right
/// ```
#[derive(Debug, Clone)]
pub struct BoxChars {
    /// Top-left corner character (e.g. `┌`).
    pub top_left: char,
    /// Top border horizontal fill character (e.g. `─`).
    pub top: char,
    /// Top border column divider character (e.g. `┬`).
    pub top_divider: char,
    /// Top-right corner character (e.g. `┐`).
    pub top_right: char,

    /// Left border character for the header row (e.g. `│`).
    pub head_left: char,
    /// Vertical column divider in the header row (e.g. `│`).
    pub head_vertical: char,
    /// Right border character for the header row (e.g. `│`).
    pub head_right: char,

    /// Left border character for the header separator (e.g. `├`).
    pub head_row_left: char,
    /// Horizontal fill character for the header separator (e.g. `─`).
    pub head_row_horizontal: char,
    /// Cross/intersection character for the header separator (e.g. `┼`).
    pub head_row_cross: char,
    /// Right border character for the header separator (e.g. `┤`).
    pub head_row_right: char,

    /// Left border character for the mid separator (e.g. `│`).
    pub mid_left: char,
    /// Vertical column divider for the mid separator (e.g. `│`).
    pub mid_vertical: char,
    /// Right border character for the mid separator (e.g. `│`).
    pub mid_right: char,

    /// Left border character for body row separators (e.g. `├`).
    pub row_left: char,
    /// Horizontal fill character for body row separators (e.g. `─`).
    pub row_horizontal: char,
    /// Cross/intersection character for body row separators (e.g. `┼`).
    pub row_cross: char,
    /// Right border character for body row separators (e.g. `┤`).
    pub row_right: char,

    /// Left border character for the footer separator (e.g. `├`).
    pub foot_row_left: char,
    /// Horizontal fill character for the footer separator (e.g. `─`).
    pub foot_row_horizontal: char,
    /// Cross/intersection character for the footer separator (e.g. `┼`).
    pub foot_row_cross: char,
    /// Right border character for the footer separator (e.g. `┤`).
    pub foot_row_right: char,

    /// Left border character for the footer row (e.g. `│`).
    pub foot_left: char,
    /// Vertical column divider in the footer row (e.g. `│`).
    pub foot_vertical: char,
    /// Right border character for the footer row (e.g. `│`).
    pub foot_right: char,

    /// Bottom-left corner character (e.g. `└`).
    pub bottom_left: char,
    /// Bottom border horizontal fill character (e.g. `─`).
    pub bottom_char: char,
    /// Bottom border column divider character (e.g. `┴`).
    pub bottom_divider: char,
    /// Bottom-right corner character (e.g. `┘`).
    pub bottom_right: char,

    /// Whether this box uses only ASCII characters.
    pub ascii: bool,
}

impl BoxChars {
    /// Parse a box definition string into a `BoxChars`.
    ///
    /// The string must contain 8 lines separated by `\n`, each with exactly 4 characters.
    ///
    /// # Panics
    ///
    /// Panics if the string does not have exactly 8 lines or any line does not have
    /// exactly 4 characters.
    pub fn new(box_str: &str, ascii: bool) -> Self {
        let lines: Vec<&str> = box_str.split('\n').collect();
        assert_eq!(lines.len(), 8, "Box string must have exactly 8 lines");

        let parse_line = |line: &str| -> Vec<char> {
            let chars: Vec<char> = line.chars().collect();
            assert_eq!(
                chars.len(),
                4,
                "Each box line must have exactly 4 characters, got {} in {:?}",
                chars.len(),
                line,
            );
            chars
        };

        let top = parse_line(lines[0]);
        let head = parse_line(lines[1]);
        let head_row = parse_line(lines[2]);
        let mid = parse_line(lines[3]);
        let row = parse_line(lines[4]);
        let foot_row = parse_line(lines[5]);
        let foot = parse_line(lines[6]);
        let bottom = parse_line(lines[7]);

        Self {
            top_left: top[0],
            top: top[1],
            top_divider: top[2],
            top_right: top[3],

            head_left: head[0],
            head_vertical: head[2],
            head_right: head[3],

            head_row_left: head_row[0],
            head_row_horizontal: head_row[1],
            head_row_cross: head_row[2],
            head_row_right: head_row[3],

            mid_left: mid[0],
            mid_vertical: mid[2],
            mid_right: mid[3],

            row_left: row[0],
            row_horizontal: row[1],
            row_cross: row[2],
            row_right: row[3],

            foot_row_left: foot_row[0],
            foot_row_horizontal: foot_row[1],
            foot_row_cross: foot_row[2],
            foot_row_right: foot_row[3],

            foot_left: foot[0],
            foot_vertical: foot[2],
            foot_right: foot[3],

            bottom_left: bottom[0],
            bottom_char: bottom[1],
            bottom_divider: bottom[2],
            bottom_right: bottom[3],

            ascii,
        }
    }

    /// Build the top border string for columns of given widths.
    ///
    /// Example for widths `[5, 3]` with SQUARE box:
    /// `"┌─────┬───┐"`
    pub fn get_top(&self, widths: &[usize]) -> String {
        let mut s = String::new();
        s.push(self.top_left);
        for (i, &width) in widths.iter().enumerate() {
            for _ in 0..width {
                s.push(self.top);
            }
            if i < widths.len() - 1 {
                s.push(self.top_divider);
            }
        }
        s.push(self.top_right);
        s
    }

    /// Build a row separator string for columns of given widths.
    ///
    /// `level` determines which set of characters to use.
    /// If `edge` is false, the left and right border characters are omitted.
    pub fn get_row(&self, widths: &[usize], level: RowLevel, edge: bool) -> String {
        let (left, horizontal, cross, right) = match level {
            RowLevel::Head => (
                self.head_row_left,
                self.head_row_horizontal,
                self.head_row_cross,
                self.head_row_right,
            ),
            RowLevel::Row => (
                self.row_left,
                self.row_horizontal,
                self.row_cross,
                self.row_right,
            ),
            RowLevel::Foot => (
                self.foot_row_left,
                self.foot_row_horizontal,
                self.foot_row_cross,
                self.foot_row_right,
            ),
            RowLevel::Mid => (
                self.mid_left,
                self.row_horizontal,
                self.mid_vertical,
                self.mid_right,
            ),
        };

        let mut s = String::new();
        if edge {
            s.push(left);
        }
        for (i, &width) in widths.iter().enumerate() {
            for _ in 0..width {
                s.push(horizontal);
            }
            if i < widths.len() - 1 {
                s.push(cross);
            }
        }
        if edge {
            s.push(right);
        }
        s
    }

    /// Build the bottom border string for columns of given widths.
    ///
    /// Example for widths `[5, 3]` with SQUARE box:
    /// `"└─────┴───┘"`
    pub fn get_bottom(&self, widths: &[usize]) -> String {
        let mut s = String::new();
        s.push(self.bottom_left);
        for (i, &width) in widths.iter().enumerate() {
            for _ in 0..width {
                s.push(self.bottom_char);
            }
            if i < widths.len() - 1 {
                s.push(self.bottom_divider);
            }
        }
        s.push(self.bottom_right);
        s
    }

    /// Return a reference to an ASCII-compatible box if `ascii_only` is true and this
    /// box is not already ASCII.
    ///
    /// Specific substitutions:
    /// - ROUNDED -> SQUARE (not truly ASCII, but a simpler fallback)
    /// - MINIMAL_HEAVY_HEAD -> MINIMAL
    /// - SIMPLE_HEAVY -> SIMPLE
    /// - HEAVY -> SQUARE
    /// - HEAVY_EDGE -> SQUARE
    /// - HEAVY_HEAD -> SQUARE
    ///
    /// If no specific substitution is found, returns `self`.
    pub fn substitute(&self, ascii_only: bool) -> &BoxChars {
        if !ascii_only {
            return self;
        }
        // We can identify boxes by comparing top_left char
        // For a more robust approach, we compare the full character set
        // by using the top-left + head_row_horizontal as a fingerprint.
        //
        // This uses pointer equality with the statics or character matching.
        // Since we can't easily do pointer comparison with Lazy, we match on characters.
        match (self.top_left, self.head_row_horizontal) {
            // ROUNDED: top_left='╭', head_row_horizontal='─'
            ('\u{256D}', '\u{2500}') => &SQUARE,
            // MINIMAL_HEAVY_HEAD: top_left=' ', head_row_horizontal='━'
            // Distinguish from SIMPLE_HEAVY by checking head_row_cross
            (' ', '\u{2501}') => {
                if self.head_row_cross == '\u{253F}' {
                    // MINIMAL_HEAVY_HEAD: cross='┿'
                    &MINIMAL
                } else {
                    // SIMPLE_HEAVY: cross='━'
                    &SIMPLE
                }
            }
            // HEAVY: top_left='┏', head_row_horizontal='━'
            ('\u{250F}', '\u{2501}') => {
                // Matches HEAVY (cross='╋') and HEAVY_HEAD (cross='╇')
                &SQUARE
            }
            // HEAVY_EDGE: top_left='┏', head_row_horizontal='─'
            ('\u{250F}', '\u{2500}') => &SQUARE,
            _ => self,
        }
    }

    /// Return a plain-headed variant of this box style.
    ///
    /// Replaces double/heavy header separators with single-line equivalents:
    /// - HEAVY_HEAD -> SQUARE
    /// - SQUARE_DOUBLE_HEAD -> SQUARE
    /// - MINIMAL_DOUBLE_HEAD -> MINIMAL
    /// - MINIMAL_HEAVY_HEAD -> MINIMAL
    /// - ASCII_DOUBLE_HEAD -> ASCII2
    pub fn get_plain_headed_box(&self) -> &BoxChars {
        match (self.top_left, self.head_row_horizontal) {
            // HEAVY_HEAD: top_left='┏', head_row_horizontal='━', cross='╇'
            ('\u{250F}', '\u{2501}') if self.head_row_cross == '\u{2547}' => &SQUARE,
            // SQUARE_DOUBLE_HEAD: top_left='┌', head_row_horizontal='═'
            ('\u{250C}', '\u{2550}') => &SQUARE,
            // MINIMAL_DOUBLE_HEAD: top_left=' ', head_row_horizontal='═'
            (' ', '\u{2550}') => &MINIMAL,
            // MINIMAL_HEAVY_HEAD: top_left=' ', head_row_horizontal='━', cross='┿'
            (' ', '\u{2501}') if self.head_row_cross == '\u{253F}' => &MINIMAL,
            // ASCII_DOUBLE_HEAD: top_left='+', head_row_horizontal='='
            ('+', '=') => &ASCII2,
            _ => self,
        }
    }
}

// ──────────────────────────────────────────────────────────
// Box constant definitions
// ──────────────────────────────────────────────────────────

/// ASCII box style using `+`, `-`, and `|` characters.
pub static ASCII: LazyLock<BoxChars> =
    LazyLock::new(|| BoxChars::new("+--+\n| ||\n|-+|\n| ||\n|-+|\n|-+|\n| ||\n+--+", true));

/// Alternate ASCII box style with `+` at every intersection.
pub static ASCII2: LazyLock<BoxChars> =
    LazyLock::new(|| BoxChars::new("+-++\n| ||\n+-++\n| ||\n+-++\n+-++\n| ||\n+-++", true));

/// ASCII box style with `=` for the header separator row.
pub static ASCII_DOUBLE_HEAD: LazyLock<BoxChars> =
    LazyLock::new(|| BoxChars::new("+-++\n| ||\n+=++\n| ||\n+-++\n+-++\n| ||\n+-++", true));

/// Standard single-line Unicode box style (`┌─┬┐`, `│`, `└─┴┘`).
pub static SQUARE: LazyLock<BoxChars> =
    LazyLock::new(|| BoxChars::new("┌─┬┐\n│ ││\n├─┼┤\n│ ││\n├─┼┤\n├─┼┤\n│ ││\n└─┴┘", false));

/// Single-line Unicode box with a double-line header separator (`╞═╪╡`).
pub static SQUARE_DOUBLE_HEAD: LazyLock<BoxChars> =
    LazyLock::new(|| BoxChars::new("┌─┬┐\n│ ││\n╞═╪╡\n│ ││\n├─┼┤\n├─┼┤\n│ ││\n└─┴┘", false));

/// Minimal box style with no outer borders, only column dividers and row separators.
pub static MINIMAL: LazyLock<BoxChars> =
    LazyLock::new(|| BoxChars::new("\n\n╶─┼╴\n\n╶─┼╴\n╶─┼╴\n\n", false));

/// Minimal box style with a heavy (thick) header separator (`╺━┿╸`).
pub static MINIMAL_HEAVY_HEAD: LazyLock<BoxChars> =
    LazyLock::new(|| BoxChars::new("\n\n╺━┿╸\n\n╶─┼╴\n╶─┼╴\n\n", false));

/// Minimal box style with a double-line header separator (`═╪`).
pub static MINIMAL_DOUBLE_HEAD: LazyLock<BoxChars> =
    LazyLock::new(|| BoxChars::new("\n\n ═╪ \n\n ─┼ \n ─┼ \n\n", false));

/// Simple box style with only horizontal rules for header and footer separators.
pub static SIMPLE: LazyLock<BoxChars> =
    LazyLock::new(|| BoxChars::new("    \n    \n ── \n    \n    \n ── \n    \n    ", false));

/// Simple box style with only a header separator rule (no footer rule).
pub static SIMPLE_HEAD: LazyLock<BoxChars> =
    LazyLock::new(|| BoxChars::new("    \n    \n ── \n    \n    \n    \n    \n    ", false));

/// Simple box style with heavy (thick) horizontal rules (`━`).
pub static SIMPLE_HEAVY: LazyLock<BoxChars> =
    LazyLock::new(|| BoxChars::new("    \n    \n ━━ \n    \n    \n ━━ \n    \n    ", false));

/// Box style using only horizontal rules for all borders and separators.
pub static HORIZONTALS: LazyLock<BoxChars> =
    LazyLock::new(|| BoxChars::new(" ── \n    \n ── \n    \n ── \n ── \n    \n ── ", false));

/// Single-line Unicode box with rounded corners (`╭╮╰╯`).
pub static ROUNDED: LazyLock<BoxChars> =
    LazyLock::new(|| BoxChars::new("╭─┬╮\n│ ││\n├─┼┤\n│ ││\n├─┼┤\n├─┼┤\n│ ││\n╰─┴╯", false));

/// Heavy (thick) Unicode box style (`┏━┳┓`, `┃`, `┗━┻┛`).
pub static HEAVY: LazyLock<BoxChars> =
    LazyLock::new(|| BoxChars::new("┏━┳┓\n┃ ┃┃\n┣━╋┫\n┃ ┃┃\n┣━╋┫\n┣━╋┫\n┃ ┃┃\n┗━┻┛", false));

/// Heavy outer edges with light inner dividers (`┏━┯┓`, `┃│┃`).
pub static HEAVY_EDGE: LazyLock<BoxChars> =
    LazyLock::new(|| BoxChars::new("┏━┯┓\n┃ │┃\n┠─┼┨\n┃ │┃\n┠─┼┨\n┠─┼┨\n┃ │┃\n┗━┷┛", false));

/// Heavy header section with light body (`┏━┳┓` header, `├─┼┤` body).
pub static HEAVY_HEAD: LazyLock<BoxChars> =
    LazyLock::new(|| BoxChars::new("┏━┳┓\n┃ ┃┃\n┡━╇┩\n│ ││\n├─┼┤\n├─┼┤\n│ ││\n└─┴┘", false));

/// Double-line Unicode box style (`╔═╦╗`, `║`, `╚═╩╝`).
pub static DOUBLE: LazyLock<BoxChars> =
    LazyLock::new(|| BoxChars::new("╔═╦╗\n║ ║║\n╠═╬╣\n║ ║║\n╠═╬╣\n╠═╬╣\n║ ║║\n╚═╩╝", false));

/// Double-line outer edges with single-line inner dividers (`╔═╤╗`, `║│║`).
pub static DOUBLE_EDGE: LazyLock<BoxChars> =
    LazyLock::new(|| BoxChars::new("╔═╤╗\n║ │║\n╟─┼╢\n║ │║\n╟─┼╢\n╟─┼╢\n║ │║\n╚═╧╝", false));

/// Markdown-compatible table box style using `|` and `-` characters.
pub static MARKDOWN: LazyLock<BoxChars> =
    LazyLock::new(|| BoxChars::new("    \n| ||\n|-||\n| ||\n|-||\n|-||\n| ||\n    ", true));

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

    // ---- Parsing tests ----

    #[test]
    fn test_parse_ascii() {
        let b = &*ASCII;
        assert_eq!(b.top_left, '+');
        assert_eq!(b.top, '-');
        assert_eq!(b.top_divider, '-');
        assert_eq!(b.top_right, '+');
        assert_eq!(b.head_left, '|');
        assert_eq!(b.head_vertical, '|');
        assert_eq!(b.head_right, '|');
        assert_eq!(b.head_row_left, '|');
        assert_eq!(b.head_row_horizontal, '-');
        assert_eq!(b.head_row_cross, '+');
        assert_eq!(b.head_row_right, '|');
        assert_eq!(b.bottom_left, '+');
        assert_eq!(b.bottom_char, '-');
        assert_eq!(b.bottom_divider, '-');
        assert_eq!(b.bottom_right, '+');
        assert!(b.ascii);
    }

    #[test]
    fn test_parse_square() {
        let b = &*SQUARE;
        assert_eq!(b.top_left, '');
        assert_eq!(b.top, '');
        assert_eq!(b.top_divider, '');
        assert_eq!(b.top_right, '');
        assert_eq!(b.head_left, '');
        assert_eq!(b.head_vertical, '');
        assert_eq!(b.head_right, '');
        assert_eq!(b.head_row_left, '');
        assert_eq!(b.head_row_horizontal, '');
        assert_eq!(b.head_row_cross, '');
        assert_eq!(b.head_row_right, '');
        assert_eq!(b.bottom_left, '');
        assert_eq!(b.bottom_char, '');
        assert_eq!(b.bottom_divider, '');
        assert_eq!(b.bottom_right, '');
        assert!(!b.ascii);
    }

    #[test]
    fn test_parse_heavy() {
        let b = &*HEAVY;
        assert_eq!(b.top_left, '');
        assert_eq!(b.top, '');
        assert_eq!(b.top_divider, '');
        assert_eq!(b.top_right, '');
        assert_eq!(b.head_row_cross, '');
        assert!(!b.ascii);
    }

    #[test]
    fn test_parse_double() {
        let b = &*DOUBLE;
        assert_eq!(b.top_left, '');
        assert_eq!(b.top, '');
        assert_eq!(b.top_divider, '');
        assert_eq!(b.top_right, '');
        assert_eq!(b.bottom_left, '');
        assert_eq!(b.bottom_char, '');
        assert_eq!(b.bottom_divider, '');
        assert_eq!(b.bottom_right, '');
    }

    #[test]
    fn test_parse_rounded() {
        let b = &*ROUNDED;
        assert_eq!(b.top_left, '');
        assert_eq!(b.top_right, '');
        assert_eq!(b.bottom_left, '');
        assert_eq!(b.bottom_right, '');
    }

    #[test]
    fn test_parse_all_19_boxes() {
        // Just force initialization of all 19 constants to ensure none panic
        let _ = &*ASCII;
        let _ = &*ASCII2;
        let _ = &*ASCII_DOUBLE_HEAD;
        let _ = &*SQUARE;
        let _ = &*SQUARE_DOUBLE_HEAD;
        let _ = &*MINIMAL;
        let _ = &*MINIMAL_HEAVY_HEAD;
        let _ = &*MINIMAL_DOUBLE_HEAD;
        let _ = &*SIMPLE;
        let _ = &*SIMPLE_HEAD;
        let _ = &*SIMPLE_HEAVY;
        let _ = &*HORIZONTALS;
        let _ = &*ROUNDED;
        let _ = &*HEAVY;
        let _ = &*HEAVY_EDGE;
        let _ = &*HEAVY_HEAD;
        let _ = &*DOUBLE;
        let _ = &*DOUBLE_EDGE;
        let _ = &*MARKDOWN;
    }

    #[test]
    fn test_ascii_flag() {
        assert!(ASCII.ascii);
        assert!(ASCII2.ascii);
        assert!(ASCII_DOUBLE_HEAD.ascii);
        assert!(MARKDOWN.ascii);
        assert!(!SQUARE.ascii);
        assert!(!ROUNDED.ascii);
        assert!(!HEAVY.ascii);
        assert!(!DOUBLE.ascii);
    }

    // ---- get_top tests ----

    #[test]
    fn test_get_top_square() {
        let top = SQUARE.get_top(&[5, 3]);
        assert_eq!(top, "┌─────┬───┐");
    }

    #[test]
    fn test_get_top_ascii() {
        // ASCII top_divider is '-', same as top fill char
        let top = ASCII.get_top(&[3, 4]);
        assert_eq!(top, "+--------+");
    }

    #[test]
    fn test_get_top_ascii2() {
        // ASCII2 top_divider is '+'
        let top = ASCII2.get_top(&[3, 4]);
        assert_eq!(top, "+---+----+");
    }

    #[test]
    fn test_get_top_single_column() {
        let top = SQUARE.get_top(&[10]);
        assert_eq!(top, "┌──────────┐");
    }

    #[test]
    fn test_get_top_three_columns() {
        let top = HEAVY.get_top(&[2, 3, 4]);
        assert_eq!(top, "┏━━┳━━━┳━━━━┓");
    }

    // ---- get_bottom tests ----

    #[test]
    fn test_get_bottom_square() {
        let bottom = SQUARE.get_bottom(&[5, 3]);
        assert_eq!(bottom, "└─────┴───┘");
    }

    #[test]
    fn test_get_bottom_heavy() {
        let bottom = HEAVY.get_bottom(&[4, 4]);
        assert_eq!(bottom, "┗━━━━┻━━━━┛");
    }

    #[test]
    fn test_get_bottom_single_column() {
        let bottom = DOUBLE.get_bottom(&[6]);
        assert_eq!(bottom, "╚══════╝");
    }

    // ---- get_row tests ----

    #[test]
    fn test_get_row_head_square() {
        let row = SQUARE.get_row(&[5, 3], RowLevel::Head, true);
        assert_eq!(row, "├─────┼───┤");
    }

    #[test]
    fn test_get_row_head_no_edge() {
        let row = SQUARE.get_row(&[5, 3], RowLevel::Head, false);
        assert_eq!(row, "─────┼───");
    }

    #[test]
    fn test_get_row_body_square() {
        let row = SQUARE.get_row(&[5, 3], RowLevel::Row, true);
        assert_eq!(row, "├─────┼───┤");
    }

    #[test]
    fn test_get_row_foot_square() {
        let row = SQUARE.get_row(&[5, 3], RowLevel::Foot, true);
        assert_eq!(row, "├─────┼───┤");
    }

    #[test]
    fn test_get_row_head_heavy() {
        let row = HEAVY.get_row(&[3, 3], RowLevel::Head, true);
        assert_eq!(row, "┣━━━╋━━━┫");
    }

    #[test]
    fn test_get_row_ascii() {
        let row = ASCII2.get_row(&[4, 4], RowLevel::Head, true);
        assert_eq!(row, "+----+----+");
    }

    // ---- substitute tests ----

    #[test]
    fn test_substitute_not_ascii() {
        let b = SQUARE.substitute(false);
        assert_eq!(b.top_left, '');
    }

    #[test]
    fn test_substitute_rounded_to_square() {
        let b = ROUNDED.substitute(true);
        assert_eq!(b.top_left, '');
        assert_eq!(b.bottom_left, '');
    }

    #[test]
    fn test_substitute_heavy_to_square() {
        let b = HEAVY.substitute(true);
        assert_eq!(b.top_left, '');
    }

    #[test]
    fn test_substitute_heavy_edge_to_square() {
        let b = HEAVY_EDGE.substitute(true);
        assert_eq!(b.top_left, '');
    }

    #[test]
    fn test_substitute_simple_heavy_to_simple() {
        let b = SIMPLE_HEAVY.substitute(true);
        assert_eq!(b.head_row_horizontal, '');
    }

    #[test]
    fn test_substitute_minimal_heavy_head_to_minimal() {
        let b = MINIMAL_HEAVY_HEAD.substitute(true);
        assert_eq!(b.head_row_horizontal, '');
        assert_eq!(b.head_row_cross, '');
    }

    // ---- get_plain_headed_box tests ----

    #[test]
    fn test_plain_headed_heavy_head() {
        let b = HEAVY_HEAD.get_plain_headed_box();
        assert_eq!(b.top_left, '');
        assert_eq!(b.head_row_horizontal, '');
    }

    #[test]
    fn test_plain_headed_square_double_head() {
        let b = SQUARE_DOUBLE_HEAD.get_plain_headed_box();
        assert_eq!(b.top_left, '');
        assert_eq!(b.head_row_horizontal, '');
    }

    #[test]
    fn test_plain_headed_minimal_double_head() {
        let b = MINIMAL_DOUBLE_HEAD.get_plain_headed_box();
        assert_eq!(b.head_row_horizontal, '');
        assert_eq!(b.head_row_cross, '');
    }

    #[test]
    fn test_plain_headed_ascii_double_head() {
        let b = ASCII_DOUBLE_HEAD.get_plain_headed_box();
        assert_eq!(b.head_row_horizontal, '-');
        assert_eq!(b.head_row_cross, '+');
    }

    #[test]
    fn test_plain_headed_identity() {
        // SQUARE has no special headed variant, returns itself
        let b = SQUARE.get_plain_headed_box();
        assert_eq!(b.top_left, '');
        assert_eq!(b.head_row_horizontal, '');
    }

    // ---- Edge case tests ----

    #[test]
    fn test_get_top_empty_widths() {
        let top = SQUARE.get_top(&[]);
        assert_eq!(top, "┌┐");
    }

    #[test]
    fn test_get_bottom_empty_widths() {
        let bottom = SQUARE.get_bottom(&[]);
        assert_eq!(bottom, "└┘");
    }

    #[test]
    fn test_get_row_empty_widths() {
        let row = SQUARE.get_row(&[], RowLevel::Head, true);
        assert_eq!(row, "├┤");
    }

    #[test]
    fn test_get_top_zero_width_column() {
        let top = SQUARE.get_top(&[0, 3]);
        assert_eq!(top, "┌┬───┐");
    }

    #[test]
    fn test_markdown_box() {
        let b = &*MARKDOWN;
        assert_eq!(b.head_left, '|');
        assert_eq!(b.head_vertical, '|');
        assert_eq!(b.head_right, '|');
        assert_eq!(b.head_row_horizontal, '-');
        assert_eq!(b.head_row_cross, '|');
        assert!(b.ascii);
    }

    #[test]
    #[should_panic(expected = "8 lines")]
    fn test_bad_line_count() {
        BoxChars::new("abc\ndef", false);
    }

    #[test]
    #[should_panic(expected = "4 characters")]
    fn test_bad_char_count() {
        BoxChars::new("ab\nabcd\nabcd\nabcd\nabcd\nabcd\nabcd\nabcd", false);
    }
}