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
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
// Resolution inheritance phases: fills None fields from defaults and widget-to-widget chains.
//
// Hand-written inheritance rules (not expressible as simple field <- defaults.field attributes):
//
// 1. defaults_internal (9 rules): ordering-dependent chains between defaults fields
// 2. text_scale inheritance (4 entries): resolve_text_scale_entry() with computed line_height
// 3. safety nets (6 rules): per-platform fallbacks for input.caret_color, scrollbar.track_color, etc.
// 4. widget-to-widget chains (9 rules): depend on resolved font/border, must run after Phase 3
// 5. link.font.color override (1 rule): link.font.color <- defaults.link_color (NOT font.color)
//
// Generated inheritance rules (Phase 94-01 G6 -- this plan):
// - border sub-field inheritance (15 rules): `#[theme_inherit(border_kind = "full"|"full_lg"|"partial")]`
// on each widget struct emits `resolve_border_from_defaults(&DefaultsBorderSpec)` which is
// called by `resolve_border_inheritance` below in deterministic order.
// - font sub-field inheritance (19 rules): `#[theme_inherit(font = "<field>")]` attributes
// emit `resolve_font_from_defaults(&FontSpec)` which is called by `resolve_font_inheritance`.
//
// Generated inheritance rules (Phase 80-02):
// - The ~55 uniform "widget.field <- defaults.field" rules are generated by
// `#[theme(inherit_from = "...")]` attributes on widget struct fields.
use crate::model::font::FontSize;
use crate::model::{DialogButtonOrder, FontSpec, TextScaleEntry, ThemeMode};
/// Resolve a text scale entry from defaults.
/// Creates the entry if None, fills sub-fields from defaults.font,
/// fills None sub-fields from defaults.font, then computes line_height
/// from defaults.line_height * resolved_size.
///
/// Per `inheritance-rules.toml [text_scale_inheritance]`:
/// - size inherits from defaults.font.size
/// - weight inherits from defaults.font.weight
/// - line_height is defaults.line_height * size, in the size's unit
fn resolve_text_scale_entry(
entry: &mut Option<TextScaleEntry>,
defaults_font: &FontSpec,
defaults_line_height: Option<f32>,
) {
let entry = entry.get_or_insert_with(TextScaleEntry::default);
if entry.size.is_none() {
entry.size = defaults_font.size;
}
if entry.weight.is_none() {
entry.weight = defaults_font.weight;
}
if entry.line_height.is_none()
&& let (Some(lh_mult), Some(font_size)) = (defaults_line_height, entry.size)
{
entry.line_height = Some(match font_size {
FontSize::Pt(_) => FontSize::Pt(lh_mult * font_size.raw()),
FontSize::Px(_) => FontSize::Px(lh_mult * font_size.raw()),
});
}
}
/// Return the platform-appropriate dialog button order.
///
/// On Windows and Linux/KDE the convention is leading-affirmative (OK on the
/// left). On GNOME, macOS, and iOS the convention is trailing-affirmative.
/// Windows uses primary-leftmost per the Microsoft Common Buttons guideline
/// and modern WinUI 3 ContentDialog — see
/// `docs/platform-facts.md:1559, 1529-1546, 1861-1862`.
pub(crate) fn platform_button_order() -> DialogButtonOrder {
#[cfg(target_os = "linux")]
{
if crate::detect::detect_linux_desktop() == crate::detect::LinuxDesktop::Kde {
DialogButtonOrder::PrimaryLeft
} else {
// GNOME uses primary-right (trailing-affirmative)
DialogButtonOrder::PrimaryRight
}
}
#[cfg(target_os = "windows")]
{
DialogButtonOrder::PrimaryLeft
}
// macOS, iOS use primary-right (trailing-affirmative)
#[cfg(not(any(target_os = "linux", target_os = "windows")))]
{
DialogButtonOrder::PrimaryRight
}
}
impl ThemeMode {
// --- Phase 1: Defaults internal chains ---
pub(crate) fn resolve_defaults_internal(&mut self) {
let d = &mut self.defaults;
// selection_background <- accent_color
if d.selection_background.is_none() {
d.selection_background = d.accent_color;
}
// focus_ring_color <- accent_color
if d.focus_ring_color.is_none() {
d.focus_ring_color = d.accent_color;
}
// selection_inactive_background <- selection_background (MUST run after selection_background is set)
if d.selection_inactive_background.is_none() {
d.selection_inactive_background = d.selection_background;
}
// text_selection_background <- selection_background (inline text highlight defaults to selection)
if d.text_selection_background.is_none() {
d.text_selection_background = d.selection_background;
}
// text_selection_color <- selection_text_color
if d.text_selection_color.is_none() {
d.text_selection_color = d.selection_text_color;
}
// defaults.font.color <- defaults.text_color
if d.font.color.is_none() {
d.font.color = d.text_color;
}
// defaults.mono_font.color <- defaults.font.color (MUST run AFTER font.color is set)
if d.mono_font.color.is_none() {
d.mono_font.color = d.font.color;
}
}
// --- Phase 2: Safety nets ---
/// Phase 2: Safety nets -- fill widget fields that derive from defaults but
/// are not part of the standard defaults-to-widget inheritance chain.
///
/// These are deterministic derivations (no OS detection):
/// - `input.caret_color` from `defaults.text_color`
/// - `scrollbar.track_color` from `defaults.background_color`
/// - `spinner.fill_color` from `defaults.accent_color`
/// - `popover.background_color` from `defaults.background_color`
/// - `list.background_color` from `defaults.background_color`
/// - `dialog.background_color` from `defaults.background_color`
pub(crate) fn resolve_safety_nets(&mut self) {
// input.caret_color <- defaults.text_color
if self.input.caret_color.is_none() {
self.input.caret_color = self.defaults.text_color;
}
// scrollbar.track <- defaults.background_color
if self.scrollbar.track_color.is_none() {
self.scrollbar.track_color = self.defaults.background_color;
}
// spinner.fill <- defaults.accent_color (all platforms use accent)
if self.spinner.fill_color.is_none() {
self.spinner.fill_color = self.defaults.accent_color;
}
// popover.background <- defaults.background_color
if self.popover.background_color.is_none() {
self.popover.background_color = self.defaults.background_color;
}
// list.background <- defaults.background_color
if self.list.background_color.is_none() {
self.list.background_color = self.defaults.background_color;
}
// dialog.background <- defaults.background_color (per_platform fallback)
if self.dialog.background_color.is_none() {
self.dialog.background_color = self.defaults.background_color;
}
}
// --- Phase 3: Widget-from-defaults ---
pub(crate) fn resolve_widgets_from_defaults(&mut self) {
self.resolve_color_inheritance();
self.resolve_border_inheritance();
self.resolve_font_inheritance();
self.resolve_text_scale();
}
pub(crate) fn resolve_color_inheritance(&mut self) {
// ~55 uniform "widget.field <- defaults.field" rules are generated by
// #[theme(inherit_from)] attributes on widget struct fields.
// Each widget's resolve_from_defaults() is called here at the start of
// Phase 3, after Phase 1 (resolve_defaults_internal) has populated
// derived defaults fields like text_selection_background.
self.window.resolve_from_defaults(&self.defaults);
self.button.resolve_from_defaults(&self.defaults);
self.input.resolve_from_defaults(&self.defaults);
self.checkbox.resolve_from_defaults(&self.defaults);
self.menu.resolve_from_defaults(&self.defaults);
self.tooltip.resolve_from_defaults(&self.defaults);
self.scrollbar.resolve_from_defaults(&self.defaults);
self.slider.resolve_from_defaults(&self.defaults);
self.progress_bar.resolve_from_defaults(&self.defaults);
self.tab.resolve_from_defaults(&self.defaults);
self.sidebar.resolve_from_defaults(&self.defaults);
self.toolbar.resolve_from_defaults(&self.defaults);
self.status_bar.resolve_from_defaults(&self.defaults);
self.list.resolve_from_defaults(&self.defaults);
self.popover.resolve_from_defaults(&self.defaults);
self.splitter.resolve_from_defaults(&self.defaults);
self.separator.resolve_from_defaults(&self.defaults);
self.switch.resolve_from_defaults(&self.defaults);
self.dialog.resolve_from_defaults(&self.defaults);
self.spinner.resolve_from_defaults(&self.defaults);
self.combo_box.resolve_from_defaults(&self.defaults);
self.segmented_control.resolve_from_defaults(&self.defaults);
self.card.resolve_from_defaults(&self.defaults);
self.expander.resolve_from_defaults(&self.defaults);
self.link.resolve_from_defaults(&self.defaults);
}
pub(crate) fn resolve_border_inheritance(&mut self) {
let d = &self.defaults.border;
// 15 rules generated by `#[theme_inherit(border_kind = "...")]` on each
// widget struct. Dispatched here in deterministic declaration order.
// Per docs/archive/v0.5.7_gaps.md §G6 + native-theme-derive/src/gen_inherit.rs
// (Phase 94-01). The resolve_border_from_defaults() method is generated
// per-widget; see `gen_border_inherit` for the emission.
self.window.resolve_border_from_defaults(d); // full_lg
self.button.resolve_border_from_defaults(d); // full
self.input.resolve_border_from_defaults(d); // full
self.checkbox.resolve_border_from_defaults(d); // full
self.tooltip.resolve_border_from_defaults(d); // full
self.progress_bar.resolve_border_from_defaults(d); // full
self.toolbar.resolve_border_from_defaults(d); // full
self.list.resolve_border_from_defaults(d); // full
self.popover.resolve_border_from_defaults(d); // full_lg
self.dialog.resolve_border_from_defaults(d); // full_lg
self.combo_box.resolve_border_from_defaults(d); // full
self.segmented_control.resolve_border_from_defaults(d); // full
self.expander.resolve_border_from_defaults(d); // full
self.sidebar.resolve_border_from_defaults(d); // partial (color + line_width only)
self.status_bar.resolve_border_from_defaults(d); // partial (color + line_width only)
}
pub(crate) fn resolve_font_inheritance(&mut self) {
let d = &self.defaults.font;
// 19 rules generated by `#[theme_inherit(font = "...")]` on each widget
// struct. Dispatched here in deterministic declaration order.
// Per docs/archive/v0.5.7_gaps.md §G6 + native-theme-derive/src/gen_inherit.rs
// (Phase 94-01). See `gen_font_inherit`.
self.window.resolve_font_from_defaults(d); // title_bar_font
self.button.resolve_font_from_defaults(d); // font
self.input.resolve_font_from_defaults(d); // font
self.checkbox.resolve_font_from_defaults(d); // font
self.menu.resolve_font_from_defaults(d); // font
self.tooltip.resolve_font_from_defaults(d); // font
self.tab.resolve_font_from_defaults(d); // font
self.sidebar.resolve_font_from_defaults(d); // font
self.toolbar.resolve_font_from_defaults(d); // font
self.status_bar.resolve_font_from_defaults(d); // font
self.list.resolve_font_from_defaults(d); // item_font + header_font (two attrs)
self.popover.resolve_font_from_defaults(d); // font
self.dialog.resolve_font_from_defaults(d); // title_font + body_font (two attrs)
self.combo_box.resolve_font_from_defaults(d); // font
self.segmented_control.resolve_font_from_defaults(d); // font
self.expander.resolve_font_from_defaults(d); // font
let link_color_stated = self.link.font.as_ref().is_some_and(|f| f.color.is_some());
self.link.resolve_font_from_defaults(d); // font
// Exception: link.font.color inherits from defaults.link_color, NOT
// defaults.font.color. This MUST run AFTER the generic
// resolve_font_from_defaults call above, which fills a None
// link.font.color from defaults.font.color; we replace that fill
// here, and keep a link.font.color the theme stated.
//
// OUT of G6 codegen scope per docs/archive/v0.5.7_gaps.md §G6: the
// override TARGET (a nested sub-field inside an Option FontSpec)
// doesn't compose with the #[theme_inherit(font = ...)] attribute
// grammar which names the whole font field. Staying hand-written
// keeps the rule visible to the `uniform_rules_all_accounted_for`
// drift test.
if !link_color_stated && let Some(ref mut font) = self.link.font {
font.color = self.defaults.link_color;
}
}
pub(crate) fn resolve_text_scale(&mut self) {
let defaults_font = &self.defaults.font;
let defaults_lh = self.defaults.line_height;
resolve_text_scale_entry(&mut self.text_scale.caption, defaults_font, defaults_lh);
resolve_text_scale_entry(
&mut self.text_scale.section_heading,
defaults_font,
defaults_lh,
);
resolve_text_scale_entry(
&mut self.text_scale.dialog_title,
defaults_font,
defaults_lh,
);
resolve_text_scale_entry(&mut self.text_scale.display, defaults_font, defaults_lh);
}
// --- Phase 4: Widget-to-widget chains ---
pub(crate) fn resolve_widget_to_widget(&mut self) {
// inactive title bar <- active title bar
if self.window.inactive_title_bar_background.is_none() {
self.window.inactive_title_bar_background = self.window.title_bar_background;
}
if self.window.inactive_title_bar_text_color.is_none() {
self.window.inactive_title_bar_text_color =
self.window.title_bar_font.as_ref().and_then(|f| f.color);
}
// text_area.border <- input.border (widget-to-widget): the multi-line
// field is framed as the single-line one; its padding alone is its own.
// Must run AFTER resolve_border_inheritance has filled input.border.
if let Some(input) = &self.input.border {
let area = self.text_area.border.get_or_insert_default();
if area.color.is_none() {
area.color = input.color;
}
if area.corner_radius.is_none() {
area.corner_radius = input.corner_radius;
}
if area.line_width.is_none() {
area.line_width = input.line_width;
}
if area.shadow_enabled.is_none() {
area.shadow_enabled = input.shadow_enabled;
}
}
// button.hover_text_color <- button.font.color (widget-to-widget)
// Must run AFTER resolve_font_inheritance has populated button.font.color
if self.button.hover_text_color.is_none() {
self.button.hover_text_color = self.button.font.as_ref().and_then(|f| f.color);
}
// button.active_text_color <- button.font.color (widget-to-widget)
if self.button.active_text_color.is_none() {
self.button.active_text_color = self.button.font.as_ref().and_then(|f| f.color);
}
// tab.hover_text_color <- tab.font.color (widget-to-widget)
if self.tab.hover_text_color.is_none() {
self.tab.hover_text_color = self.tab.font.as_ref().and_then(|f| f.color);
}
// list.hover_background <- list.background_color and
// sidebar.hover_background <- sidebar.background_color (widget-to-widget):
// an unstated hover is no tint, the row's own fill, where no source
// gives the platform's (macOS, docs/platform-facts.md §2.12, §2.15).
// Must run AFTER resolve_widgets_from_defaults has filled each
// background_color.
if self.list.hover_background.is_none() {
self.list.hover_background = self.list.background_color;
}
if self.sidebar.hover_background.is_none() {
self.sidebar.hover_background = self.sidebar.background_color;
}
// list.hover_text_color <- list.item_font.color (widget-to-widget)
if self.list.hover_text_color.is_none() {
self.list.hover_text_color = self.list.item_font.as_ref().and_then(|f| f.color);
}
// splitter.hover_color <- splitter.divider_color (widget-to-widget)
if self.splitter.hover_color.is_none() {
self.splitter.hover_color = self.splitter.divider_color;
}
// link.hover_text_color <- link.font.color (widget-to-widget)
if self.link.hover_text_color.is_none() {
self.link.hover_text_color = self.link.font.as_ref().and_then(|f| f.color);
}
// link.active_text_color <- link.font.color (widget-to-widget)
if self.link.active_text_color.is_none() {
self.link.active_text_color = self.link.font.as_ref().and_then(|f| f.color);
}
}
}
#[cfg(test)]
#[allow(clippy::expect_used)]
mod tests {
/// Verify that every rule in inheritance-rules.toml [defaults_internal] section
/// is covered by the hand-written implementation in this file.
///
/// This test catches drift: if someone adds a rule to the TOML but forgets
/// to implement it in Rust, this test fails.
#[test]
fn inheritance_rules_toml_covers_defaults_internal() {
let toml_str = include_str!("../../../docs/inheritance-rules.toml");
let table: toml::Table = toml_str.parse().expect("valid TOML");
// [defaults_internal] section
let defaults_internal = table
.get("defaults_internal")
.and_then(|v| v.as_table())
.expect("[defaults_internal] section exists");
// These are the fields that resolve_defaults_internal() handles.
// If a new rule is added to the TOML, add the target field here too.
let implemented_targets: &[&str] = &[
"defaults.selection_background",
"defaults.focus_ring_color",
"defaults.selection_inactive_background",
"defaults.text_selection_background",
"defaults.text_selection_color",
"defaults.font.color",
"defaults.mono_font.color",
];
for key in defaults_internal.keys() {
assert!(
implemented_targets.contains(&key.as_str()),
"inheritance-rules.toml [defaults_internal] has rule '{key}' \
but it is not listed in inheritance.rs implemented_targets. \
Either implement the rule or add it to the list."
);
}
// Reverse check: every implemented target should be in the TOML
for &target in implemented_targets {
assert!(
defaults_internal.contains_key(target),
"inheritance.rs claims to implement '{target}' but it is not \
in inheritance-rules.toml [defaults_internal]"
);
}
}
/// Helper: parse inheritance-rules.toml once.
fn load_rules_toml() -> toml::Table {
let toml_str = include_str!("../../../docs/inheritance-rules.toml");
toml_str.parse().expect("valid TOML")
}
/// Helper: extract a string array from a TOML value.
fn toml_string_array(val: &toml::Value) -> Vec<String> {
val.as_array()
.expect("expected array")
.iter()
.map(|v| v.as_str().expect("expected string").to_string())
.collect()
}
/// Helper: assert bidirectional coverage between a TOML key set and an explicit list.
fn assert_bidirectional(section_name: &str, toml_keys: &[String], implemented: &[&str]) {
for key in toml_keys {
assert!(
implemented.contains(&key.as_str()),
"[{section_name}] TOML has '{key}' but it is not in the implemented list. \
Either implement the rule or add it to the test."
);
}
for &target in implemented {
assert!(
toml_keys.iter().any(|k| k == target),
"[{section_name}] implementation claims '{target}' but it is not in the TOML."
);
}
}
// --- [border_inheritance] bidirectional ---
// --- [border_inheritance] INVERTED drift test (Phase 94-01 G6) ---
//
// Post-G6 direction: the macro-emitted BorderInheritanceInfo registry is
// the source of truth for which widgets inherit border sub-fields from
// defaults.border. docs/inheritance-rules.toml is a generated-documentation
// output that must match the registry. If they diverge, the fix is to
// regenerate the TOML from the registry — NOT to edit the TOML by hand.
//
// Renamed from `border_inheritance_widgets_match_toml` /
// `border_inheritance_lg_widgets_match_toml` (pre-G6 direction) to make
// the ownership direction explicit in the test name.
//
// Includes silent-green guards (non-empty inventory + count-lower-bound)
// to reject the failure mode where an empty registry would silently
// byte-equal an empty toml array. See Phase 93-09 IconLoader precedent.
#[test]
fn border_inheritance_toml_matches_macro_emit() {
// Collect widget names from the inventory registry for full + full_lg
// kinds (these are the `widgets_with_border` entries in the TOML).
// Partial widgets (sidebar, status_bar) are NOT part of
// widgets_with_border since they don't inherit all 4 sub-fields.
let mut gen_full: Vec<String> = inventory::iter::<crate::resolve::BorderInheritanceInfo>()
.filter(|i| i.kind == "full" || i.kind == "full_lg")
.map(|i| i.widget_name.to_string())
.collect();
gen_full.sort();
gen_full.dedup();
// Silent-green guards.
let all_count = inventory::iter::<crate::resolve::BorderInheritanceInfo>().count();
assert!(
all_count > 0,
"BorderInheritanceInfo inventory is empty. Silent-green bug: \
either widget structs are missing #[theme_inherit(border_kind=...)] \
attributes (plan 94-01 Task 3 Step A) or the proc-macro is not \
emitting inventory::submit! (plan 94-01 Task 2 Step B.3)."
);
assert!(
all_count >= 15,
"Expected >=15 border widgets (13 full + 2 partial), got {all_count}"
);
assert!(
!gen_full.is_empty(),
"full+full_lg subset of BorderInheritanceInfo is empty — silent-green bug."
);
let table = load_rules_toml();
let section = table
.get("border_inheritance")
.and_then(|v| v.as_table())
.expect("[border_inheritance] section exists");
let mut toml_full: Vec<String> = toml_string_array(
section
.get("widgets_with_border")
.expect("widgets_with_border key"),
);
toml_full.sort();
assert_eq!(
gen_full, toml_full,
"widgets_with_border in docs/inheritance-rules.toml diverges from \
macro-emitted BorderInheritanceInfo registry. If the macro is \
authoritative (post-G6), regenerate the TOML section. \
If the TOML should win, change the widget struct's \
#[theme_inherit(border_kind = ...)] attribute."
);
// Now assert corner_radius_lg_widgets matches the FullLg subset.
let mut gen_lg: Vec<String> = inventory::iter::<crate::resolve::BorderInheritanceInfo>()
.filter(|i| i.kind == "full_lg")
.map(|i| i.widget_name.to_string())
.collect();
gen_lg.sort();
gen_lg.dedup();
let mut toml_lg: Vec<String> = toml_string_array(
section
.get("corner_radius_lg_widgets")
.expect("corner_radius_lg_widgets key"),
);
toml_lg.sort();
assert_eq!(
gen_lg, toml_lg,
"corner_radius_lg_widgets diverges from BorderInheritanceInfo (kind=\"full_lg\")"
);
}
// --- [font_inheritance] INVERTED drift test (Phase 94-01 G6) ---
#[test]
fn font_inheritance_toml_matches_macro_emit() {
// Build widgets_with_font entries as "<widget>.<font_field>" strings,
// sorted for deterministic comparison against the TOML array.
let mut generated: Vec<String> = inventory::iter::<crate::resolve::FontInheritanceInfo>()
.map(|i| format!("{}.{}", i.widget_name, i.font_field))
.collect();
generated.sort();
// Silent-green guards.
assert!(
!generated.is_empty(),
"FontInheritanceInfo inventory is empty. Silent-green bug: \
either widget structs are missing #[theme_inherit(font=...)] \
attributes or the proc-macro is not emitting inventory::submit!."
);
assert!(
generated.len() >= 19,
"Expected >=19 font widgets (15 single + 2 list-double + 2 \
dialog-double), got {}",
generated.len()
);
let table = load_rules_toml();
let section = table
.get("font_inheritance")
.and_then(|v| v.as_table())
.expect("[font_inheritance] section exists");
let mut toml_fonts: Vec<String> = toml_string_array(
section
.get("widgets_with_font")
.expect("widgets_with_font key"),
);
toml_fonts.sort();
assert_eq!(
generated, toml_fonts,
"widgets_with_font in docs/inheritance-rules.toml diverges from \
macro-emitted FontInheritanceInfo registry. Regenerate the TOML \
if the macro is authoritative (post-G6)."
);
}
// --- Regression guard: list.alternate_row_background NOT derived ---
//
// The rule `list.alternate_row_background <- list.background_color` was
// deprecated (see docs/inheritance-rules.toml
// `[wrong_safety_nets."list.alternate_row_background"]`;
// `why_wrong = "Alternate rows are always a tinted variant"`).
// Post-G6 it must NOT be re-introduced into any inheritance category.
// Presets provide this field explicitly; no resolver populates it.
#[test]
fn list_alternate_row_background_not_derived() {
let src = include_str!("../resolve/inheritance.rs");
// Count occurrences of "alternate_row_background" INSIDE the
// resolve_widget_to_widget function body. Expected: zero — the
// widget-to-widget rules are 11 field rules (2 window, 2 button,
// 1 tab, 1 list hover_background, 1 sidebar hover_background, 1 list
// hover_text_color, 1 splitter, 2 link) and the text_area.border
// block, which takes its 4 unstated fields from input.border. None
// touch alternate_row_background.
//
// Zero-panic: the split chain can return None if the function
// signature is renamed — in which case the assertion should FAIL
// loudly rather than skip (the source-scan invariant is lost).
// No invented fallback value; we expect the split to succeed or
// expect() to fail the test with a clear message.
let after_sig = src.split("fn resolve_widget_to_widget").nth(1).expect(
"resolve_widget_to_widget function must exist in inheritance.rs — \
test must be updated if the function is renamed",
);
let body = after_sig
.split("fn ")
.next()
.expect("split of non-empty string always yields at least one element");
let occurrences = body.matches("alternate_row_background").count();
assert_eq!(
occurrences, 0,
"list.alternate_row_background must NOT appear in \
resolve_widget_to_widget. Rule is deprecated per \
docs/inheritance-rules.toml [wrong_safety_nets]. \
Presets must provide this field explicitly."
);
}
// --- [per_platform] bidirectional (safety nets) ---
#[test]
fn per_platform_rules_match_safety_nets() {
let table = load_rules_toml();
let section = table
.get("per_platform")
.and_then(|v| v.as_table())
.expect("[per_platform] section exists");
let toml_keys: Vec<String> = section.keys().cloned().collect();
// These are the fields that resolve_safety_nets() fills.
let implemented_safety_nets: &[&str] = &[
"input.caret_color",
"scrollbar.track_color",
"spinner.fill_color",
"popover.background_color",
"list.background_color",
"dialog.background_color",
];
assert_bidirectional("per_platform", &toml_keys, implemented_safety_nets);
}
// --- [text_scale_inheritance] bidirectional ---
#[test]
fn text_scale_entries_match_toml() {
let table = load_rules_toml();
let section = table
.get("text_scale_inheritance")
.and_then(|v| v.as_table())
.expect("[text_scale_inheritance] section exists");
let toml_entries = toml_string_array(section.get("entries").expect("entries key"));
// These are the entries that resolve_text_scale() processes.
let implemented_entries: &[&str] =
&["caption", "section_heading", "dialog_title", "display"];
assert_bidirectional(
"text_scale_inheritance.entries",
&toml_entries,
implemented_entries,
);
}
// --- [uniform] rules and their sources ---
//
// The [uniform] section contains rules implemented across multiple phases.
// Every rule's key and source are compared against the implementation:
// - proc-macro-generated rules (via #[theme(inherit_from = "...")]) — Phase 3:
// against the UniformInheritanceInfo registry
// - partial border rules (sidebar/status_bar) — Phase 3: against the
// BorderInheritanceInfo registry's `partial` rows
// - widget-to-widget rules — Phase 4, and the font color override
// (link.font.color) — Phase 3: hand-written, so listed below
#[test]
fn uniform_rules_all_accounted_for() {
use std::collections::BTreeMap;
let table = load_rules_toml();
let section = table
.get("uniform")
.and_then(|v| v.as_table())
.expect("[uniform] section exists");
let toml_rules: BTreeMap<String, String> = section
.iter()
.map(|(key, source)| {
let source = source.as_str().expect("[uniform] sources are strings");
(key.clone(), source.to_string())
})
.collect();
// Every [uniform] rule must appear in exactly one of these categories.
let mut implemented: Vec<(String, String)> = Vec::new();
// Category 1: proc-macro generated via #[theme(inherit_from = "defaults.*")],
// implemented by resolve_from_defaults() on each widget struct.
let macro_rules: Vec<(String, String)> =
inventory::iter::<crate::resolve::UniformInheritanceInfo>()
.map(|i| {
(
format!("{}.{}", i.widget_name, i.field),
i.inherit_from.to_string(),
)
})
.collect();
assert!(
macro_rules.len() >= 65,
"Expected >=65 inherit_from rows in UniformInheritanceInfo, got {}. \
Silent-green guard: the proc-macro may not be emitting inventory::submit!.",
macro_rules.len()
);
implemented.extend(macro_rules);
// Category 2: partial border rules (resolve_border_inheritance, Phase 3),
// the color + line_width that gen_border_inherit's `partial` kind fills.
let partial: Vec<&str> = inventory::iter::<crate::resolve::BorderInheritanceInfo>()
.filter(|i| i.kind == "partial")
.map(|i| i.widget_name)
.collect();
assert!(
!partial.is_empty(),
"no `partial` rows in BorderInheritanceInfo"
);
for widget in partial {
for sub in ["color", "line_width"] {
implemented.push((
format!("{widget}.border.{sub}"),
format!("defaults.border.{sub}"),
));
}
}
// Category 3: hand-written rules — widget-to-widget chains
// (resolve_widget_to_widget, Phase 4) and the link.font.color override
// (resolve_font_inheritance, Phase 3).
let hand_written_rules: &[(&str, &str)] = &[
(
"window.inactive_title_bar_background",
"window.title_bar_background",
),
(
"window.inactive_title_bar_text_color",
"window.title_bar_font.color",
),
("text_area.border.color", "input.border.color"),
(
"text_area.border.corner_radius",
"input.border.corner_radius",
),
("text_area.border.line_width", "input.border.line_width"),
(
"text_area.border.shadow_enabled",
"input.border.shadow_enabled",
),
("button.hover_text_color", "button.font.color"),
("button.active_text_color", "button.font.color"),
("tab.hover_text_color", "tab.font.color"),
("list.hover_background", "list.background_color"),
("sidebar.hover_background", "sidebar.background_color"),
("list.hover_text_color", "list.item_font.color"),
("splitter.hover_color", "splitter.divider_color"),
("link.hover_text_color", "link.font.color"),
("link.active_text_color", "link.font.color"),
("link.font.color", "defaults.link_color"),
];
for &(target, source) in hand_written_rules {
implemented.push((target.to_string(), source.to_string()));
}
let mut drift: Vec<String> = Vec::new();
let mut code_rules: BTreeMap<String, String> = BTreeMap::new();
for (target, source) in implemented {
if code_rules.insert(target.clone(), source).is_some() {
drift.push(format!("'{target}' is implemented in two categories"));
}
}
for (target, source) in &toml_rules {
match code_rules.get(target) {
None => drift.push(format!(
"TOML has '{target}' = '{source}' but no implementation category does"
)),
Some(code) if code != source => drift.push(format!(
"'{target}': TOML says '{source}', the implementation '{code}'"
)),
Some(_) => {}
}
}
for (target, source) in &code_rules {
if !toml_rules.contains_key(target) {
drift.push(format!(
"implementation has '{target}' = '{source}' but the TOML does not"
));
}
}
assert!(
drift.is_empty(),
"[uniform] in docs/inheritance-rules.toml diverges from the implementation:\n{}",
drift.join("\n")
);
}
// --- [no_inheritance] negative check ---
//
// Fields in [no_inheritance] must NEVER appear as inheritance targets in any
// of the implemented rule lists above.
#[test]
fn no_inheritance_fields_are_not_inherited() {
let table = load_rules_toml();
let section = table
.get("no_inheritance")
.and_then(|v| v.as_table())
.expect("[no_inheritance] section exists");
let no_inherit_fields = toml_string_array(section.get("fields").expect("fields key"));
// Gather ALL implemented inheritance targets across all phases.
// If any no_inheritance field appears here, we have a bug.
let mut all_inherited_targets: Vec<String> = vec![
// defaults_internal (Phase 1)
"defaults.selection_background".into(),
"defaults.focus_ring_color".into(),
"defaults.selection_inactive_background".into(),
"defaults.text_selection_background".into(),
"defaults.text_selection_color".into(),
"defaults.font.color".into(),
"defaults.mono_font.color".into(),
// safety nets (Phase 2) — target fields
"input.caret_color".into(),
"scrollbar.track_color".into(),
"spinner.fill_color".into(),
"popover.background_color".into(),
"list.background_color".into(),
"dialog.background_color".into(),
// widget-to-widget (Phase 4)
"window.inactive_title_bar_background".into(),
"window.inactive_title_bar_text_color".into(),
"button.hover_text_color".into(),
"button.active_text_color".into(),
"tab.hover_text_color".into(),
"list.hover_text_color".into(),
"splitter.hover_color".into(),
"link.hover_text_color".into(),
"link.active_text_color".into(),
"list.alternate_row_background".into(),
// link.font.color override
"link.font.color".into(),
];
// Post-G6 extension: dynamically pull border + font inheritance targets
// from the BorderInheritanceInfo / FontInheritanceInfo registries so the
// negative check auto-extends when new widgets declare #[theme_inherit].
//
// Compile-probe: referencing these types guarantees the test fails at
// COMPILE TIME (not as a silent-green PASS) before Task 2 ships the
// registry types. See Phase 93-09 IconLoader silent-ignore precedent.
let _border_registry_type_probe: Option<&crate::resolve::BorderInheritanceInfo> = None;
let _font_registry_type_probe: Option<&crate::resolve::FontInheritanceInfo> = None;
for info in inventory::iter::<crate::resolve::BorderInheritanceInfo>() {
// widget.border.color / .corner_radius / .line_width / .shadow_enabled
all_inherited_targets.push(format!("{}.border.color", info.widget_name));
all_inherited_targets.push(format!("{}.border.line_width", info.widget_name));
// full + full_lg widgets also target corner_radius and shadow_enabled;
// partial widgets target only color + line_width (both already added).
if info.kind == "full" || info.kind == "full_lg" {
all_inherited_targets.push(format!("{}.border.corner_radius", info.widget_name));
all_inherited_targets.push(format!("{}.border.shadow_enabled", info.widget_name));
}
}
for info in inventory::iter::<crate::resolve::FontInheritanceInfo>() {
// widget.<font_field>.family / .size / .weight / .style / .color
let prefix = format!("{}.{}", info.widget_name, info.font_field);
for sub in ["family", "size", "weight", "style", "color"] {
all_inherited_targets.push(format!("{prefix}.{sub}"));
}
}
for field in &no_inherit_fields {
assert!(
!all_inherited_targets.iter().any(|t| t == field),
"[no_inheritance] field '{field}' is listed as no-inherit but appears \
in an inheritance target list. Either remove the inheritance rule or \
remove the field from [no_inheritance]."
);
}
}
// ═════════════════════════════════════════════════════════════════════════
// G6 RED tests (Phase 94-01 Task 1) — regression guards for the new codegen
// path that migrates 34 inheritance rules from hand-written code to
// `#[theme_inherit(...)]` struct-level attributes on the widget structs.
//
// Before Task 2+3 land, these tests MUST fail AT COMPILE TIME (not with
// runtime empty-vec PASS). Structural compile-probes are spelled out
// explicitly below. Silent-green PASS via empty inventory is the bug class
// Phase 93-09 (IconLoader typed-per-set refactor) was chartered to prevent;
// the `let _registry_type_exists: Option<&crate::resolve::X> = None;` line
// AND the `assert!(!generated.is_empty(), ...)` runtime guard are the two
// independent defences that together rule out the silent-green failure mode.
//
// See docs/archive/v0.5.7_planning-decision-log.md, phase 94 entries.
// ═════════════════════════════════════════════════════════════════════════
/// Sentinel helper: a non-default DefaultsBorderSpec with unique values
/// for every field, used to distinguish "inherited from defaults" from
/// "pre-existing widget value" in the dispatch tests below.
fn sentinel_defaults_border() -> crate::model::border::DefaultsBorderSpec {
crate::model::border::DefaultsBorderSpec {
color: Some(crate::Rgba::new(255, 0, 0, 255)), // RED
corner_radius: Some(9.0),
corner_radius_lg: Some(13.0),
line_width: Some(2.0),
opacity: Some(1.0),
shadow_enabled: Some(true),
}
}
/// Sentinel helper: a non-default FontSpec with unique values for every
/// sub-field, used to verify the font codegen populates every sub-field.
fn sentinel_defaults_font() -> crate::model::FontSpec {
crate::model::FontSpec {
family: Some(std::sync::Arc::from("TestMono")),
size: Some(crate::model::font::FontSize::Pt(13.0)),
weight: Some(500),
style: Some(crate::model::font::FontStyle::Italic),
color: Some(crate::Rgba::new(0, 0, 255, 255)), // BLUE
}
}
/// Test 1 (RED): the generated `resolve_border_from_defaults` methods
/// must exist on every widget that declares `#[theme_inherit(border_kind)]`.
///
/// Before Task 2 lands: compile fails with "no method named
/// resolve_border_from_defaults found for struct ButtonTheme ...".
/// After Task 3 lands: all 15 widgets populate their border correctly.
#[test]
fn border_codegen_dispatch_matches_runtime() {
let mut mode = crate::model::ThemeMode::default();
mode.defaults.border = sentinel_defaults_border();
// Direct-invoke compile-probe: referencing the method on one widget
// forces Task 2 to exist. If the method is missing, this line fails
// to compile. (Empty-vec / runtime fallbacks cannot silently PASS.)
mode.button
.resolve_border_from_defaults(&mode.defaults.border);
let button_border = mode
.button
.border
.as_ref()
.expect("button.border populated");
assert_eq!(button_border.color, Some(crate::Rgba::new(255, 0, 0, 255)));
assert_eq!(button_border.corner_radius, Some(9.0));
assert_eq!(button_border.line_width, Some(2.0));
assert_eq!(button_border.shadow_enabled, Some(true));
// End-to-end dispatch: resolve_border_inheritance must call the generated
// methods on all 15 widgets. Reset and re-run via the public entry.
let mut mode = crate::model::ThemeMode::default();
mode.defaults.border = sentinel_defaults_border();
mode.resolve_border_inheritance();
// 10 "full" widgets: color, corner_radius, line_width, shadow_enabled all
// inherited from defaults.border (non-lg variant).
let full_widgets: &[(&str, &Option<crate::model::border::WidgetBorderSpec>)] = &[
("button", &mode.button.border),
("input", &mode.input.border),
("checkbox", &mode.checkbox.border),
("tooltip", &mode.tooltip.border),
("progress_bar", &mode.progress_bar.border),
("toolbar", &mode.toolbar.border),
("list", &mode.list.border),
("combo_box", &mode.combo_box.border),
("segmented_control", &mode.segmented_control.border),
("expander", &mode.expander.border),
];
for (name, border_opt) in full_widgets {
let b = border_opt
.as_ref()
.unwrap_or_else(|| panic!("{name}.border must be populated"));
assert_eq!(
b.color,
Some(crate::Rgba::new(255, 0, 0, 255)),
"{name}.border.color"
);
assert_eq!(b.corner_radius, Some(9.0), "{name}.border.corner_radius");
assert_eq!(b.line_width, Some(2.0), "{name}.border.line_width");
assert_eq!(b.shadow_enabled, Some(true), "{name}.border.shadow_enabled");
}
// 3 "full_lg" widgets: corner_radius comes from corner_radius_lg (13.0), not 9.0.
let lg_widgets: &[(&str, &Option<crate::model::border::WidgetBorderSpec>)] = &[
("window", &mode.window.border),
("popover", &mode.popover.border),
("dialog", &mode.dialog.border),
];
for (name, border_opt) in lg_widgets {
let b = border_opt
.as_ref()
.unwrap_or_else(|| panic!("{name}.border must be populated"));
assert_eq!(
b.color,
Some(crate::Rgba::new(255, 0, 0, 255)),
"{name}.border.color"
);
assert_eq!(
b.corner_radius,
Some(13.0),
"{name}.border.corner_radius (lg)"
);
assert_eq!(b.line_width, Some(2.0), "{name}.border.line_width");
assert_eq!(b.shadow_enabled, Some(true), "{name}.border.shadow_enabled");
}
// 2 "partial" widgets: only color + line_width inherited; corner_radius
// and shadow_enabled remain None.
let partial_widgets: &[(&str, &Option<crate::model::border::WidgetBorderSpec>)] = &[
("sidebar", &mode.sidebar.border),
("status_bar", &mode.status_bar.border),
];
for (name, border_opt) in partial_widgets {
let b = border_opt
.as_ref()
.unwrap_or_else(|| panic!("{name}.border must be populated"));
assert_eq!(
b.color,
Some(crate::Rgba::new(255, 0, 0, 255)),
"{name}.border.color"
);
assert_eq!(b.line_width, Some(2.0), "{name}.border.line_width");
assert_eq!(
b.corner_radius, None,
"{name}.border.corner_radius (partial)"
);
assert_eq!(
b.shadow_enabled, None,
"{name}.border.shadow_enabled (partial)"
);
}
}
/// Test 2 (RED): the generated `resolve_font_from_defaults` methods must
/// exist on every widget that declares `#[theme_inherit(font = "...")]`.
///
/// Before Task 2 lands: compile fails with "no method named
/// resolve_font_from_defaults found for struct ButtonTheme ...".
/// After Task 3 lands: all 19 widget fonts populate correctly, including
/// list (two fonts), dialog (two fonts), and link (color-override exception).
#[test]
fn font_codegen_dispatch_matches_runtime() {
let mut mode = crate::model::ThemeMode::default();
mode.defaults.font = sentinel_defaults_font();
// Ensure link.font.color override has a distinct value to verify.
mode.defaults.link_color = Some(crate::Rgba::new(0, 255, 0, 255)); // GREEN
// Direct-invoke compile-probe on Button.
mode.button.resolve_font_from_defaults(&mode.defaults.font);
let button_font = mode.button.font.as_ref().expect("button.font populated");
assert_eq!(
button_font.family.as_deref(),
Some("TestMono"),
"button.font.family"
);
assert_eq!(
button_font.size,
Some(crate::model::font::FontSize::Pt(13.0)),
"button.font.size"
);
assert_eq!(button_font.weight, Some(500), "button.font.weight");
assert_eq!(
button_font.style,
Some(crate::model::font::FontStyle::Italic),
"button.font.style"
);
assert_eq!(
button_font.color,
Some(crate::Rgba::new(0, 0, 255, 255)),
"button.font.color"
);
// End-to-end dispatch via resolve_font_inheritance.
let mut mode = crate::model::ThemeMode::default();
mode.defaults.font = sentinel_defaults_font();
mode.defaults.link_color = Some(crate::Rgba::new(0, 255, 0, 255)); // GREEN
mode.resolve_font_inheritance();
// Helper: assert a font matches the sentinel values (with configurable expected color).
let assert_font =
|font: &crate::model::FontSpec, name: &str, expected_color: crate::Rgba| {
assert_eq!(font.family.as_deref(), Some("TestMono"), "{name}.family");
assert_eq!(
font.size,
Some(crate::model::font::FontSize::Pt(13.0)),
"{name}.size"
);
assert_eq!(font.weight, Some(500), "{name}.weight");
assert_eq!(
font.style,
Some(crate::model::font::FontStyle::Italic),
"{name}.style"
);
assert_eq!(font.color, Some(expected_color), "{name}.color");
};
let blue = crate::Rgba::new(0, 0, 255, 255);
// 15 widgets use the .font field populated from defaults.font.
assert_font(
mode.window
.title_bar_font
.as_ref()
.expect("window.title_bar_font populated"),
"window.title_bar_font",
blue,
);
assert_font(
mode.button.font.as_ref().expect("button.font"),
"button.font",
blue,
);
assert_font(
mode.input.font.as_ref().expect("input.font"),
"input.font",
blue,
);
assert_font(
mode.checkbox.font.as_ref().expect("checkbox.font"),
"checkbox.font",
blue,
);
assert_font(
mode.menu.font.as_ref().expect("menu.font"),
"menu.font",
blue,
);
assert_font(
mode.tooltip.font.as_ref().expect("tooltip.font"),
"tooltip.font",
blue,
);
assert_font(mode.tab.font.as_ref().expect("tab.font"), "tab.font", blue);
assert_font(
mode.sidebar.font.as_ref().expect("sidebar.font"),
"sidebar.font",
blue,
);
assert_font(
mode.toolbar.font.as_ref().expect("toolbar.font"),
"toolbar.font",
blue,
);
assert_font(
mode.status_bar.font.as_ref().expect("status_bar.font"),
"status_bar.font",
blue,
);
assert_font(
mode.popover.font.as_ref().expect("popover.font"),
"popover.font",
blue,
);
assert_font(
mode.combo_box.font.as_ref().expect("combo_box.font"),
"combo_box.font",
blue,
);
assert_font(
mode.segmented_control
.font
.as_ref()
.expect("segmented_control.font"),
"segmented_control.font",
blue,
);
assert_font(
mode.expander.font.as_ref().expect("expander.font"),
"expander.font",
blue,
);
// List has TWO font fields: item_font AND header_font.
assert_font(
mode.list
.item_font
.as_ref()
.expect("list.item_font populated"),
"list.item_font",
blue,
);
assert_font(
mode.list
.header_font
.as_ref()
.expect("list.header_font populated"),
"list.header_font",
blue,
);
// Dialog has TWO font fields: title_font AND body_font.
assert_font(
mode.dialog
.title_font
.as_ref()
.expect("dialog.title_font populated"),
"dialog.title_font",
blue,
);
assert_font(
mode.dialog
.body_font
.as_ref()
.expect("dialog.body_font populated"),
"dialog.body_font",
blue,
);
// Link has the color override exception: link.font.color = defaults.link_color
// (GREEN), NOT defaults.font.color (BLUE). Other sub-fields inherit normally.
let link_font = mode.link.font.as_ref().expect("link.font populated");
assert_eq!(
link_font.family.as_deref(),
Some("TestMono"),
"link.font.family"
);
assert_eq!(
link_font.size,
Some(crate::model::font::FontSize::Pt(13.0)),
"link.font.size"
);
assert_eq!(link_font.weight, Some(500), "link.font.weight");
assert_eq!(
link_font.style,
Some(crate::model::font::FontStyle::Italic),
"link.font.style"
);
assert_eq!(
link_font.color,
Some(crate::Rgba::new(0, 255, 0, 255)),
"link.font.color (OVERRIDE: from link_color, NOT font.color)"
);
}
/// Test 3 (RED): the `BorderInheritanceInfo` inventory registry must
/// exist and be populated post-Task-3.
///
/// The compile-probe `let _registry_type_exists: Option<&crate::resolve::BorderInheritanceInfo> = None;`
/// guarantees the test FAILS at COMPILE TIME before Task 2 defines the type.
/// The `assert!(!generated.is_empty(), ...)` guard guarantees silent-green
/// PASS via empty inventory is rejected post-Task-3 (Phase 93-09 precedent).
#[test]
fn border_inheritance_registry_is_populated_and_matches_toml() {
// Compile-probe: references the type path directly. Before Task 2,
// this line fails to compile with `unresolved path`.
let _registry_type_exists: Option<&crate::resolve::BorderInheritanceInfo> = None;
// Collect widget names for full + full_lg + partial kinds (the
// widgets_with_border TOML array covers all border-inheriting widgets).
let mut generated: Vec<&str> = inventory::iter::<crate::resolve::BorderInheritanceInfo>()
.map(|i| i.widget_name)
.collect();
generated.sort();
generated.dedup();
// Silent-green guard: post-Task-3 the inventory must be non-empty.
// An empty vec passing byte-equal against empty toml_sorted would
// silently PASS — reject that failure mode explicitly.
assert!(
!generated.is_empty(),
"BorderInheritanceInfo inventory is empty post-Task-3. Silent-green bug: \
either widget structs are missing #[theme_inherit(border_kind=...)] \
attributes (Task 3 Step A) or the proc-macro is not emitting \
inventory::submit! (Task 2 Step B.3)."
);
assert!(
generated.len() >= 15,
"Expected >=15 border widgets (13 full + 2 partial, full_lg subset of full), got {}",
generated.len()
);
let table = load_rules_toml();
let section = table
.get("border_inheritance")
.and_then(|v| v.as_table())
.expect("[border_inheritance] section exists");
// full + full_lg widgets from TOML
let mut toml_full: Vec<String> = toml_string_array(
section
.get("widgets_with_border")
.expect("widgets_with_border key"),
);
toml_full.sort();
// Generated full + full_lg widgets from inventory (kind = "full" | "full_lg")
let mut gen_full: Vec<String> = inventory::iter::<crate::resolve::BorderInheritanceInfo>()
.filter(|i| i.kind == "full" || i.kind == "full_lg")
.map(|i| i.widget_name.to_string())
.collect();
gen_full.sort();
gen_full.dedup();
assert_eq!(
gen_full, toml_full,
"widgets_with_border in docs/inheritance-rules.toml diverges from \
macro-emitted BorderInheritanceInfo registry."
);
// corner_radius_lg widgets from TOML
let mut toml_lg: Vec<String> = toml_string_array(
section
.get("corner_radius_lg_widgets")
.expect("corner_radius_lg_widgets key"),
);
toml_lg.sort();
let mut gen_lg: Vec<String> = inventory::iter::<crate::resolve::BorderInheritanceInfo>()
.filter(|i| i.kind == "full_lg")
.map(|i| i.widget_name.to_string())
.collect();
gen_lg.sort();
gen_lg.dedup();
assert_eq!(
gen_lg, toml_lg,
"corner_radius_lg_widgets diverges from BorderInheritanceInfo (kind=\"full_lg\")"
);
}
/// Test 4 (RED): the `FontInheritanceInfo` inventory registry must exist
/// and be populated post-Task-3.
///
/// Symmetric to Test 3 for font inheritance. Compile-probe plus non-empty
/// assertion rules out silent-green PASS via empty inventory.
#[test]
fn font_inheritance_registry_is_populated_and_matches_toml() {
// Compile-probe.
let _registry_type_exists: Option<&crate::resolve::FontInheritanceInfo> = None;
let mut generated: Vec<String> = inventory::iter::<crate::resolve::FontInheritanceInfo>()
.map(|i| format!("{}.{}", i.widget_name, i.font_field))
.collect();
generated.sort();
// Silent-green guard.
assert!(
!generated.is_empty(),
"FontInheritanceInfo inventory is empty post-Task-3. Silent-green bug."
);
assert!(
generated.len() >= 19,
"Expected >=19 font widgets (15 single + 2 list-double + 2 dialog-double), got {}",
generated.len()
);
let table = load_rules_toml();
let section = table
.get("font_inheritance")
.and_then(|v| v.as_table())
.expect("[font_inheritance] section exists");
let mut toml_fonts: Vec<String> = toml_string_array(
section
.get("widgets_with_font")
.expect("widgets_with_font key"),
);
toml_fonts.sort();
assert_eq!(
generated, toml_fonts,
"widgets_with_font in docs/inheritance-rules.toml diverges from \
macro-emitted FontInheritanceInfo registry."
);
}
}