envision 0.17.0

A ratatui framework for collaborative TUI development with headless testing support
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
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
use super::*;

#[test]
fn test_default_theme() {
    let theme = Theme::default();
    assert_eq!(theme.focused, Color::Yellow);
    assert_eq!(theme.disabled, Color::DarkGray);
    assert_eq!(theme.success, Color::Green);
    assert_eq!(theme.warning, Color::Yellow);
    assert_eq!(theme.error, Color::Red);
    assert_eq!(theme.info, Color::Cyan);
}

#[test]
#[allow(deprecated)]
fn test_nord_theme() {
    let theme = Theme::nord();
    assert_eq!(theme.focused, NORD8);
    assert_eq!(theme.selected, NORD9);
    assert_eq!(theme.disabled, NORD3);
    assert_eq!(theme.success, NORD14);
    assert_eq!(theme.warning, NORD13);
    assert_eq!(theme.error, NORD11);
    assert_eq!(theme.info, NORD8);
    assert_eq!(theme.background, NORD0);
    assert_eq!(theme.foreground, NORD6);
}

#[test]
#[allow(deprecated)]
fn test_nord_colors() {
    assert_eq!(NORD0, Color::Rgb(46, 52, 64));
    assert_eq!(NORD8, Color::Rgb(136, 192, 208));
    assert_eq!(NORD14, Color::Rgb(163, 190, 140));
}

#[test]
fn test_focused_style() {
    let theme = Theme::default();
    let style = theme.focused_style();
    assert_eq!(style.fg, Some(Color::Yellow));
}

#[test]
fn test_focused_bold_style() {
    let theme = Theme::default();
    let style = theme.focused_bold_style();
    assert_eq!(style.fg, Some(Color::Yellow));
    assert!(style.add_modifier.contains(Modifier::BOLD));
}

#[test]
fn test_selected_style_focused() {
    let theme = Theme::default();
    let style = theme.selected_style(true);
    assert_eq!(style.fg, Some(Color::Yellow));
    assert!(style.add_modifier.contains(Modifier::BOLD));
}

#[test]
fn test_selected_style_unfocused() {
    let theme = Theme::default();
    let style = theme.selected_style(false);
    assert_eq!(style.fg, None);
    assert!(style.add_modifier.contains(Modifier::BOLD));
}

#[test]
fn test_disabled_style() {
    let theme = Theme::default();
    let style = theme.disabled_style();
    assert_eq!(style.fg, Some(Color::DarkGray));
}

#[test]
fn test_placeholder_style() {
    let theme = Theme::default();
    let style = theme.placeholder_style();
    assert_eq!(style.fg, Some(Color::DarkGray));
}

#[test]
fn test_semantic_styles() {
    let theme = Theme::default();

    let success = theme.success_style();
    assert_eq!(success.fg, Some(Color::Green));

    let warning = theme.warning_style();
    assert_eq!(warning.fg, Some(Color::Yellow));

    let error = theme.error_style();
    assert_eq!(error.fg, Some(Color::Red));

    let info = theme.info_style();
    assert_eq!(info.fg, Some(Color::Cyan));
}

#[test]
fn test_progress_filled_style() {
    let theme = Theme::default();
    let style = theme.progress_filled_style();
    assert_eq!(style.fg, Some(Color::Cyan));
    assert_eq!(style.bg, Some(Color::Black));
}

#[test]
fn test_theme_clone() {
    let theme = Theme::nord();
    let cloned = theme.clone();
    assert_eq!(theme, cloned);
}

#[test]
fn test_custom_theme() {
    let custom = Theme {
        focused: Color::Magenta,
        selected: Color::LightBlue,
        ..Theme::default()
    };
    assert_eq!(custom.focused, Color::Magenta);
    assert_eq!(custom.selected, Color::LightBlue);
    assert_eq!(custom.disabled, Color::DarkGray); // From default
}

#[test]
fn test_normal_style() {
    let theme = Theme::default();
    let style = theme.normal_style();
    // Default theme uses Color::Reset for fg/bg
    assert_eq!(style.fg, Some(Color::Reset));
    assert_eq!(style.bg, Some(Color::Reset));
}

#[test]
#[allow(deprecated)]
fn test_normal_style_nord() {
    let theme = Theme::nord();
    let style = theme.normal_style();
    assert_eq!(style.fg, Some(NORD6));
    assert_eq!(style.bg, Some(NORD0));
}

#[test]
#[allow(deprecated)]
fn test_focused_border_style_differs_from_focused_style() {
    let theme = Theme::nord();
    let border_style = theme.focused_border_style();
    let focused_style = theme.focused_style();
    // Both use focused color for fg
    assert_eq!(border_style.fg, Some(NORD8));
    assert_eq!(focused_style.fg, Some(NORD8));
    // Border style includes background, focused style does not
    assert_eq!(border_style.bg, Some(NORD0));
    assert_eq!(focused_style.bg, None);
}

#[test]
fn test_primary_style() {
    let theme = Theme::default();
    let style = theme.primary_style();
    assert_eq!(style.fg, Some(Color::Cyan));
}

#[test]
#[allow(deprecated)]
fn test_primary_style_nord() {
    let theme = Theme::nord();
    let style = theme.primary_style();
    assert_eq!(style.fg, Some(NORD10));
}

#[test]
#[allow(deprecated)]
fn test_border_style() {
    let theme = Theme::nord();
    let style = theme.border_style();
    assert_eq!(style.fg, Some(NORD3));
}

#[test]
#[allow(deprecated)]
fn test_selected_highlight_style_focused() {
    let theme = Theme::nord();
    let style = theme.selected_highlight_style(true);
    assert_eq!(style.bg, Some(NORD9));
    assert_eq!(style.fg, Some(NORD6));
}

#[test]
#[allow(deprecated)]
fn test_selected_highlight_style_unfocused() {
    let theme = Theme::nord();
    let style = theme.selected_highlight_style(false);
    assert_eq!(style.bg, Some(NORD3));
    assert_eq!(style.fg, Some(NORD6));
}

#[test]
#[allow(deprecated)]
fn test_dracula_theme() {
    let theme = Theme::dracula();
    assert_eq!(theme.background, DRACULA_BG);
    assert_eq!(theme.foreground, DRACULA_FG);
    assert_eq!(theme.border, DRACULA_COMMENT);
    assert_eq!(theme.focused, DRACULA_PURPLE);
    assert_eq!(theme.selected, DRACULA_PINK);
    assert_eq!(theme.disabled, DRACULA_COMMENT);
    assert_eq!(theme.placeholder, DRACULA_COMMENT);
    assert_eq!(theme.primary, DRACULA_CYAN);
    assert_eq!(theme.success, DRACULA_GREEN);
    assert_eq!(theme.warning, DRACULA_YELLOW);
    assert_eq!(theme.error, DRACULA_RED);
    assert_eq!(theme.info, DRACULA_CYAN);
    assert_eq!(theme.progress_filled, DRACULA_PURPLE);
    assert_eq!(theme.progress_empty, DRACULA_CURRENT);
}

#[test]
#[allow(deprecated)]
fn test_dracula_colors() {
    assert_eq!(DRACULA_BG, Color::Rgb(40, 42, 54));
    assert_eq!(DRACULA_PURPLE, Color::Rgb(189, 147, 249));
    assert_eq!(DRACULA_GREEN, Color::Rgb(80, 250, 123));
}

#[test]
#[allow(deprecated)]
fn test_solarized_dark_theme() {
    let theme = Theme::solarized_dark();
    assert_eq!(theme.background, SOLARIZED_BASE03);
    assert_eq!(theme.foreground, SOLARIZED_BASE0);
    assert_eq!(theme.border, SOLARIZED_BASE01);
    assert_eq!(theme.focused, SOLARIZED_BLUE);
    assert_eq!(theme.selected, SOLARIZED_CYAN);
    assert_eq!(theme.disabled, SOLARIZED_BASE01);
    assert_eq!(theme.placeholder, SOLARIZED_BASE01);
    assert_eq!(theme.primary, SOLARIZED_BLUE);
    assert_eq!(theme.success, SOLARIZED_GREEN);
    assert_eq!(theme.warning, SOLARIZED_YELLOW);
    assert_eq!(theme.error, SOLARIZED_RED);
    assert_eq!(theme.info, SOLARIZED_CYAN);
    assert_eq!(theme.progress_filled, SOLARIZED_BLUE);
    assert_eq!(theme.progress_empty, SOLARIZED_BASE02);
}

#[test]
#[allow(deprecated)]
fn test_solarized_dark_colors() {
    assert_eq!(SOLARIZED_BASE03, Color::Rgb(0, 43, 54));
    assert_eq!(SOLARIZED_BLUE, Color::Rgb(38, 139, 210));
    assert_eq!(SOLARIZED_GREEN, Color::Rgb(133, 153, 0));
}

#[test]
#[allow(deprecated)]
fn test_gruvbox_dark_theme() {
    let theme = Theme::gruvbox_dark();
    assert_eq!(theme.background, GRUVBOX_BG);
    assert_eq!(theme.foreground, GRUVBOX_FG);
    assert_eq!(theme.border, GRUVBOX_GRAY);
    assert_eq!(theme.focused, GRUVBOX_YELLOW);
    assert_eq!(theme.selected, GRUVBOX_BLUE);
    assert_eq!(theme.disabled, GRUVBOX_GRAY);
    assert_eq!(theme.placeholder, GRUVBOX_GRAY);
    assert_eq!(theme.primary, GRUVBOX_AQUA);
    assert_eq!(theme.success, GRUVBOX_GREEN);
    assert_eq!(theme.warning, GRUVBOX_ORANGE);
    assert_eq!(theme.error, GRUVBOX_RED);
    assert_eq!(theme.info, GRUVBOX_BLUE);
    assert_eq!(theme.progress_filled, GRUVBOX_YELLOW);
    assert_eq!(theme.progress_empty, GRUVBOX_BG1);
}

#[test]
#[allow(deprecated)]
fn test_gruvbox_dark_colors() {
    assert_eq!(GRUVBOX_BG, Color::Rgb(40, 40, 40));
    assert_eq!(GRUVBOX_YELLOW, Color::Rgb(250, 189, 47));
    assert_eq!(GRUVBOX_GREEN, Color::Rgb(184, 187, 38));
}

#[test]
#[allow(deprecated)]
fn test_catppuccin_mocha_theme() {
    let theme = Theme::catppuccin_mocha();
    assert_eq!(theme.background, CATPPUCCIN_BASE);
    assert_eq!(theme.foreground, CATPPUCCIN_TEXT);
    assert_eq!(theme.border, CATPPUCCIN_SURFACE2);
    assert_eq!(theme.focused, CATPPUCCIN_LAVENDER);
    assert_eq!(theme.selected, CATPPUCCIN_MAUVE);
    assert_eq!(theme.disabled, CATPPUCCIN_SURFACE2);
    assert_eq!(theme.placeholder, CATPPUCCIN_OVERLAY0);
    assert_eq!(theme.primary, CATPPUCCIN_BLUE);
    assert_eq!(theme.success, CATPPUCCIN_GREEN);
    assert_eq!(theme.warning, CATPPUCCIN_YELLOW);
    assert_eq!(theme.error, CATPPUCCIN_RED);
    assert_eq!(theme.info, CATPPUCCIN_SAPPHIRE);
    assert_eq!(theme.progress_filled, CATPPUCCIN_LAVENDER);
    assert_eq!(theme.progress_empty, CATPPUCCIN_SURFACE0);
}

#[test]
#[allow(deprecated)]
fn test_catppuccin_mocha_colors() {
    assert_eq!(CATPPUCCIN_BASE, Color::Rgb(30, 30, 46));
    assert_eq!(CATPPUCCIN_LAVENDER, Color::Rgb(180, 190, 254));
    assert_eq!(CATPPUCCIN_GREEN, Color::Rgb(166, 227, 161));
}

#[test]
fn test_all_themes_distinct() {
    let themes = [
        Theme::default(),
        Theme::nord(),
        Theme::dracula(),
        Theme::solarized_dark(),
        Theme::gruvbox_dark(),
        Theme::catppuccin_mocha(),
    ];
    for i in 0..themes.len() {
        for j in (i + 1)..themes.len() {
            assert_ne!(
                themes[i], themes[j],
                "themes at indices {} and {} should differ",
                i, j
            );
        }
    }
}

#[test]
fn test_severity_enum_variants() {
    // Pin the four severity variants and their ordering.
    let _good = Severity::Good;
    let _mild = Severity::Mild;
    let _bad = Severity::Bad;
    let _critical = Severity::Critical;
    // Pin Copy/Clone/Eq so consumers can destructure freely.
    let s = Severity::Bad;
    let s2 = s;
    assert_eq!(s, s2);
}

#[test]
fn test_severity_from_thresholds_band_boundaries() {
    let thresholds = [
        (1.0, Severity::Good),
        (3.0, Severity::Mild),
        (10.0, Severity::Bad),
    ];
    // Below first cutoff: Good.
    assert_eq!(Severity::from_thresholds(0.5, &thresholds), Severity::Good);
    assert_eq!(
        Severity::from_thresholds(0.999, &thresholds),
        Severity::Good
    );
    // At cutoff falls through to next band (Mild).
    assert_eq!(Severity::from_thresholds(1.0, &thresholds), Severity::Mild);
    // Inside Mild range.
    assert_eq!(Severity::from_thresholds(2.0, &thresholds), Severity::Mild);
    assert_eq!(
        Severity::from_thresholds(2.999, &thresholds),
        Severity::Mild
    );
    // At Mild cutoff falls through to Bad.
    assert_eq!(Severity::from_thresholds(3.0, &thresholds), Severity::Bad);
    assert_eq!(Severity::from_thresholds(5.0, &thresholds), Severity::Bad);
    // At Bad cutoff falls through to Critical (default).
    assert_eq!(
        Severity::from_thresholds(10.0, &thresholds),
        Severity::Critical
    );
    assert_eq!(
        Severity::from_thresholds(20.0, &thresholds),
        Severity::Critical
    );
}

#[test]
fn test_severity_from_thresholds_empty() {
    // Empty threshold slice: every value is Critical.
    assert_eq!(Severity::from_thresholds(0.0, &[]), Severity::Critical);
    assert_eq!(Severity::from_thresholds(-1.0, &[]), Severity::Critical);
    assert_eq!(Severity::from_thresholds(1e9, &[]), Severity::Critical);
}

#[test]
fn test_severity_from_thresholds_unsorted_first_match_wins() {
    // Documented first-match-wins: iteration is in slice order, not by sorted cutoff.
    // Unsorted thresholds give well-defined but possibly counter-intuitive results.
    let unsorted = [
        (10.0, Severity::Bad),
        (1.0, Severity::Good),
        (3.0, Severity::Mild),
    ];
    // value=2.0: first cutoff is 10.0; 2.0 < 10.0, so returns Bad immediately.
    assert_eq!(Severity::from_thresholds(2.0, &unsorted), Severity::Bad);
    // value=15.0: 15.0 < 10.0? no. 15.0 < 1.0? no. 15.0 < 3.0? no. Critical default.
    assert_eq!(
        Severity::from_thresholds(15.0, &unsorted),
        Severity::Critical
    );
}

#[test]
fn test_named_color_enum_variants() {
    // Pin all 26 NamedColor variants — the spec's complete Catppuccin-derived palette.
    let variants = [
        NamedColor::Rosewater,
        NamedColor::Flamingo,
        NamedColor::Pink,
        NamedColor::Mauve,
        NamedColor::Red,
        NamedColor::Maroon,
        NamedColor::Peach,
        NamedColor::Yellow,
        NamedColor::Green,
        NamedColor::Teal,
        NamedColor::Sky,
        NamedColor::Sapphire,
        NamedColor::Blue,
        NamedColor::Lavender,
        NamedColor::Text,
        NamedColor::Subtext1,
        NamedColor::Subtext0,
        NamedColor::Overlay2,
        NamedColor::Overlay1,
        NamedColor::Overlay0,
        NamedColor::Surface2,
        NamedColor::Surface1,
        NamedColor::Surface0,
        NamedColor::Base,
        NamedColor::Mantle,
        NamedColor::Crust,
    ];
    assert_eq!(variants.len(), 26);
}

#[test]
fn test_palette_struct_construction() {
    // Direct construction: a custom user theme can build a Palette with no envision changes.
    let custom = Palette {
        rosewater: Color::Rgb(255, 0, 0),
        flamingo: Color::Rgb(255, 0, 0),
        pink: Color::Rgb(255, 0, 0),
        mauve: Color::Rgb(255, 0, 0),
        red: Color::Rgb(255, 0, 0),
        maroon: Color::Rgb(255, 0, 0),
        peach: Color::Rgb(255, 0, 0),
        yellow: Color::Rgb(255, 0, 0),
        green: Color::Rgb(255, 0, 0),
        teal: Color::Rgb(255, 0, 0),
        sky: Color::Rgb(255, 0, 0),
        sapphire: Color::Rgb(255, 0, 0),
        blue: Color::Rgb(255, 0, 0),
        lavender: Color::Rgb(255, 0, 0),
        text: Color::Rgb(255, 0, 0),
        subtext1: Color::Rgb(255, 0, 0),
        subtext0: Color::Rgb(255, 0, 0),
        overlay2: Color::Rgb(255, 0, 0),
        overlay1: Color::Rgb(255, 0, 0),
        overlay0: Color::Rgb(255, 0, 0),
        surface2: Color::Rgb(255, 0, 0),
        surface1: Color::Rgb(255, 0, 0),
        surface0: Color::Rgb(255, 0, 0),
        base: Color::Rgb(255, 0, 0),
        mantle: Color::Rgb(255, 0, 0),
        crust: Color::Rgb(255, 0, 0),
    };
    assert_eq!(custom.rosewater, Color::Rgb(255, 0, 0));
    assert_eq!(custom.crust, Color::Rgb(255, 0, 0));
    // Pin Clone + Copy + Debug + PartialEq.
    let cloned = custom;
    assert_eq!(custom, cloned);
}

#[test]
#[allow(deprecated)]
fn test_catppuccin_palette_pinned() {
    // Pin every Catppuccin palette entry to its source constant.
    // Future palette tweaks show up as test diffs.
    let theme = Theme::catppuccin_mocha();
    let p = &theme.palette;
    assert_eq!(p.rosewater, CATPPUCCIN_ROSEWATER);
    assert_eq!(p.flamingo, CATPPUCCIN_FLAMINGO);
    assert_eq!(p.pink, CATPPUCCIN_PINK);
    assert_eq!(p.mauve, CATPPUCCIN_MAUVE);
    assert_eq!(p.red, CATPPUCCIN_RED);
    assert_eq!(p.maroon, CATPPUCCIN_MAROON);
    assert_eq!(p.peach, CATPPUCCIN_PEACH);
    assert_eq!(p.yellow, CATPPUCCIN_YELLOW);
    assert_eq!(p.green, CATPPUCCIN_GREEN);
    assert_eq!(p.teal, CATPPUCCIN_TEAL);
    assert_eq!(p.sky, CATPPUCCIN_SKY);
    assert_eq!(p.sapphire, CATPPUCCIN_SAPPHIRE);
    assert_eq!(p.blue, CATPPUCCIN_BLUE);
    assert_eq!(p.lavender, CATPPUCCIN_LAVENDER);
    assert_eq!(p.text, CATPPUCCIN_TEXT);
    assert_eq!(p.subtext1, CATPPUCCIN_SUBTEXT1);
    assert_eq!(p.subtext0, CATPPUCCIN_SUBTEXT0);
    assert_eq!(p.overlay2, CATPPUCCIN_OVERLAY2);
    assert_eq!(p.overlay1, CATPPUCCIN_OVERLAY1);
    assert_eq!(p.overlay0, CATPPUCCIN_OVERLAY0);
    assert_eq!(p.surface2, CATPPUCCIN_SURFACE2);
    assert_eq!(p.surface1, CATPPUCCIN_SURFACE1);
    assert_eq!(p.surface0, CATPPUCCIN_SURFACE0);
    assert_eq!(p.base, CATPPUCCIN_BASE);
    assert_eq!(p.mantle, CATPPUCCIN_MANTLE);
    assert_eq!(p.crust, CATPPUCCIN_CRUST);
}

#[test]
#[allow(deprecated)]
fn test_nord_palette_pinned() {
    // Pin Nord's nearest-equivalent palette mapping. Documented in Theme::nord().
    let theme = Theme::nord();
    let p = &theme.palette;

    // Nord Aurora warm accents map to closest hue.
    assert_eq!(p.red, NORD11); // Nord red
    assert_eq!(p.maroon, NORD11); // No native maroon; reuse red
    assert_eq!(p.peach, NORD12); // Nord orange
    assert_eq!(p.yellow, NORD13); // Nord yellow
    assert_eq!(p.green, NORD14); // Nord green
    assert_eq!(p.teal, NORD7); // Nord frost teal

    // Nord pinks/rosewaters: no native; map to Snow Storm light tones.
    assert_eq!(p.rosewater, NORD4);
    assert_eq!(p.flamingo, NORD4);

    // Nord purples (only Nord15 exists): pink/mauve/lavender all to Nord15.
    assert_eq!(p.pink, NORD15);
    assert_eq!(p.mauve, NORD15);
    assert_eq!(p.lavender, NORD15);

    // Nord Frost cool blues.
    assert_eq!(p.sky, NORD8); // light blue
    assert_eq!(p.sapphire, NORD9); // mid blue
    assert_eq!(p.blue, NORD10); // deep blue

    // Text/overlay tones from Snow Storm (light → less light).
    assert_eq!(p.text, NORD6);
    assert_eq!(p.subtext1, NORD5);
    assert_eq!(p.subtext0, NORD4);
    assert_eq!(p.overlay2, NORD3);
    assert_eq!(p.overlay1, NORD3);
    assert_eq!(p.overlay0, NORD3);

    // Surface/background tones from Polar Night (light → dark).
    assert_eq!(p.surface2, NORD2);
    assert_eq!(p.surface1, NORD1);
    assert_eq!(p.surface0, NORD1);
    assert_eq!(p.base, NORD0);
    assert_eq!(p.mantle, NORD0);
    assert_eq!(p.crust, NORD0);
}

#[test]
#[allow(deprecated)]
fn test_dracula_palette_pinned() {
    let theme = Theme::dracula();
    let p = &theme.palette;

    // Dracula has named accents: Cyan, Green, Orange, Pink, Purple, Red, Yellow.
    assert_eq!(p.red, DRACULA_RED);
    assert_eq!(p.maroon, DRACULA_RED); // No maroon; reuse red
    assert_eq!(p.peach, DRACULA_ORANGE);
    assert_eq!(p.yellow, DRACULA_YELLOW);
    assert_eq!(p.green, DRACULA_GREEN);
    assert_eq!(p.teal, DRACULA_CYAN); // Closest cool teal-ish

    // Pinks/mauves/lavender: native pink and purple available.
    assert_eq!(p.pink, DRACULA_PINK);
    assert_eq!(p.mauve, DRACULA_PURPLE);
    assert_eq!(p.lavender, DRACULA_PURPLE);
    assert_eq!(p.rosewater, DRACULA_PINK); // Closest pastel pink
    assert_eq!(p.flamingo, DRACULA_PINK);

    // Cool blues: Dracula has only Cyan; map all blues to Cyan.
    assert_eq!(p.sky, DRACULA_CYAN);
    assert_eq!(p.sapphire, DRACULA_CYAN);
    assert_eq!(p.blue, DRACULA_CYAN);

    // Text + overlay tones.
    assert_eq!(p.text, DRACULA_FG);
    assert_eq!(p.subtext1, DRACULA_FG);
    assert_eq!(p.subtext0, DRACULA_COMMENT);
    assert_eq!(p.overlay2, DRACULA_COMMENT);
    assert_eq!(p.overlay1, DRACULA_COMMENT);
    assert_eq!(p.overlay0, DRACULA_COMMENT);

    // Surface / base tones.
    assert_eq!(p.surface2, DRACULA_CURRENT);
    assert_eq!(p.surface1, DRACULA_CURRENT);
    assert_eq!(p.surface0, DRACULA_CURRENT);
    assert_eq!(p.base, DRACULA_BG);
    assert_eq!(p.mantle, DRACULA_BG);
    assert_eq!(p.crust, DRACULA_BG);
}

#[test]
#[allow(deprecated)]
fn test_solarized_dark_palette_pinned() {
    let theme = Theme::solarized_dark();
    let p = &theme.palette;

    // Solarized has yellow/orange/red/magenta/violet/blue/cyan/green plus base shades.
    assert_eq!(p.red, SOLARIZED_RED);
    assert_eq!(p.maroon, SOLARIZED_RED);
    assert_eq!(p.peach, SOLARIZED_ORANGE);
    assert_eq!(p.yellow, SOLARIZED_YELLOW);
    assert_eq!(p.green, SOLARIZED_GREEN);
    assert_eq!(p.teal, SOLARIZED_CYAN);

    // Pinks: no native pink; magenta is closest pink-ish hue.
    assert_eq!(p.pink, SOLARIZED_MAGENTA);
    assert_eq!(p.rosewater, SOLARIZED_MAGENTA);
    assert_eq!(p.flamingo, SOLARIZED_MAGENTA);
    assert_eq!(p.mauve, SOLARIZED_MAGENTA);
    assert_eq!(p.lavender, SOLARIZED_MAGENTA); // No violet const exported; magenta closest

    // Cool blues.
    assert_eq!(p.sky, SOLARIZED_CYAN);
    assert_eq!(p.sapphire, SOLARIZED_BLUE);
    assert_eq!(p.blue, SOLARIZED_BLUE);

    // Text/overlay/surface tones.
    assert_eq!(p.text, SOLARIZED_BASE1);
    assert_eq!(p.subtext1, SOLARIZED_BASE0);
    assert_eq!(p.subtext0, SOLARIZED_BASE01);
    assert_eq!(p.overlay2, SOLARIZED_BASE01);
    assert_eq!(p.overlay1, SOLARIZED_BASE01);
    assert_eq!(p.overlay0, SOLARIZED_BASE01);
    assert_eq!(p.surface2, SOLARIZED_BASE02);
    assert_eq!(p.surface1, SOLARIZED_BASE02);
    assert_eq!(p.surface0, SOLARIZED_BASE02);
    assert_eq!(p.base, SOLARIZED_BASE03);
    assert_eq!(p.mantle, SOLARIZED_BASE03);
    assert_eq!(p.crust, SOLARIZED_BASE03);
}

#[test]
#[allow(deprecated)]
fn test_gruvbox_dark_palette_pinned() {
    let theme = Theme::gruvbox_dark();
    let p = &theme.palette;

    // Gruvbox accents: red/green/yellow/blue/purple/aqua/orange.
    assert_eq!(p.red, GRUVBOX_RED);
    assert_eq!(p.maroon, GRUVBOX_RED);
    assert_eq!(p.peach, GRUVBOX_ORANGE);
    assert_eq!(p.yellow, GRUVBOX_YELLOW);
    assert_eq!(p.green, GRUVBOX_GREEN);
    assert_eq!(p.teal, GRUVBOX_AQUA);

    // Pinks/mauves/lavender: gruvbox purple is the only purple.
    assert_eq!(p.pink, GRUVBOX_PURPLE);
    assert_eq!(p.rosewater, GRUVBOX_PURPLE);
    assert_eq!(p.flamingo, GRUVBOX_PURPLE);
    assert_eq!(p.mauve, GRUVBOX_PURPLE);
    assert_eq!(p.lavender, GRUVBOX_PURPLE);

    // Cool blues: only one blue + aqua.
    assert_eq!(p.sky, GRUVBOX_AQUA);
    assert_eq!(p.sapphire, GRUVBOX_BLUE);
    assert_eq!(p.blue, GRUVBOX_BLUE);

    // Text/overlay tones.
    assert_eq!(p.text, GRUVBOX_FG);
    assert_eq!(p.subtext1, GRUVBOX_FG);
    assert_eq!(p.subtext0, GRUVBOX_GRAY);
    assert_eq!(p.overlay2, GRUVBOX_GRAY);
    assert_eq!(p.overlay1, GRUVBOX_GRAY);
    assert_eq!(p.overlay0, GRUVBOX_GRAY);

    // Surface/base tones.
    assert_eq!(p.surface2, GRUVBOX_BG1);
    assert_eq!(p.surface1, GRUVBOX_BG1);
    assert_eq!(p.surface0, GRUVBOX_BG1);
    assert_eq!(p.base, GRUVBOX_BG);
    assert_eq!(p.mantle, GRUVBOX_BG);
    assert_eq!(p.crust, GRUVBOX_BG);
}

#[test]
fn test_namedcolor_lookup_returns_palette_entry() {
    // theme.color(N) must return the same value as theme.palette.<field for N>.
    let theme = Theme::catppuccin_mocha();
    assert_eq!(theme.color(NamedColor::Lavender), theme.palette.lavender);
    assert_eq!(theme.color(NamedColor::Peach), theme.palette.peach);
    assert_eq!(theme.color(NamedColor::Crust), theme.palette.crust);
    assert_eq!(theme.color(NamedColor::Rosewater), theme.palette.rosewater);
    assert_eq!(theme.color(NamedColor::Teal), theme.palette.teal);

    // Same round-trip for a non-Catppuccin theme.
    let nord = Theme::nord();
    assert_eq!(nord.color(NamedColor::Lavender), nord.palette.lavender);
    assert_eq!(nord.color(NamedColor::Peach), nord.palette.peach);
}

#[test]
fn test_namedcolor_distinct_per_theme() {
    // On Catppuccin Mocha, palette accents must be distinct.
    let theme = Theme::catppuccin_mocha();
    assert_ne!(
        theme.color(NamedColor::Peach),
        theme.color(NamedColor::Yellow)
    );
    assert_ne!(
        theme.color(NamedColor::Red),
        theme.color(NamedColor::Maroon)
    );
    assert_ne!(
        theme.color(NamedColor::Blue),
        theme.color(NamedColor::Sapphire)
    );
    assert_ne!(
        theme.color(NamedColor::Pink),
        theme.color(NamedColor::Mauve)
    );
    assert_ne!(
        theme.color(NamedColor::Green),
        theme.color(NamedColor::Teal)
    );
}

#[test]
fn test_default_palette_pinned() {
    let theme = Theme::default();
    let p = &theme.palette;

    // The Default theme uses ratatui's basic Color enum for max terminal compat.
    // Many NamedColor variants intentionally collapse to the same basic Color.
    assert_eq!(p.red, Color::Red);
    assert_eq!(p.maroon, Color::Red);
    assert_eq!(p.flamingo, Color::Red);
    assert_eq!(p.rosewater, Color::Red);

    assert_eq!(p.peach, Color::Yellow);
    assert_eq!(p.yellow, Color::Yellow);

    assert_eq!(p.green, Color::Green);
    assert_eq!(p.teal, Color::Green);

    assert_eq!(p.sky, Color::Cyan);
    assert_eq!(p.sapphire, Color::Cyan);
    assert_eq!(p.blue, Color::Blue);

    assert_eq!(p.pink, Color::Magenta);
    assert_eq!(p.mauve, Color::Magenta);
    assert_eq!(p.lavender, Color::Magenta);

    // Text + overlay tones.
    assert_eq!(p.text, Color::White);
    assert_eq!(p.subtext1, Color::Gray);
    assert_eq!(p.subtext0, Color::Gray);
    assert_eq!(p.overlay2, Color::DarkGray);
    assert_eq!(p.overlay1, Color::DarkGray);
    assert_eq!(p.overlay0, Color::DarkGray);

    // Surface/base tones.
    assert_eq!(p.surface2, Color::DarkGray);
    assert_eq!(p.surface1, Color::Black);
    assert_eq!(p.surface0, Color::Black);
    assert_eq!(p.base, Color::Reset);
    assert_eq!(p.mantle, Color::Reset);
    assert_eq!(p.crust, Color::Black);
}

#[test]
#[allow(deprecated)]
fn test_severity_color_per_theme() {
    // Catppuccin: Good → Green, Mild → Yellow, Bad → Peach, Critical → Red.
    let cat = Theme::catppuccin_mocha();
    assert_eq!(cat.severity_color(Severity::Good), CATPPUCCIN_GREEN);
    assert_eq!(cat.severity_color(Severity::Mild), CATPPUCCIN_YELLOW);
    assert_eq!(cat.severity_color(Severity::Bad), CATPPUCCIN_PEACH);
    assert_eq!(cat.severity_color(Severity::Critical), CATPPUCCIN_RED);

    // Nord: routes through palette.
    let nord = Theme::nord();
    assert_eq!(nord.severity_color(Severity::Good), NORD14);
    assert_eq!(nord.severity_color(Severity::Mild), NORD13);
    assert_eq!(nord.severity_color(Severity::Bad), NORD12);
    assert_eq!(nord.severity_color(Severity::Critical), NORD11);

    // Default theme: Mild and Bad collapse to Color::Yellow per documented behavior.
    let def = Theme::default();
    assert_eq!(def.severity_color(Severity::Good), Color::Green);
    assert_eq!(def.severity_color(Severity::Mild), Color::Yellow);
    assert_eq!(def.severity_color(Severity::Bad), Color::Yellow); // collapse
    assert_eq!(def.severity_color(Severity::Critical), Color::Red);
}

#[test]
fn test_severity_style_critical_is_bold() {
    let theme = Theme::catppuccin_mocha();
    let critical = theme.severity_style(Severity::Critical);
    let good = theme.severity_style(Severity::Good);
    let mild = theme.severity_style(Severity::Mild);
    let bad = theme.severity_style(Severity::Bad);

    assert!(critical.add_modifier.contains(Modifier::BOLD));
    assert!(!good.add_modifier.contains(Modifier::BOLD));
    assert!(!mild.add_modifier.contains(Modifier::BOLD));
    assert!(!bad.add_modifier.contains(Modifier::BOLD));
}

#[test]
fn test_severity_style_fg_matches_severity_color() {
    let theme = Theme::catppuccin_mocha();
    for sev in [
        Severity::Good,
        Severity::Mild,
        Severity::Bad,
        Severity::Critical,
    ] {
        let style = theme.severity_style(sev);
        assert_eq!(
            style.fg,
            Some(theme.severity_color(sev)),
            "severity_style({:?}).fg must equal severity_color({:?})",
            sev,
            sev
        );
    }
}

#[test]
fn test_palette_completeness_per_theme() {
    // For each shipped theme, every NamedColor variant returns *some* color.
    // The Default theme legitimately uses Color::Reset for some background tones,
    // so this test does not blanket-reject Reset; it only verifies that
    // theme.color(N) executes the match without panicking and the field has been
    // assigned (no inadvertent Color::default() leftovers from incomplete
    // construction).
    //
    // This test pins current values transitively via the per-theme
    // `*_palette_pinned` tests; this test specifically guards against future
    // additions to NamedColor that lack per-theme handling. When a new variant
    // is added, the exhaustive match in Theme::color forces an arm; this test
    // ensures the per-theme constructors got updated.
    let themes = [
        ("default", Theme::default()),
        ("nord", Theme::nord()),
        ("dracula", Theme::dracula()),
        ("solarized_dark", Theme::solarized_dark()),
        ("gruvbox_dark", Theme::gruvbox_dark()),
        ("catppuccin_mocha", Theme::catppuccin_mocha()),
    ];
    let all_named = [
        NamedColor::Rosewater,
        NamedColor::Flamingo,
        NamedColor::Pink,
        NamedColor::Mauve,
        NamedColor::Red,
        NamedColor::Maroon,
        NamedColor::Peach,
        NamedColor::Yellow,
        NamedColor::Green,
        NamedColor::Teal,
        NamedColor::Sky,
        NamedColor::Sapphire,
        NamedColor::Blue,
        NamedColor::Lavender,
        NamedColor::Text,
        NamedColor::Subtext1,
        NamedColor::Subtext0,
        NamedColor::Overlay2,
        NamedColor::Overlay1,
        NamedColor::Overlay0,
        NamedColor::Surface2,
        NamedColor::Surface1,
        NamedColor::Surface0,
        NamedColor::Base,
        NamedColor::Mantle,
        NamedColor::Crust,
    ];
    for (name, theme) in &themes {
        for n in &all_named {
            // Just call it; assert each call returns a value (compile guarantee).
            let _ = theme.color(*n);
        }
        // Sanity: at minimum, accent colors should not all be the same value.
        // (Catches a fully-defaulted Palette { ..Default::default() } accident.)
        assert_ne!(
            theme.color(NamedColor::Red),
            theme.color(NamedColor::Green),
            "{}: Red and Green collapsed — palette likely uninitialized",
            name,
        );
    }
}

#[test]
fn test_crate_root_reexports() {
    // Verify the new types are reachable from `envision::*` (compiled-out check).
    // The actual import path is exercised by usage; this test just pins the
    // smoke check.
    use crate::{NamedColor, Palette, Severity};
    let _ = NamedColor::Lavender;
    let _ = Severity::Good;
    // Palette construction is verified in test_palette_struct_construction.
    let _ = std::mem::size_of::<Palette>();
}