makeover-layout 0.52.1

The renderer-agnostic half of the make-family design system: what a thing IS, named as intents and relationships and never as values. Colour defers to makeover, spacing to makeover-geometry; what is left is composition, plus which affordances exist at a given input class and window size.
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
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
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
//! The crate's own tests, in the file the crate's `mod tests;` names.
//!
//! Moved out of `lib.rs` whole: the root is a facade of `pub use` lines, and
//! 2,000 lines of tests under 250 lines of re-exports made the facade the
//! smaller half of the file that declares it.

use super::{Change, Intent as _, Syntax};

/// Every name a caller is told to use, reached through the root path.
///
/// The thirteen modules are private, so a member left out of the facade
/// stays reachable inside the crate and vanishes from the API outside it,
/// which is a silent semver break. This is where that fails instead.
#[test]
fn the_names_a_caller_is_told_to_use_are_exported_from_the_root() {
    #[allow(unused_imports)]
    use crate::{
        Affordance, AffordanceAxis, Arrangement, Awaiting, Bevel, Budget, CellPart, Change,
        ColumnKind, ColumnRoom, Contrast, DATE_FORMAT, DATETIME_FORMAT, Depth, Edge, Extent, Facet,
        FacetValue, Fallback, Family, FieldKind, Fill, Fit, Flow, Heading, Intent, Loading,
        MIN_CEILING, Measure, Nesting, Notice, PageKind, Paging, Placement, Priority, Readiness,
        Region, RowPart, Selecting, Selector, Share, Showing, Sizing, Sort, Span, Standing, State,
        Strip, Syntax, ThemeVariant, Token, Tone, Track, Unit, Value, Width, Window,
    };
}

/// A run nothing claimed is a real answer rather than a missing one, which
/// is why this is not an `Option<Syntax>`: a lexer that ran and found
/// ordinary code has said something.
#[test]
fn an_unclassified_run_is_plain_and_plain_is_the_default() {
    assert_eq!(Syntax::default(), Syntax::Plain);
    assert_eq!(Syntax::Plain.name(), "plain");
}

/// Every class has a stable lowercase name, and no two share one. The
/// spelling is named here rather than agreed per renderer, which is what
/// stops one calling it `str` and the next `string`.
#[test]
fn every_syntax_class_has_its_own_spelling() {
    let all = [
        Syntax::Plain,
        Syntax::Keyword,
        Syntax::String,
        Syntax::Comment,
        Syntax::Constant,
        Syntax::Entity,
        Syntax::Variable,
        Syntax::Support,
    ];
    let mut seen = std::collections::BTreeSet::new();
    for class in all {
        assert!(!class.name().is_empty(), "{class:?} has no spelling");
        assert!(seen.insert(class.name()), "{class:?} shares a spelling");
    }
    assert_eq!(seen.len(), all.len());
}

/// Context is a state and not an absence, so an unchanged line is
/// distinguishable from a line nobody marked. `Syntax::Plain`'s argument.
#[test]
fn an_unmarked_diff_line_is_context() {
    assert_eq!(Change::default(), Change::Context);
    assert_eq!(Change::Context.token(), "content");
}

/// The two sides reuse the status axis rather than minting a palette. An
/// app holding them fixed across themes says so in its own sheet.
#[test]
fn the_two_sides_of_a_change_take_the_status_intents() {
    assert_eq!(Change::Added.token(), "success");
    assert_eq!(Change::Removed.token(), "danger");
}

/// The concept is named here and its magnitude is not, which is
/// `Awaiting`'s split and is why a renderer can disagree with another
/// about what a level is worth without either of them being wrong.
#[test]
fn nesting_says_how_deep_and_not_how_wide() {
    assert_eq!(Nesting::default(), Nesting::top());
    assert_eq!(Nesting::top().level, 0);
    assert!(!Nesting::top().is_nested());

    let under = Nesting::at(2);
    assert_eq!(under.level, 2);
    assert!(under.is_nested());

    // Ordered, so a renderer walking a flat list of rows can compare two
    // levels rather than reaching into the field.
    assert!(Nesting::top() < under);
}

use super::*;

#[test]
fn a_markdown_field_is_multiline_and_offers_nothing() {
    // The editing counterpart of markdown prose is still text: every host
    // can draw it, which is the whole reason the kind was addable.
    assert!(FieldKind::Rich.multiline());
    assert!(FieldKind::Textarea.multiline());
    assert!(!FieldKind::Text.multiline());
    // It is not a chooser and not a moment.
    assert!(!FieldKind::Rich.offers_options());
    assert!(!FieldKind::Rich.temporal());
    assert!(FieldKind::Rich.visible());
}

#[test]
fn only_the_numeric_kinds_are_measurable() {
    assert!(FieldKind::Number.measurable());
    assert!(FieldKind::Range.measurable());
    // An axis is measured in something and both its ends are in it, so the
    // unit is read once for the pair rather than per end.
    assert!(FieldKind::Interval.measurable());
    // A date is ordered and is not a quantity with a unit to choose: its
    // unit is fixed by the kind, so saying one would restate `kind`.
    for kind in [
        FieldKind::Text,
        FieldKind::Date,
        FieldKind::DateTime,
        FieldKind::Select,
        FieldKind::Checkbox,
        FieldKind::File,
    ] {
        assert!(!kind.measurable(), "{kind:?}");
    }
}

#[test]
fn only_a_subtree_prunes_and_only_the_listing_modes_offer_values() {
    // Excluding a value from a flat facet is the same fact as not picking
    // it, so the affordance exists in exactly one mode.
    assert!(Selecting::Subtree.prunes());
    for mode in [
        Selecting::OneOf,
        Selecting::AnyOf,
        Selecting::Range,
        Selecting::Text,
    ] {
        assert!(!mode.prunes(), "{mode:?}");
    }
    // Text and Range answer with something that is not one of a set.
    assert!(!Selecting::Text.offers_values());
    assert!(!Selecting::Range.offers_values());
    assert!(Selecting::OneOf.offers_values());
    assert!(Selecting::AnyOf.accumulates());
    assert!(!Selecting::OneOf.accumulates());
}

#[test]
fn an_inherited_value_is_in_force_without_having_been_picked() {
    // The distinction a bool cannot hold, and the reason Standing has four
    // members: a child under a taken parent narrows the set, and clearing
    // it clears nothing.
    assert!(Standing::Inherited.in_force());
    assert!(!Standing::Inherited.is_picked());
    assert!(Standing::Taken.in_force());
    assert!(Standing::Taken.is_picked());
    // A prune is a decision that takes the value out.
    assert!(Standing::Pruned.is_picked());
    assert!(!Standing::Pruned.in_force());
    assert!(!Standing::Open.is_picked());
    assert!(!Standing::Open.in_force());
    // Out from above: not a decision, not in force, read back like a prune.
    assert!(!Standing::PrunedAbove.is_picked());
    assert!(!Standing::PrunedAbove.in_force());
    assert!(Standing::PrunedAbove.pruned_out());
    assert!(Standing::Pruned.pruned_out());
    assert!(!Standing::Inherited.pruned_out());
    assert_eq!(Standing::PrunedAbove.intent(), Standing::Pruned.intent());
    // A pruned branch still answers a press, so it may not read as inert.
    assert_ne!(Standing::Pruned.intent(), "content-muted");
}

#[test]
fn a_facet_is_engaged_by_a_decision_and_not_by_an_inherited_value() {
    let inherited = [
        FacetValue::of("music")
            .standing(Standing::Taken)
            .at(Nesting::at(0), true),
        FacetValue::new("music/synths", "synths")
            .standing(Standing::Inherited)
            .at(Nesting::at(1), false),
    ];
    let facet = Facet::new("Tag", Selecting::Subtree, &inherited);
    assert!(facet.engaged());
    // The gutter an indenting renderer reserves before its first paint.
    assert_eq!(facet.reach(), 1);

    let untouched = [
        FacetValue::of("music").at(Nesting::at(0), true),
        FacetValue::new("music/synths", "synths")
            .standing(Standing::Inherited)
            .at(Nesting::at(1), false),
    ];
    // Inherited alone is something further up doing the narrowing, and
    // there is nothing further up here.
    assert!(!Facet::new("Tag", Selecting::Subtree, &untouched).engaged());

    // A text facet lists nothing, so it is flat and never reads as engaged
    // from its values: the typed string is not held here.
    let typed = Facet::new("Search", Selecting::Text, &[]);
    assert!(!typed.engaged());
    assert_eq!(typed.reach(), 0);
}

#[test]
fn a_count_is_absent_rather_than_zero_when_it_was_not_measured() {
    // Awaiting::amount's rule in a second place: a written zero reads as
    // "none of them", which is a different claim from "not counted".
    assert_eq!(FacetValue::of("Ambient").count, None);
    assert_eq!(FacetValue::of("Ambient").counted(0).count, Some(0));
}

#[test]
fn one_kind_takes_files() {
    assert!(FieldKind::File.takes_files());
    for kind in [
        FieldKind::Text,
        FieldKind::Textarea,
        FieldKind::Rich,
        FieldKind::Select,
        FieldKind::Checkbox,
        FieldKind::Hidden,
    ] {
        assert!(!kind.takes_files());
    }
}

#[test]
fn the_four_readiness_states_are_one_axis_and_only_one_shows_content() {
    // Mutually exclusive is the test for one enum against several fields: a
    // region shows its content, or that it is coming, or that there is none,
    // or that it broke. Never two.
    assert!(Readiness::Ready.shows_content());
    for state in [Readiness::Pending, Readiness::Empty, Readiness::Failed] {
        assert!(!state.shows_content());
    }
}

#[test]
fn a_region_shows_all_of_its_children_unless_it_says_otherwise() {
    // The default is the behaviour every region had before this member
    // existed, which is what keeps it additive: a description written
    // against 0.22.0 says the same thing under 0.23.0.
    assert_eq!(Showing::default(), Showing::All);
    assert!(!Showing::All.selective());
}

#[test]
fn only_a_disclosure_can_show_nothing() {
    // The two derived idioms differ in one respect and this is it. A
    // carousel's row moves between frames and never reaches empty; a
    // disclosure's summary line is the same control wearing its closed
    // state, so a renderer has to know which it is drawing.
    assert!(Showing::AtMostOne.dismissible());
    assert!(!Showing::One.dismissible());
    assert!(!Showing::All.dismissible());

    // Both are selective, though. Deriving chrome is one question and
    // whether that chrome closes is another.
    assert!(Showing::One.selective());
    assert!(Showing::AtMostOne.selective());
}

#[test]
fn an_empty_region_is_not_a_broken_one() {
    // An empty list is the normal state of a new install. Drawing it in a
    // danger tone reports a fault where there is none, and this is the one
    // place the distinction is carried.
    assert_eq!(Readiness::Empty.tone(), Tone::Neutral);
    assert_eq!(Readiness::Failed.tone(), Tone::Danger);
    assert_eq!(Readiness::Pending.tone(), Tone::Neutral);
}

#[test]
fn a_direction_flips_and_says_what_it_is() {
    assert_eq!(Sort::Ascending.reversed(), Sort::Descending);
    assert_eq!(Sort::Descending.reversed().reversed(), Sort::Descending);
    assert_eq!(Sort::Ascending.as_str(), "ascending");
}

#[test]
fn a_direction_carries_its_caret_and_the_two_are_not_the_same_glyph() {
    // The spelling every renderer reads, so that agreeing is composition
    // rather than three files happening to hold the same literal.
    assert_eq!(Sort::Ascending.glyph(), "\u{25B2}");
    assert_eq!(Sort::Descending.glyph(), "\u{25BC}");
    assert_ne!(Sort::Ascending.glyph(), Sort::Descending.glyph());
    // Bare. The gap is the renderer's, and a space here would be a second
    // one wherever a renderer already carries its own.
    for d in [Sort::Ascending, Sort::Descending] {
        assert_eq!(d.glyph().trim(), d.glyph());
    }
}

#[test]
fn a_proportion_is_a_row_part_and_takes_no_intent_of_its_own() {
    // The meter carries the tone, so a part-level intent underneath would
    // fight it. Same answer `Tokens` needed, for the same reason.
    assert_eq!(RowPart::Proportion.intent(), RowPart::Tokens.intent());
}

#[test]
fn a_file_field_is_drawn_and_offers_no_options() {
    // It is a control the user operates, unlike `Hidden`, and it does not
    // pick from a list the description carries, unlike `Select`.
    assert!(FieldKind::File.visible());
    assert!(!FieldKind::File.offers_options());
    assert!(!FieldKind::File.confidential());
}

#[test]
fn inset_is_raised_with_the_light_moved() {
    let (rl, rd) = Bevel::Raised.edges();
    let (il, id) = Bevel::Inset.edges();
    assert_eq!((rl, rd), (Edge::Light, Edge::Dark));
    assert_eq!((il, id), (rd, rl));
}

#[test]
fn pressing_twice_is_a_no_op() {
    for b in [Bevel::Raised, Bevel::Inset] {
        assert_eq!(b.pressed().pressed(), b);
    }
}

#[test]
fn a_raised_region_is_never_filled_with_a_recessed_surface() {
    // The bug this vocabulary exists to make unrepresentable.
    assert_eq!(Depth::Raised.fill(), Some(Fill::Raised));
    assert_eq!(Depth::Raised.bevel(), Some(Bevel::Raised));
    assert_eq!(Depth::Well.bevel(), Some(Bevel::Inset));
    assert_ne!(Depth::Well.fill(), Depth::Raised.fill());
}

#[test]
fn state_is_orthogonal_to_depth() {
    // The reason State is its own axis and not a Depth member: a disabled
    // button and a disabled field are both disabled and are not the same
    // shape, which one shared variant could not have said.
    assert_eq!(Depth::Raised.fill(), Some(Fill::Raised));
    assert_eq!(Depth::Well.fill(), Some(Fill::Well));
    assert!(State::Disabled.suppresses_interaction());
}

#[test]
fn only_disabled_stops_answering() {
    // Kept in spirit from the version where `Focus` was the counter-example:
    // suppressing interaction is `Disabled`'s alone, so a member added here
    // later does not get to inherit it by being a state.
    assert!(State::Disabled.suppresses_interaction());
}

#[test]
fn disabled_resolves_against_an_intent_makeover_already_derives() {
    // No new token, so this costs no `makeover` release.
    assert_eq!(State::Disabled.token(), "content-muted");
}

#[test]
fn flat_has_neither_edge_nor_fill() {
    assert_eq!(Depth::Flat.bevel(), None);
    assert_eq!(Depth::Flat.fill(), None);
}

#[test]
fn sunken_is_recessed_by_colour_with_no_edge() {
    // The one member carrying a fill without a bevel. A renderer that
    // assumes the two arrive together drops the fill silently, which is
    // exactly what makeover-webview did before 0.3.0.
    assert_eq!(Depth::Sunken.fill(), Some(Fill::Sunken));
    assert_eq!(Depth::Sunken.bevel(), None);
}

#[test]
fn sunken_and_flat_are_different_claims() {
    // Both edgeless, and only one of them needs a colour. Collapsing them
    // is what left an unchosen tab unsayable.
    assert_eq!(Depth::Flat.bevel(), Depth::Sunken.bevel());
    assert_ne!(Depth::Flat.fill(), Depth::Sunken.fill());
}

#[test]
fn a_sunken_surface_is_not_a_well() {
    // Authored in opposite directions: makeover derives surface-well by
    // inverting against the theme's content colour, while surface-sunken is
    // authored and may sit darker than raised.
    assert_ne!(Fill::Sunken, Fill::Well);
    assert_eq!(Fill::Sunken.token(), "surface-sunken");
    assert_eq!(Fill::Well.token(), "surface-well");
}

#[test]
fn every_selector_describes_both_of_its_states() {
    // The gap 0.3.0 closed. Before it, only `chosen` existed and the
    // unchosen option fell through to Flat at every renderer.
    for s in [Selector::Tabs, Selector::Segmented, Selector::Toggle] {
        assert_ne!(
            s.chosen(),
            s.unchosen(),
            "{s:?} cannot tell picked from unpicked"
        );
    }
}

#[test]
fn only_a_tab_inverts_the_other_way() {
    // Tabs recede so the chosen one comes forward; a segment and a toggle
    // stand up so the chosen one is held in. That inversion is the whole
    // content of "picked" once colour is deferred, and it is why the three
    // are not one member with a flag.
    assert_eq!(Selector::Tabs.unchosen(), Depth::Sunken);
    assert_eq!(Selector::Tabs.chosen(), Depth::Raised);

    for s in [Selector::Segmented, Selector::Toggle] {
        assert_eq!(s.unchosen(), Depth::Raised);
        assert_eq!(s.chosen(), Depth::Well);
        // Held in is what pressing produces: one appearance, two reasons.
        assert_eq!(s.unchosen().pressed(), s.chosen());
    }
}

#[test]
fn pressing_a_card_makes_a_well() {
    assert_eq!(Depth::Raised.pressed(), Depth::Well);
    assert_eq!(
        Depth::Raised.pressed().bevel(),
        Depth::Raised.bevel().map(Bevel::pressed)
    );
    // Only raised regions respond to being pressed.
    assert_eq!(Depth::Flat.pressed(), Depth::Flat);
    assert_eq!(Depth::Well.pressed(), Depth::Well);
    // An overlay is a surface, not a control.
    assert_eq!(Depth::Overlay.pressed(), Depth::Overlay);
}

#[test]
fn an_overlay_is_lifted_rather_than_edged() {
    // The wave-2 rule: a surface over the page takes elevation, a surface
    // in the page takes a bevel. Both halves come off the one Depth, so
    // they cannot disagree.
    assert_eq!(Depth::Overlay.fill(), Some(Fill::Overlay));
    assert_eq!(Depth::Overlay.bevel(), None);

    // Three depths have no bevel and they are not the same claim. Flat has
    // nothing to separate from, Sunken's colour is doing the separating,
    // and an overlay is separated by the lift.
    assert_ne!(Depth::Overlay.fill(), Depth::Sunken.fill());
    assert_ne!(Depth::Overlay.fill(), Depth::Flat.fill());
}

#[test]
fn neutral_is_content_not_muted_content() {
    // Neutral means "no status", and that is all it means. It answered
    // `content-muted` until 2026-08-27, which muted a figure's headline
    // number to the colour of its own caption. What makes a badge quiet
    // is `Token::Badge` answering no click, which lives on the renderer.
    assert_eq!(Tone::Neutral.token(), "content");
    assert!(!Token::Badge.interactive());
    assert_eq!(State::Disabled.token(), "content-muted");
}

#[test]
fn intents_name_makeover_tokens_and_nothing_else() {
    assert_eq!(Edge::Light.token(), "bevel-light");
    assert_eq!(Edge::Dark.token(), "bevel-dark");
    assert_eq!(Fill::Raised.token(), "surface-raised");
    assert_eq!(Fill::Well.token(), "surface-well");
    // No value ever leaves this crate.
    for t in [
        Edge::Light.token(),
        Edge::Dark.token(),
        Tone::Danger.token(),
        Tone::Neutral.token(),
        State::Disabled.token(),
    ] {
        assert!(!t.starts_with('#'), "{t} looks like a value");
        assert!(
            !t.chars().next().unwrap().is_ascii_digit(),
            "{t} is a value"
        );
    }
}

#[test]
fn a_badge_cannot_be_pressed_and_a_chip_latches() {
    // The one line that runs through all three apps' taxonomies.
    assert!(!Token::Badge.interactive());
    assert!(Token::Chip { removable: false }.interactive());
    assert!(Token::Chip { removable: true }.interactive());

    // A badge is a label, so giving it an edge would lie about it.
    assert_eq!(Token::Badge.depth(false), Depth::Flat);
    assert_eq!(Token::Badge.depth(true), Depth::Flat);

    // A latched chip wears the same shape a pressed one does.
    let chip = Token::Chip { removable: false };
    assert_eq!(chip.depth(false), Depth::Raised);
    assert_eq!(chip.depth(true), Depth::Raised.pressed());
}

#[test]
fn a_toast_and_a_banner_differ_in_more_than_placement() {
    assert!(Notice::Toast.transient());
    assert!(!Notice::Banner.transient());
    // A toast floats above the page; a banner rests in the flow.
    assert_eq!(Notice::Toast.fill(), Fill::Overlay);
    assert_eq!(Notice::Banner.fill(), Fill::Raised);
}

#[test]
fn emphasis_falls_off_down_the_row() {
    // `revealed_on_hover` was asserted here until 0.13.0 retired it. It said
    // a row's actions stay hidden until hover, which stopped being true when
    // makeover-webview 0.23.0 showed them at rest, and nothing had consumed
    // it for a release either way.
    assert_eq!(RowPart::Primary.intent(), "content");
    assert_eq!(RowPart::Secondary.intent(), "content-secondary");
    assert_eq!(RowPart::Meta.intent(), "content-muted");
}

#[test]
fn a_token_part_carries_no_intent_of_its_own() {
    // Each token carries its own tone, so a part-level intent underneath
    // would fight the thing sitting on it. Same reasoning as actions, which
    // is why they answer alike.
    assert_eq!(RowPart::Tokens.intent(), RowPart::Actions.intent());
    assert_eq!(RowPart::Tokens.intent(), "content");
}

#[test]
fn the_two_temporal_kinds_are_the_two_that_name_a_moment() {
    // The pair is named once so a host with parsing to do asks here rather
    // than spelling it out, which is `offers_options`' reason.
    assert!(FieldKind::Date.temporal());
    assert!(FieldKind::DateTime.temporal());

    for kind in [
        FieldKind::Text,
        FieldKind::Secret,
        FieldKind::Number,
        FieldKind::Email,
        FieldKind::Url,
        FieldKind::Tel,
        FieldKind::Range,
        FieldKind::Textarea,
        FieldKind::Rich,
        FieldKind::Select,
        FieldKind::Radio,
        FieldKind::Checkbox,
        FieldKind::File,
        FieldKind::Hidden,
    ] {
        assert!(!kind.temporal(), "{kind:?}");
    }
}

#[test]
fn a_date_carries_no_time_and_a_datetime_carries_no_zone() {
    // The formats are the whole reason the members are worth naming apart
    // from text, so the doc comments and the constants have to agree. A
    // host reading one and meeting the other is the silent failure.
    assert_eq!(DATE_FORMAT, "%Y-%m-%d");
    assert!(!DATE_FORMAT.contains("%H"), "a day carries no hour");

    assert_eq!(DATETIME_FORMAT, "%Y-%m-%dT%H:%M");
    assert!(
        DATETIME_FORMAT.starts_with(DATE_FORMAT),
        "a moment starts with the day it is on"
    );
    // Local, and that is a property of the value rather than an omission.
    assert!(!DATETIME_FORMAT.contains("%Z"), "no zone name");
    assert!(!DATETIME_FORMAT.ends_with('Z'), "not UTC-stamped");
    assert!(!DATETIME_FORMAT.contains("%S"), "no seconds by default");
}

#[test]
fn a_temporal_kind_takes_a_label_above_it_and_offers_no_options() {
    // Neither is a checkbox and neither is a fixed set, so both fall where
    // text does. Asserted because a new kind lands in three predicates and
    // only one of them is the interesting one.
    for kind in [FieldKind::Date, FieldKind::DateTime] {
        assert!(kind.visible(), "{kind:?}");
        assert!(!kind.confidential(), "{kind:?}");
        assert!(!kind.labels_itself(), "{kind:?}");
        assert!(!kind.offers_options(), "{kind:?}");
    }
}

#[test]
fn a_cell_part_names_an_intent_and_only_the_value_is_text() {
    // The table half of what RowPart::intent does for rows. A cell holding
    // a control and a cell holding text answered alike until 0.14.0, and a
    // control in a cell took the cell's text colour.
    assert_eq!(CellPart::Value.intent(), "content");

    for part in [CellPart::Tokens, CellPart::Actions, CellPart::Link] {
        // Each for its own reason -- a token carries its tone, an action is
        // a control, a link takes the action colour -- and all three reach
        // the intent inheriting already gives.
        assert_eq!(part.intent(), CellPart::Value.intent(), "{part:?}");
    }
}

#[test]
fn every_cell_part_answers_with_a_token_and_never_a_value() {
    for part in [
        CellPart::Value,
        CellPart::Tokens,
        CellPart::Actions,
        CellPart::Link,
    ] {
        let intent = part.intent();
        assert!(!intent.is_empty(), "{part:?} names nothing");
        assert!(!intent.starts_with('#'), "{part:?} looks like a value");
    }
}

#[test]
fn a_chosen_segment_is_held_in_and_a_chosen_tab_comes_forward() {
    assert_eq!(Selector::Segmented.chosen(), Depth::Well);
    assert_eq!(Selector::Toggle.chosen(), Depth::Well);
    // The exception, and the whole folder semantic: the open tab joins its
    // pane rather than sinking away from it.
    assert_eq!(Selector::Tabs.chosen(), Depth::Raised);

    // A held-in segment is indistinguishable from a pressed raised one,
    // which is the economy the light model buys over a colour swap.
    assert_eq!(Selector::Segmented.chosen(), Depth::Raised.pressed());

    // A toggle stands alone; the other two are built out of parts that
    // touch.
    assert!(Selector::Segmented.abutting());
    assert!(Selector::Tabs.abutting());
    assert!(!Selector::Toggle.abutting());
}

#[test]
fn columns_are_peers_and_a_split_is_not() {
    // The distinction the member exists for. A split's two panes stand in a
    // master-detail relationship; columns choose nothing about each other.
    // Both are flat, so depth cannot tell them apart and the doc has to.
    assert_eq!(Region::Columns.depth(), Depth::Flat);
    assert_eq!(Region::Split.depth(), Depth::Flat);
    assert_ne!(Region::Columns, Region::Split);
}

#[test]
fn columns_carry_no_count_and_no_share() {
    // The two things a board is always asked to carry and must not. How
    // many is what the children say; how wide is settled by "peers are
    // equal".
    //
    // The guard is the binding itself and it is a compile-time one: adding
    // a field to `Columns` stops this line compiling, which is a better
    // failure than any assertion about it. Written out rather than inlined
    // for exactly that reason.
    let columns: Region<'_> = Region::Columns;
    assert_eq!(columns.name(), None);
}

#[test]
fn columns_are_described_and_the_escape_hatch_is_still_one_member() {
    // A board's contents are ordinary description all the way down, so a
    // renderer that does not lay them across still draws every column.
    // Stacking them vertically is honouring this member, not degrading it.
    assert!(Region::Columns.described());
    assert!(!Region::Handover { name: "timeline" }.described());
}

#[test]
fn a_span_never_has_zero_minutes_however_it_is_asked_for() {
    // Every renderer divides by this. A caller passing a backwards or empty
    // span is a bug, but it is not a bug worth a panic three renderers deep.
    assert_eq!(Span::new(600, 600).length(), 1);
    assert_eq!(Span::new(600, 300).length(), 1);
    assert_eq!(Span::DAY.length(), 1440);
}

#[test]
fn a_span_can_run_past_midnight_without_a_second_date() {
    // 22:00 to 02:00. The alternative was carrying a date, which drags a
    // timezone into the vocabulary for the sake of one night shift.
    let overnight = Span::new(1320, 1560);
    assert_eq!(overnight.length(), 240);
    assert!(overnight.holds(1500));
    assert!(!overnight.holds(1200));
}

#[test]
fn overlap_is_computed_rather_than_declared() {
    // The reason Placement carries no `conflicts` flag: the times already
    // say it, and a second source for one fact is how a stale conflict
    // badge outlives the conflict.
    let morning = Placement::new(540, 60); // 09:00-10:00
    let overlapping = Placement::new(570, 60); // 09:30-10:30
    let after = Placement::new(600, 60); // 10:00-11:00

    assert!(morning.overlaps(overlapping));
    assert!(overlapping.overlaps(morning), "overlap is symmetric");
    // Touching end to end is not overlapping: `to` is exclusive, so a
    // 10:00 start does not collide with a 10:00 end.
    assert!(!morning.overlaps(after));
    assert!(!after.overlaps(morning));
}

#[test]
fn a_placement_is_always_drawable() {
    assert_eq!(Placement::new(540, 0).length(), 1);
    assert_eq!(Placement::new(540, 30).end(), 570);
}

#[test]
fn a_track_places_the_fraction_every_renderer_would_otherwise_compute() {
    let day = Track::DAY;
    assert!((day.fraction(0) - 0.0).abs() < f32::EPSILON);
    assert!((day.fraction(720) - 0.5).abs() < f32::EPSILON);
    // Clamped rather than off the end: an event running past the span's
    // close draws at the edge, which beats panicking or drawing nowhere.
    assert!((day.fraction(2000) - 1.0).abs() < f32::EPSILON);
}

#[test]
fn a_track_counts_its_slots_and_never_divides_by_zero() {
    assert_eq!(Track::DAY.slots(), 96);
    assert_eq!(Track::over(Span::new(540, 1020)).slots(), 32);
    // A span that does not divide evenly keeps a slot for its tail.
    assert_eq!(Track::over(Span::new(0, 50)).slots(), 4);
    // slot: 0 is a caller bug that reads as one slot, not a panic.
    let degenerate = Track {
        span: Span::DAY,
        slot: 0,
        tick: 60,
        unit: Unit::Minutes,
    };
    assert_eq!(degenerate.slots(), 1);
}

#[test]
fn a_track_carries_facts_and_no_presentation() {
    // The guard on the thing the withdrawn refusal was right about. If a
    // pixel measure, a scroll offset or a colour ever lands on Track, the
    // member has stopped being a fact about the data and the timeline
    // really has become a component library wearing a description's name.
    let day = Track::DAY;
    assert_eq!(day.span, Span::DAY);
    assert_eq!(day.slot, 15);
    assert_eq!(day.tick, 60);
    assert_eq!(day.unit, Unit::Minutes);

    // Three fields when this was written, and the fourth came here to say
    // why, which is the whole point of the assertion. `unit` is what the
    // integers COUNT -- a fact about the data, unavailable from the numbers
    // themselves, and the absence of it is what let a month strip render
    // under a wall clock. A fifth field still has to argue, and "the
    // renderer would find it handy" is still not the argument.
    // Destructured rather than rebuilt: this is the form that names every
    // field and stops compiling when a fifth arrives, without binding
    // anything a lint has to forgive.
    let Track {
        span: _,
        slot: _,
        tick: _,
        unit: _,
    } = day;
}

#[test]
fn a_day_strip_is_the_same_arithmetic_under_a_different_unit() {
    // The probe that found the defect, kept as a test. Fifteen days from
    // day three, on a thirty-one day month: the geometry was always right
    // and only the label was wrong, which is why `unit` is a fact and not
    // presentation.
    let march = Track::days(Span::new(0, 31));
    assert_eq!(march.slots(), 31);
    assert_eq!(march.unit, Unit::Days);

    let leave = Placement::new(2, 15);
    assert!((march.fraction(leave.at()) - 2.0 / 31.0).abs() < 0.0001);
    assert!((march.fraction(leave.end()) - 17.0 / 31.0).abs() < 0.0001);
}

#[test]
fn a_strip_that_runs_down_stacks_its_tabs_and_one_that_runs_across_does_not() {
    // Reached through the root, so a `Strip` left out of the facade fails here
    // as well as in the export test.
    use crate::Strip;
    assert!(Strip::Down.runs_down());
    assert!(!Strip::Across.runs_down());
    // Two directions and no third: the match is exhaustive on purpose, so a
    // renderer that handles both has handled every strip.
    let named = |strip: Strip| match strip {
        Strip::Across => "across",
        Strip::Down => "down",
    };
    assert_ne!(named(Strip::Across), named(Strip::Down));
}

#[test]
fn a_pane_is_looked_into_and_a_band_is_not() {
    assert_eq!(Region::Pane.depth(), Depth::Well);
    assert_eq!(Region::Modal.depth(), Depth::Raised);
    assert_eq!(Region::Plate.depth(), Depth::Raised);
    for r in [
        Region::Band,
        Region::Sidebar,
        Region::Group,
        Region::Split,
        Region::TabGroup,
    ] {
        assert_eq!(r.depth(), Depth::Flat, "{r:?} should carry no edge");
    }
}

#[test]
fn exactly_one_region_is_opaque() {
    // The escape hatch is one member and stays one member. If a second
    // undescribed region ever appears, the description has started
    // conceding rather than deferring.
    for r in [
        Region::Band,
        Region::Sidebar,
        Region::Pane,
        Region::Group,
        Region::Plate,
        Region::Split,
        Region::TabGroup,
        Region::Modal,
        // A widget is described, and that is the whole of what separates it
        // from a bespoke here. Both carry a name this crate never reads;
        // only one of them has contents under it that a renderer which does
        // not know the name can still walk.
        Region::Widget { name: "carousel" },
    ] {
        assert!(r.described(), "{r:?} should be describable");
    }
    assert!(!Region::Handover { name: "day-plan" }.described());
}

#[test]
fn a_region_nobody_converted_yet_is_not_a_region_the_app_gave_up_on() {
    // The whole of why this is two members. Both are opaque and neither is
    // described, so the old single member made them one value; a renderer
    // with no fill drew both as an empty box and said nothing either way.
    assert!(Region::Handover { name: "day-plan" }.owed());
    assert!(
        !Region::Ceded {
            name: "revenue-chart"
        }
        .owed()
    );

    // Everything that carries its own contents owes nothing, which is the
    // reading a renderer needs for the members it already draws.
    assert!(!Region::Pane.owed());
    assert!(!Region::Widget { name: "carousel" }.owed());

    // Opaqueness is the axis they still share.
    assert!(!Region::Ceded { name: "waveform" }.described());
    assert_eq!(Region::Ceded { name: "waveform" }.name(), Some("waveform"));
    assert_eq!(Region::Ceded { name: "waveform" }.depth(), Depth::Flat);
}

#[test]
fn a_group_contains_a_section_without_claiming_to_be_a_pane() {
    // The whole of why this is a member rather than a `Pane`. A pane is
    // looked into and scrolls; a group is neither, and four groups inside a
    // settings pane described as panes are four wells inside a well.
    assert_eq!(Region::Pane.depth(), Depth::Well);
    assert_eq!(Region::Group.depth(), Depth::Flat);
    assert_ne!(Region::Group, Region::Pane);

    // Described, and it carries no name: a group is a primitive every
    // renderer draws from scratch, which is what separates it from the two
    // members that do carry one.
    assert!(Region::Group.described());
    assert_eq!(Region::Group.name(), None);
}

#[test]
fn a_section_heading_names_a_block_that_now_exists() {
    // `Heading::Section` has said "names a block within the screen" since
    // 0.2.0 and there was no block. The pairing is the point, and it is the
    // reason a group carries no heading of its own: the heading is an
    // ordinary node in the body, and a group without one is legal.
    //
    // This asserted `Heading::Section.separated()` until 0.50.2, which said
    // the pairing only by implication and through a predicate no renderer
    // read. What actually holds it up is the group being a real block at a
    // depth of its own.
    assert_eq!(Region::Group.depth(), Depth::Flat);
    assert_eq!(Region::Group.name(), None);
}

#[test]
fn a_widget_inherits_its_depth_the_way_a_bespoke_does() {
    // Stronger than the bespoke case: a widget is drawn by whichever
    // renderer recognises the name, so a depth chosen here would be this
    // crate deciding a carousel is raised on every host.
    assert_eq!(Region::Widget { name: "carousel" }.depth(), Depth::Flat);
    assert_eq!(Region::Widget { name: "pager" }.depth(), Depth::Flat);
}

#[test]
fn a_name_is_readable_without_asking_which_member_carried_it() {
    // A renderer dispatching on a name wants the string, not the member.
    // Writing that `matches!` at each renderer is how the two drift apart.
    assert_eq!(Region::Widget { name: "carousel" }.name(), Some("carousel"));
    assert_eq!(
        Region::Handover { name: "day-plan" }.name(),
        Some("day-plan")
    );

    for r in [
        Region::Band,
        Region::Sidebar,
        Region::Pane,
        Region::Group,
        Region::Plate,
        Region::Split,
        Region::TabGroup,
        Region::Modal,
    ] {
        assert_eq!(r.name(), None, "{r:?} names nothing an app chose");
    }
}

#[test]
fn a_bespoke_region_inherits_its_depth_rather_than_choosing_one() {
    // The app owns the contents, not the placement. An app that wants its
    // timeline in a well frames it in a Pane.
    assert_eq!(Region::Handover { name: "day-plan" }.depth(), Depth::Flat);
    assert_eq!(Region::Handover { name: "kanban" }.depth(), Depth::Flat);
}

#[test]
fn a_screen_with_a_bespoke_region_is_still_a_whole_screen() {
    // The argument the member exists for: goingson's day-plan has to be
    // routable, or the description covers only the boring screens and the
    // interesting four need a second path beside the router.
    let day_plan = [
        Region::Band,
        Region::Handover { name: "day-plan" },
        Region::Sidebar,
    ];
    assert_eq!(day_plan.iter().filter(|r| r.described()).count(), 2);
    assert_eq!(day_plan.iter().filter(|r| !r.described()).count(), 1);
}

#[test]
fn a_secret_field_is_marked_as_one_and_a_hidden_field_is_not_drawn() {
    assert!(FieldKind::Secret.confidential());
    assert!(FieldKind::Secret.visible());

    assert!(!FieldKind::Hidden.visible());
    // Nothing else is confidential, or the marker means nothing.
    for k in [
        FieldKind::Text,
        FieldKind::Number,
        FieldKind::Textarea,
        FieldKind::Rich,
        FieldKind::Select,
        FieldKind::Checkbox,
        FieldKind::Hidden,
    ] {
        assert!(!k.confidential(), "{k:?} should not be confidential");
    }

    // Only a checkbox carries its own label.
    assert!(FieldKind::Checkbox.labels_itself());
    assert!(!FieldKind::Text.labels_itself());
}

#[test]
fn exactly_the_option_taking_kinds_say_so() {
    // The renderers branch on this rather than on a list of their own, so
    // a kind added without a decision here renders its options nowhere.
    assert!(FieldKind::Select.offers_options());
    assert!(FieldKind::Radio.offers_options());
    assert!(FieldKind::Checklist.offers_options());
    for kind in [
        FieldKind::Text,
        FieldKind::Secret,
        FieldKind::Number,
        FieldKind::Email,
        FieldKind::Url,
        FieldKind::Tel,
        FieldKind::Range,
        FieldKind::Textarea,
        FieldKind::Rich,
        FieldKind::Checkbox,
        FieldKind::Hidden,
    ] {
        assert!(!kind.offers_options(), "{kind:?} does not offer options");
    }
}

#[test]
fn a_checklist_is_one_question_whose_answer_is_a_set() {
    // The one kind that takes several options, so a renderer marks its
    // options by `chosen` alone and a pick leaves the others standing.
    assert!(FieldKind::Checklist.takes_several());
    for kind in [
        FieldKind::Select,
        FieldKind::Radio,
        FieldKind::Checkbox,
        FieldKind::Text,
        FieldKind::File,
        FieldKind::Theme,
    ] {
        assert!(!kind.takes_several(), "{kind:?} answers with one value");
    }
    // A question above its options, like a radio group, and not a checkbox
    // labelling itself: the set is what is asked about.
    assert!(!FieldKind::Checklist.labels_itself());
}

#[test]
fn a_radio_group_takes_a_label_even_though_its_options_carry_their_own() {
    // The near-miss: each option is labelled beside its own button, so a
    // renderer could plausibly read the group as self-labelling and drop
    // the question. Checkbox is the only kind that does that.
    assert!(!FieldKind::Radio.labels_itself());
    assert!(FieldKind::Checkbox.labels_itself());
}

#[test]
fn columns_drop_by_priority_and_never_by_position() {
    let cols = [
        ColumnRoom {
            width: Width::Fill,
            priority: Priority::Essential,
            ..ColumnRoom::new("Title")
        },
        ColumnRoom {
            width: Width::Fixed,
            priority: Priority::Secondary,
            ..ColumnRoom::new("Due")
        },
        ColumnRoom {
            width: Width::Fixed,
            priority: Priority::Optional,
            ..ColumnRoom::new("Estimate")
        },
    ];

    // Widest: everything survives.
    assert_eq!(
        cols.iter()
            .filter(|c| c.kept_at(Priority::Optional))
            .count(),
        3
    );
    // Narrower: the optional column goes first.
    let kept: Vec<_> = cols
        .iter()
        .filter(|c| c.kept_at(Priority::Secondary))
        .map(|c| c.heading)
        .collect();
    assert_eq!(kept, ["Title", "Due"]);
    // Narrowest: only what identifies the row.
    let kept: Vec<_> = cols
        .iter()
        .filter(|c| c.kept_at(Priority::Essential))
        .map(|c| c.heading)
        .collect();
    assert_eq!(kept, ["Title"]);
}

#[test]
fn inserting_a_column_does_not_move_what_gets_dropped() {
    // The bug the ordinal form has and this form cannot: goingson hides
    // `nth-child(n+5)` against a seven-column table, so a column inserted
    // anywhere to the left silently hides a different one.
    let estimate = ColumnRoom {
        width: Width::Fixed,
        priority: Priority::Optional,
        ..ColumnRoom::new("Estimate")
    };
    let before = [ColumnRoom::new("Title"), estimate];
    let after = [
        ColumnRoom::new("Title"),
        ColumnRoom::new("Project"), // inserted
        estimate,
    ];

    fn dropped<'a>(cols: &[ColumnRoom<'a>]) -> Vec<&'a str> {
        cols.iter()
            .filter(|c| !c.kept_at(Priority::Secondary))
            .map(|c| c.heading)
            .collect()
    }
    assert_eq!(dropped(&before), ["Estimate"]);
    assert_eq!(dropped(&after), ["Estimate"]);
}

#[test]
fn a_table_with_no_essential_column_never_drops_to_nothing() {
    // The cutoff rises through `Priority::RAISING` until the columns fit, and
    // never past the strongest priority actually present: a table whose
    // strongest column is Secondary would otherwise reach Essential, where the
    // budget keeps no column at all.
    let rank = |name, priority| ColumnRoom {
        priority,
        ..ColumnRoom::new(name)
    };
    let cols = [
        rank("Optional", Priority::Optional),
        rank("Secondary", Priority::Secondary),
    ];
    // Nothing ever fits, so the cutoff falls through to the floor.
    assert_eq!(
        ColumnRoom::cutoff_for(&cols, |_| false),
        Priority::Secondary
    );
    // A table that does hold an essential column still drops to it.
    let with_essential = [
        rank("Optional", Priority::Optional),
        ColumnRoom::new("Essential"),
    ];
    assert_eq!(
        ColumnRoom::cutoff_for(&with_essential, |_| false),
        Priority::Essential
    );
}

#[test]
fn a_multibyte_heading_floors_in_characters_not_bytes() {
    // `ch` is the width of a glyph, so a Cyrillic heading counted by `len()`
    // would read as 12 ch and over-reserve. Fixed width keeps the fill floor
    // out of the way and no caret keeps the heading the widest term.
    let fixed = |heading| ColumnRoom {
        width: Width::Fixed,
        ..ColumnRoom::new(heading)
    };
    assert_eq!(fixed("Статус").floor(), fixed("Status").floor());
    assert_eq!(fixed("Статус").floor(), 8);
}

#[test]
fn an_arrangement_carries_the_tab_group_as_a_modifier() {
    // goingson uses the tab group inside the content region rather than
    // instead of one, so it is not a third arrangement.
    let go = Arrangement::list_detail(true);
    let plain = Arrangement::list_detail(false);
    assert_ne!(go, plain);
    assert_ne!(go, Arrangement::sidebar_content());
}

#[test]
fn a_share_is_a_proportion_and_resolves_the_same_way_everywhere() {
    // The point of the member: a terminal reading columns and a webview
    // reading a grid honour one fact, so two hosts showing one screen agree
    // about its proportions.
    // 60 since 0.48.1, and pinned rather than inferred: a list side carries a
    // table on every host that has one, and 40% of the window could not hold
    // it. goingson's four table-bearing screens each overrode this by hand.
    assert_eq!(Share::LIST.as_percent(), 60);
    assert_eq!(Share::LIST.of(100), 60);
    assert_eq!(
        Share::SIDEBAR.of(96),
        24,
        "quasi-tui's 24 columns, said as a quarter"
    );
}

#[test]
fn a_region_never_resolves_to_nothing() {
    // A region the description named should be visible. A zero-width one
    // reads on screen as a region that vanished, which is the hardest kind
    // of bug to find from what is drawn. With no width at all there is
    // nothing to show it in, and a column handed out of nothing overdraws
    // whatever sits beside the screen.
    assert_eq!(Share::percent(5).of(1), 1);
    assert_eq!(Share::percent(5).of(0), 0);
}

#[test]
fn a_share_outside_the_range_is_clamped_rather_than_refused() {
    assert_eq!(Share::percent(0), Share::percent(5));
    assert_eq!(Share::percent(200), Share::percent(95));
}

#[test]
fn the_share_rides_on_the_arrangement_that_knows_which_question_it_is() {
    // How much a sidebar takes and how much a list side takes are different
    // questions, and this enum is the only thing that knows which is being
    // asked.
    assert_eq!(Arrangement::sidebar_content().share(), Some(Share::SIDEBAR));
    assert_eq!(Arrangement::list_detail(false).share(), Some(Share::LIST));
    // One region divides nothing, so there is no share to answer with.
    assert_eq!(Arrangement::Single.share(), None);
    assert_eq!(
        Arrangement::Single.with_share(Share::percent(20)),
        Arrangement::Single
    );

    let narrow = Arrangement::sidebar_content().with_share(Share::percent(20));
    assert_eq!(narrow.share(), Some(Share::percent(20)));
    assert!(matches!(narrow, Arrangement::SidebarContent { .. }));
}

#[test]
fn a_measure_defaults_to_the_one_53_of_69_templates_asked_for() {
    // The default is meaningful: a screen nobody said anything about uses
    // the window it was given.
    assert_eq!(Measure::default(), Measure::Wide);
    assert_eq!(Measure::Reading.as_str(), "reading");
}

#[test]
fn readiness_names_the_state_and_not_the_shimmer() {
    // Two members and no third. If a skeleton ever appears in this enum,
    // the deferral rule has been broken.
    assert_ne!(Readiness::Ready, Readiness::Pending);
}

#[test]
fn a_window_with_no_length_still_answers_what_it_can() {
    // The uncounted case is the common one, not the degenerate one: a query
    // that asked for 51 to learn there were more than 50 knows there are,
    // and not how many.
    let uncounted = Window::new(100, 50);
    assert_eq!(uncounted.index(), Some(2));
    assert_eq!(uncounted.windows(), None);
    assert!(uncounted.has_before());
    // Unknown length cannot rule out more, and offering a way forward that
    // turns out empty is the cheaper mistake.
    assert!(uncounted.has_after());
}

#[test]
fn a_counted_window_knows_where_it_ends() {
    let last = Window::new(350, 50).of(400);
    assert_eq!(last.index(), Some(7));
    assert_eq!(last.windows(), Some(8));
    assert!(last.has_before());
    assert!(!last.has_after());

    let first = Window::new(0, 50).of(400);
    assert!(!first.has_before());
    assert!(first.has_after());
}

#[test]
fn a_window_that_does_not_divide_evenly_rounds_up() {
    // 401 rows in pages of 50 is eight pages and a straggler, which is nine
    // pages. Rounding down would make the last one unreachable.
    assert_eq!(Window::new(0, 50).of(401).windows(), Some(9));
}

#[test]
fn a_zero_count_answers_none_rather_than_dividing() {
    let empty = Window::new(0, 0).of(400);
    assert_eq!(empty.index(), None);
    assert_eq!(empty.windows(), None);
    // And it still clamps rather than panicking.
    assert_eq!(Window::new(900, 0).of(400).clamped().from(), 399);
}

#[test]
fn an_empty_sequence_has_no_window() {
    // A host that counted zero says so, and there is no page to number: "1 of 0"
    // is the renderer reading a page where none exists. `clamped()` cannot help
    // here, since there is no window to clamp inside.
    let none = Window::new(0, 10).of(0);
    assert_eq!(none.index(), None);
    assert_eq!(none.windows(), Some(0));
    assert_eq!(Paging::pages(0, 10).of(0).page(), None);
    assert_eq!(Paging::pages(0, 10).of(0).pages_total(), Some(0));
}

#[test]
fn a_window_past_the_end_clamps_inside_rather_than_vanishing() {
    // `Slot::current`'s reasoning, one layer down: a description pointing
    // past the end is a host bug, and answering it by drawing nothing
    // reports a region that vanished.
    assert_eq!(Window::new(900, 50).of(400).clamped().from(), 350);
    // Nothing to clamp against when the length is unknown.
    assert_eq!(Window::new(900, 50).clamped().from(), 900);
}

#[test]
fn a_carousel_frame_is_a_window_of_one() {
    // The shape a carousel instantiates. Same code as a paged list, which is
    // the whole reason `Window` exists rather than two copies of it.
    let third = Window::frame(2, 5);
    assert_eq!(third.index(), Some(2));
    assert_eq!(third.windows(), Some(5));
    assert!(third.has_before());
    assert!(third.has_after());

    let last = Window::frame(4, 5);
    assert!(!last.has_after());
}

#[test]
fn numbered_pages_read_from_one_and_load_more_has_no_page() {
    // The page number is read aloud, so it is one-based; `Window::index` is
    // the zero-based form for indexing.
    let third = Paging::pages(100, 50).of(400);
    assert_eq!(third.page(), Some(3));
    assert_eq!(third.pages_total(), Some(8));
    assert_eq!(third.total(), Some(400));
    assert!(third.has_previous());
    assert!(third.has_more());

    // Load-more grew a window from the start, so "page 2" would name
    // nothing and the type says so rather than inventing one.
    let grown = Paging::more(150).of(400);
    assert_eq!(grown.page(), None);
    assert_eq!(grown.pages_total(), None);
    assert_eq!(grown.shown(), 150);
    assert!(!grown.has_previous());
    assert!(grown.has_more());
}

#[test]
fn an_uncounted_paging_offers_forward_and_admits_no_total() {
    // What a host that will not pay for a COUNT describes. `None` here is
    // permanent: a total arriving later would widen the text that prints it,
    // which is the reflow "first paint is final paint" forbids.
    let feed = Paging::more(50);
    assert_eq!(feed.total(), None);
    assert_eq!(feed.pages_total(), None);
    assert_eq!(feed.remaining(), None);
    assert!(feed.has_more());
}

#[test]
fn what_is_left_is_derived_and_never_underflows() {
    assert_eq!(Paging::more(150).of(400).remaining(), Some(250));
    assert_eq!(Paging::pages(350, 50).of(400).remaining(), Some(0));
    // A host that overshot its own total gets zero rather than a wrapped
    // usize, which would print as "18446744073709551516 remaining".
    assert_eq!(Paging::more(500).of(400).remaining(), Some(0));
}

#[test]
fn a_fallback_is_authored_and_a_group_cannot_omit_it() {
    // No `Default`. The compiler is what enforces rule 2, so the assertion
    // that matters is one this file cannot write; what it can say is that
    // the four authored answers are distinct and none is privileged.
    let all = [
        Fallback::Wrap,
        Fallback::Stack,
        Fallback::Shed,
        Fallback::Menu,
    ];
    for (i, a) in all.iter().enumerate() {
        for b in &all[i + 1..] {
            assert_ne!(a, b);
        }
    }
}

#[test]
fn shedding_stops_at_essential_whatever_the_group_holds() {
    // Priority is read the same way for a group member as for a column,
    // which is the whole claim of generalising it off a table's columns.
    let members = [
        ("tabs", Priority::Essential),
        ("search", Priority::Secondary),
        ("count", Priority::Optional),
    ];
    let kept: Vec<_> = members
        .iter()
        .filter(|(_, p)| *p >= Priority::Essential)
        .map(|(n, _)| *n)
        .collect();
    assert_eq!(kept, ["tabs"]);
}

#[test]
fn a_role_says_what_a_part_is_worth_when_the_run_does_not_fit() {
    // The row still identifies itself after everything droppable has gone,
    // which is the property the ladder exists for.
    assert_eq!(RowPart::Primary.priority(), Priority::Essential);
    // A control is not a fact. Room comes out of what the row says, never
    // out of what it offers.
    assert_eq!(RowPart::Actions.priority(), Priority::Essential);
    assert_eq!(RowPart::Meta.priority(), Priority::Optional);
    assert_eq!(RowPart::Proportion.priority(), Priority::Optional);
    assert_eq!(RowPart::Secondary.priority(), Priority::Secondary);
    // Tokens sit in the middle deliberately: a toned badge is often the
    // most scannable thing in a row, so it does not go first.
    assert_eq!(RowPart::Tokens.priority(), Priority::Secondary);
}

#[test]
fn a_run_is_one_line_unless_the_description_says_two() {
    // The default is what every part did before flows existed, so a
    // description written against the old vocabulary keeps its rendering.
    assert_eq!(Flow::default(), Flow::Tight);
    assert_eq!(Flow::Tight.lines(), 1);
    assert_eq!(Flow::Relaxed.lines(), 2);
}

#[test]
fn an_unknown_flow_reads_as_one_line() {
    // `#[non_exhaustive]`'s cost, taken deliberately. A tier added upstream
    // reaches an old renderer as one line rather than as a build break, and
    // one line is the reading that cannot break a neighbour's layout. The
    // match in `lines` is what this holds; it fails if a new tier is given
    // an arm that returns something unbounded.
    for flow in [Flow::Tight, Flow::Relaxed] {
        assert!((1..=2).contains(&flow.lines()));
    }
}

#[test]
fn an_awaiting_mark_is_indeterminate_until_something_is_measured() {
    // The default is the common case: a call waits, and nothing about it is
    // countable. A determinate bar is the exception and says so.
    assert_eq!(Awaiting::default(), Awaiting::unmeasured());
    assert!(!Awaiting::unmeasured().is_determinate());
    assert!(Awaiting::of(40 * 1024 * 1024).is_determinate());
    assert_eq!(Awaiting::of(7).amount, Some(7));
}

#[test]
fn every_kind_but_theme_offers_no_themes() {
    for kind in [
        FieldKind::Text,
        FieldKind::Select,
        FieldKind::Radio,
        FieldKind::Checkbox,
        FieldKind::File,
        FieldKind::Hidden,
    ] {
        assert!(
            !kind.offers_themes(),
            "{kind:?} does not read a field's themes"
        );
    }
}

#[test]
fn a_contrast_tier_reads_worst_first() {
    // Matches `makeover::ContrastTier`, so an adopter's conversion cannot
    // invert an ordering by accident and a sort agrees across the seam.
    assert!(Contrast::Low < Contrast::Standard);
    assert!(Contrast::Standard < Contrast::High);
}

#[test]
fn the_groups_and_badges_have_one_spelling_each() {
    // The whole argument for these living here: three renderers picking
    // their own is one picker reading three ways.
    assert_eq!(ThemeVariant::Light.heading(), "Light");
    assert_eq!(ThemeVariant::Dark.heading(), "Dark");
    assert_eq!(ThemeVariant::HighContrast.heading(), "High Contrast");

    assert_eq!(ThemeVariant::HighContrast.as_str(), "high-contrast");

    assert_eq!(Contrast::High.badge(), "AA");
    assert_eq!(Contrast::Standard.badge(), "OK");
    assert_eq!(Contrast::Low.badge(), "low");
}

#[test]
fn the_variant_spelling_matches_the_theme_file_s_own() {
    // The seam this enum is duplicated across. `makeover::parse_meta` reads
    // `meta.variant` as one of these three strings; a rename on either side
    // that does not move together silently regroups every picker.
    for (variant, spelling) in [
        (ThemeVariant::Light, "light"),
        (ThemeVariant::Dark, "dark"),
        (ThemeVariant::HighContrast, "high-contrast"),
    ] {
        assert_eq!(variant.as_str(), spelling);
        assert_eq!(variant.to_string(), spelling);
    }
}

#[test]
fn a_column_kind_states_the_facts_every_renderer_reads() {
    // wiki `table-model`'s kind table, said as the four facts a host needs.
    assert!(ColumnKind::Number.aligns_end() && ColumnKind::Actions.aligns_end());
    assert!(
        !ColumnKind::Date.wraps(),
        "a date that wraps prints over its neighbour"
    );
    assert!(ColumnKind::Identifier.wraps() && ColumnKind::Identifier.monospace());
    assert!(ColumnKind::Code.monospace() && !ColumnKind::Code.wraps());
    assert!(ColumnKind::Date.tabular() && ColumnKind::Number.tabular());
    assert_eq!(ColumnRoom::new("x").kind, ColumnKind::Text);
}

#[test]
fn a_column_floor_is_declared_or_derived_and_always_on_the_ladder() {
    let declared = |heading, ch| ColumnRoom {
        min: Some(ch),
        ..ColumnRoom::new(heading)
    };
    // Declared wins, rounded up to an even count so a webview can name it.
    assert_eq!(declared("Buyer", 16).floor(), 16);
    assert_eq!(declared("Buyer", 15).floor(), 16);
    // Undeclared takes the widest of the kind, the heading and, for a column
    // that fills, sixteen.
    let content = |heading| ColumnRoom {
        width: Width::Content,
        ..ColumnRoom::new(heading)
    };
    let date = ColumnRoom {
        kind: ColumnKind::Date,
        ..content("Due")
    };
    assert_eq!(date.floor(), 10, "a date floors at what it holds");
    // Eleven characters and two for the capitals, rounded up.
    assert_eq!(content("Description").floor(), 14, "a long heading wins");
    // A caret needs room beside its heading.
    let sorted = ColumnRoom {
        caret: true,
        ..content("Description")
    };
    assert_eq!(sorted.floor(), 16);
    // The column that takes the slack holds the prose.
    assert_eq!(ColumnRoom::new("Item").floor(), 16);
    assert_eq!(content("Item").floor(), 8);
    // Held inside the ladder at both ends.
    assert_eq!(declared("x", 0).floor(), 2);
    assert_eq!(declared("x", 500).floor(), MIN_CEILING);
    assert_eq!(MIN_CEILING % 2, 0, "the ceiling is itself a rung");
}

/// Every kind floors at something a reader can still recognise the column by.
///
/// This replaces `only_the_kinds_that_cannot_truncate_hold_their_minimum`,
/// which asserted the whitelist removed in 0.51.0. A floor belongs to every
/// kind, so what is worth asserting is that none of them is nominal: the
/// narrowest floor in the set still holds a short value whole.
#[test]
fn every_kind_floors_wide_enough_to_be_recognised() {
    for kind in [
        ColumnKind::Text,
        ColumnKind::Identifier,
        ColumnKind::Date,
        ColumnKind::Number,
        ColumnKind::Code,
        ColumnKind::Status,
        ColumnKind::Actions,
    ] {
        assert!(
            kind.floor() >= 6,
            "{kind:?} floors at {} ch, which is a fragment rather than a column",
            kind.floor()
        );
        assert!(
            kind.floor() <= MIN_CEILING,
            "{kind:?} floors above the ladder the webview can carry"
        );
    }
    // A date is the widest fixed-shape value in the set and a number the
    // narrowest, which is the ordering the floors are chosen to express.
    assert!(ColumnKind::Date.floor() > ColumnKind::Number.floor());
}

#[test]
fn a_span_and_a_placement_at_the_end_of_the_axis_do_not_overflow() {
    let span = crate::Span::new(u16::MAX, 3);
    assert!(span.to() > span.from());
    let late = crate::Placement::new(1000, u16::MAX);
    assert_eq!(late.end(), u16::MAX);
    let edge = crate::Placement::new(u16::MAX, 10);
    assert_eq!(edge.end(), u16::MAX);
    assert!(late.overlaps(edge));
}

#[test]
fn a_column_floor_declared_past_the_ceiling_is_held_under_it() {
    let column = crate::ColumnRoom {
        min: Some(u16::MAX),
        ..crate::ColumnRoom::new("Wide")
    };
    assert_eq!(column.floor(), crate::MIN_CEILING);
}

#[test]
fn a_share_rounds_to_nearest_and_never_invents_width() {
    let share = crate::Share::percent(21);
    assert_eq!(share.of(10), 2);
    assert_eq!(crate::Share::percent(25).of(10), 3);
    assert_eq!(share.of(0), 0);
    assert_eq!(crate::Share::percent(5).of(10), 1);
    assert_eq!(crate::Share::percent(5).of(4), 1);
    assert!(crate::Share::percent(95).of(7) <= 7);
}

#[test]
fn a_misaligned_page_counts_the_short_page_before_it() {
    let paging = crate::Paging::pages(5, 10).of(20);
    assert_eq!(paging.page(), Some(2));
    assert_eq!(paging.pages_total(), Some(3));
    assert!(paging.has_previous());
    let aligned = crate::Paging::pages(10, 10).of(20);
    assert_eq!(aligned.page(), Some(2));
    assert_eq!(aligned.pages_total(), Some(2));
    let first = crate::Paging::pages(0, 10).of(25);
    assert_eq!((first.page(), first.pages_total()), (Some(1), Some(3)));
}

#[test]
fn a_budget_counts_only_the_columns_kept_at_its_cutoff() {
    let floored = |heading, ch, priority| ColumnRoom {
        min: Some(ch),
        priority,
        ..ColumnRoom::new(heading)
    };
    let columns = [
        floored("name", 20, Priority::Essential),
        floored("size", 8, Priority::Optional),
        floored("owner", 10, Priority::Secondary),
    ];
    let all = ColumnRoom::budget(&columns, Priority::Optional);
    assert_eq!((all.columns, all.floors), (3, 38));
    let kept = ColumnRoom::budget(&columns, Priority::Essential);
    assert_eq!((kept.columns, kept.floors), (1, 20));
    // One gap between adjacent columns and one at each edge.
    assert!((all.width(1.0, 2.0) - (38.0 + 8.0)).abs() < f32::EPSILON);
}

#[test]
fn the_cutoff_rises_only_until_the_columns_fit() {
    let floored = |heading, ch, priority| ColumnRoom {
        min: Some(ch),
        priority,
        ..ColumnRoom::new(heading)
    };
    let columns = [
        floored("name", 20, Priority::Essential),
        floored("size", 8, Priority::Optional),
        floored("owner", 10, Priority::Secondary),
    ];
    let at = |width: f32| ColumnRoom::cutoff_for(&columns, |b| b.width(1.0, 1.0) <= width);
    assert_eq!(at(100.0), Priority::Optional);
    assert_eq!(at(33.0), Priority::Secondary);
    assert_eq!(at(22.0), Priority::Essential);
    // Too narrow even for the essential column: squeezed, never dropped.
    assert_eq!(at(1.0), Priority::Essential);
    assert_eq!(Priority::RAISING.last(), Some(&Priority::Essential));
}

#[test]
fn sizing_answers_by_name_and_falls_back() {
    let sizing = crate::Sizing::new(&[("due", 12u16)], 8);
    assert_eq!(sizing.length_for("due"), 12);
    assert_eq!(sizing.length_for("title"), 8);
}

#[test]
fn a_growing_set_has_no_page_to_number() {
    assert_eq!(Paging::more(150).of(400).page(), None);
    assert_eq!(
        Paging::pages(50, 50).of(400).kind,
        crate::PageKind::Numbered
    );
    let window = Window::new(10, 5).of(40);
    assert_eq!(
        (window.from(), window.count(), window.length()),
        (10, 5, Some(40))
    );
}

#[test]
fn a_plate_is_a_group_lifted_rather_than_a_pane_turned_over() {
    // The two things a pane says, a scroll and a sunk surface, are both
    // absent from a group; a plate keeps the first absence and inverts the
    // second. It carries no name, for the reason a group carries none.
    assert_eq!(Region::Plate.depth(), Depth::Raised);
    assert_ne!(Region::Plate.depth(), Region::Pane.depth());
    assert_ne!(Region::Plate, Region::Group);
    assert!(Region::Plate.described());
    assert!(!Region::Plate.owed());
    assert_eq!(Region::Plate.name(), None);
}