ferrosys 0.8.0

Pure-Rust filesystem formatter and reader: ext4, ext3, ext2, FAT32, FAT16, FAT12, exFAT, btrfs, and APFS — rootless, in userspace, byte-reproducible
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
//! The up-case table an exFAT volume folds names through, and the recommended table the
//! format defines.
//!
//! exFAT compares names case-insensitively, and what "case-insensitively" means is not a
//! property of Unicode on the volume's behalf — it is a mapping the volume itself carries, in
//! the cluster heap, described by an `0x82` directory entry that advertises the mapping's
//! checksum. Two implementations agree about whether `README` and `readme` are one name
//! exactly when they fold through the same table.
//!
//! # The recommended table, and why its checksum is written down
//!
//! [`RECOMMENDED_UPCASE_TABLE`] is the mapping the format recommends, and it is what every
//! current implementation writes. A volume carrying it folds names the way every other
//! implementation folds them, which is the whole point of a table that could have been
//! anything.
//!
//! Its checksum is [`RECOMMENDED_UPCASE_CHECKSUM`], a value written down rather than derived:
//! a table checked against arithmetic over its own bytes checks out however badly it was
//! transcribed, the way a self-signed certificate proves nothing. The constant is what says
//! these units are the recommended table and not a table that resembles it.
//!
//! # The stored form is compressed, and mostly is not
//!
//! The table is a sequence of 16-bit units covering the characters from `U+0000` upward, one
//! unit per character, each unit the character it maps to. A unit of `0xFFFF` is the one
//! exception: it is a marker, and the unit after it is a count of characters that map to
//! themselves and are therefore not stored.
//!
//! The recommended table uses four such runs and stores the remaining 2910 characters
//! outright, which is what makes it 5836 bytes rather than the 131072 an uncompressed table
//! of the whole Basic Multilingual Plane would be. Its last unit is `0xFFFF` as a *mapping* —
//! `U+FFFF` maps to itself explicitly — and the table ends there, having covered exactly
//! 65536 characters.

use crate::bytes::put_u16;

use super::ParseError;

/// The 16-bit units the up-case table the format recommends is stored as.
///
/// Held as the units the format stores rather than as the bytes a volume holds, so the
/// little-endian conversion happens once, in [`write_upcase_table`], and a transcription
/// error is a wrong character rather than a swapped pair of bytes.
///
/// A table this crate writes is checked against [`RECOMMENDED_UPCASE_CHECKSUM`] rather than
/// against itself — see the module's own documentation for why that distinction is the whole
/// of it.
pub const RECOMMENDED_UPCASE_TABLE: [u16; 2918] = [
    0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, 0x000A, 0x000B,
    0x000C, 0x000D, 0x000E, 0x000F, 0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017,
    0x0018, 0x0019, 0x001A, 0x001B, 0x001C, 0x001D, 0x001E, 0x001F, 0x0020, 0x0021, 0x0022, 0x0023,
    0x0024, 0x0025, 0x0026, 0x0027, 0x0028, 0x0029, 0x002A, 0x002B, 0x002C, 0x002D, 0x002E, 0x002F,
    0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, 0x0038, 0x0039, 0x003A, 0x003B,
    0x003C, 0x003D, 0x003E, 0x003F, 0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047,
    0x0048, 0x0049, 0x004A, 0x004B, 0x004C, 0x004D, 0x004E, 0x004F, 0x0050, 0x0051, 0x0052, 0x0053,
    0x0054, 0x0055, 0x0056, 0x0057, 0x0058, 0x0059, 0x005A, 0x005B, 0x005C, 0x005D, 0x005E, 0x005F,
    0x0060, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, 0x0048, 0x0049, 0x004A, 0x004B,
    0x004C, 0x004D, 0x004E, 0x004F, 0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057,
    0x0058, 0x0059, 0x005A, 0x007B, 0x007C, 0x007D, 0x007E, 0x007F, 0x0080, 0x0081, 0x0082, 0x0083,
    0x0084, 0x0085, 0x0086, 0x0087, 0x0088, 0x0089, 0x008A, 0x008B, 0x008C, 0x008D, 0x008E, 0x008F,
    0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097, 0x0098, 0x0099, 0x009A, 0x009B,
    0x009C, 0x009D, 0x009E, 0x009F, 0x00A0, 0x00A1, 0x00A2, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7,
    0x00A8, 0x00A9, 0x00AA, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF, 0x00B0, 0x00B1, 0x00B2, 0x00B3,
    0x00B4, 0x00B5, 0x00B6, 0x00B7, 0x00B8, 0x00B9, 0x00BA, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x00BF,
    0x00C0, 0x00C1, 0x00C2, 0x00C3, 0x00C4, 0x00C5, 0x00C6, 0x00C7, 0x00C8, 0x00C9, 0x00CA, 0x00CB,
    0x00CC, 0x00CD, 0x00CE, 0x00CF, 0x00D0, 0x00D1, 0x00D2, 0x00D3, 0x00D4, 0x00D5, 0x00D6, 0x00D7,
    0x00D8, 0x00D9, 0x00DA, 0x00DB, 0x00DC, 0x00DD, 0x00DE, 0x00DF, 0x00C0, 0x00C1, 0x00C2, 0x00C3,
    0x00C4, 0x00C5, 0x00C6, 0x00C7, 0x00C8, 0x00C9, 0x00CA, 0x00CB, 0x00CC, 0x00CD, 0x00CE, 0x00CF,
    0x00D0, 0x00D1, 0x00D2, 0x00D3, 0x00D4, 0x00D5, 0x00D6, 0x00F7, 0x00D8, 0x00D9, 0x00DA, 0x00DB,
    0x00DC, 0x00DD, 0x00DE, 0x0178, 0x0100, 0x0100, 0x0102, 0x0102, 0x0104, 0x0104, 0x0106, 0x0106,
    0x0108, 0x0108, 0x010A, 0x010A, 0x010C, 0x010C, 0x010E, 0x010E, 0x0110, 0x0110, 0x0112, 0x0112,
    0x0114, 0x0114, 0x0116, 0x0116, 0x0118, 0x0118, 0x011A, 0x011A, 0x011C, 0x011C, 0x011E, 0x011E,
    0x0120, 0x0120, 0x0122, 0x0122, 0x0124, 0x0124, 0x0126, 0x0126, 0x0128, 0x0128, 0x012A, 0x012A,
    0x012C, 0x012C, 0x012E, 0x012E, 0x0130, 0x0131, 0x0132, 0x0132, 0x0134, 0x0134, 0x0136, 0x0136,
    0x0138, 0x0139, 0x0139, 0x013B, 0x013B, 0x013D, 0x013D, 0x013F, 0x013F, 0x0141, 0x0141, 0x0143,
    0x0143, 0x0145, 0x0145, 0x0147, 0x0147, 0x0149, 0x014A, 0x014A, 0x014C, 0x014C, 0x014E, 0x014E,
    0x0150, 0x0150, 0x0152, 0x0152, 0x0154, 0x0154, 0x0156, 0x0156, 0x0158, 0x0158, 0x015A, 0x015A,
    0x015C, 0x015C, 0x015E, 0x015E, 0x0160, 0x0160, 0x0162, 0x0162, 0x0164, 0x0164, 0x0166, 0x0166,
    0x0168, 0x0168, 0x016A, 0x016A, 0x016C, 0x016C, 0x016E, 0x016E, 0x0170, 0x0170, 0x0172, 0x0172,
    0x0174, 0x0174, 0x0176, 0x0176, 0x0178, 0x0179, 0x0179, 0x017B, 0x017B, 0x017D, 0x017D, 0x017F,
    0x0243, 0x0181, 0x0182, 0x0182, 0x0184, 0x0184, 0x0186, 0x0187, 0x0187, 0x0189, 0x018A, 0x018B,
    0x018B, 0x018D, 0x018E, 0x018F, 0x0190, 0x0191, 0x0191, 0x0193, 0x0194, 0x01F6, 0x0196, 0x0197,
    0x0198, 0x0198, 0x023D, 0x019B, 0x019C, 0x019D, 0x0220, 0x019F, 0x01A0, 0x01A0, 0x01A2, 0x01A2,
    0x01A4, 0x01A4, 0x01A6, 0x01A7, 0x01A7, 0x01A9, 0x01AA, 0x01AB, 0x01AC, 0x01AC, 0x01AE, 0x01AF,
    0x01AF, 0x01B1, 0x01B2, 0x01B3, 0x01B3, 0x01B5, 0x01B5, 0x01B7, 0x01B8, 0x01B8, 0x01BA, 0x01BB,
    0x01BC, 0x01BC, 0x01BE, 0x01F7, 0x01C0, 0x01C1, 0x01C2, 0x01C3, 0x01C4, 0x01C5, 0x01C4, 0x01C7,
    0x01C8, 0x01C7, 0x01CA, 0x01CB, 0x01CA, 0x01CD, 0x01CD, 0x01CF, 0x01CF, 0x01D1, 0x01D1, 0x01D3,
    0x01D3, 0x01D5, 0x01D5, 0x01D7, 0x01D7, 0x01D9, 0x01D9, 0x01DB, 0x01DB, 0x018E, 0x01DE, 0x01DE,
    0x01E0, 0x01E0, 0x01E2, 0x01E2, 0x01E4, 0x01E4, 0x01E6, 0x01E6, 0x01E8, 0x01E8, 0x01EA, 0x01EA,
    0x01EC, 0x01EC, 0x01EE, 0x01EE, 0x01F0, 0x01F1, 0x01F2, 0x01F1, 0x01F4, 0x01F4, 0x01F6, 0x01F7,
    0x01F8, 0x01F8, 0x01FA, 0x01FA, 0x01FC, 0x01FC, 0x01FE, 0x01FE, 0x0200, 0x0200, 0x0202, 0x0202,
    0x0204, 0x0204, 0x0206, 0x0206, 0x0208, 0x0208, 0x020A, 0x020A, 0x020C, 0x020C, 0x020E, 0x020E,
    0x0210, 0x0210, 0x0212, 0x0212, 0x0214, 0x0214, 0x0216, 0x0216, 0x0218, 0x0218, 0x021A, 0x021A,
    0x021C, 0x021C, 0x021E, 0x021E, 0x0220, 0x0221, 0x0222, 0x0222, 0x0224, 0x0224, 0x0226, 0x0226,
    0x0228, 0x0228, 0x022A, 0x022A, 0x022C, 0x022C, 0x022E, 0x022E, 0x0230, 0x0230, 0x0232, 0x0232,
    0x0234, 0x0235, 0x0236, 0x0237, 0x0238, 0x0239, 0x2C65, 0x023B, 0x023B, 0x023D, 0x2C66, 0x023F,
    0x0240, 0x0241, 0x0241, 0x0243, 0x0244, 0x0245, 0x0246, 0x0246, 0x0248, 0x0248, 0x024A, 0x024A,
    0x024C, 0x024C, 0x024E, 0x024E, 0x0250, 0x0251, 0x0252, 0x0181, 0x0186, 0x0255, 0x0189, 0x018A,
    0x0258, 0x018F, 0x025A, 0x0190, 0x025C, 0x025D, 0x025E, 0x025F, 0x0193, 0x0261, 0x0262, 0x0194,
    0x0264, 0x0265, 0x0266, 0x0267, 0x0197, 0x0196, 0x026A, 0x2C62, 0x026C, 0x026D, 0x026E, 0x019C,
    0x0270, 0x0271, 0x019D, 0x0273, 0x0274, 0x019F, 0x0276, 0x0277, 0x0278, 0x0279, 0x027A, 0x027B,
    0x027C, 0x2C64, 0x027E, 0x027F, 0x01A6, 0x0281, 0x0282, 0x01A9, 0x0284, 0x0285, 0x0286, 0x0287,
    0x01AE, 0x0244, 0x01B1, 0x01B2, 0x0245, 0x028D, 0x028E, 0x028F, 0x0290, 0x0291, 0x01B7, 0x0293,
    0x0294, 0x0295, 0x0296, 0x0297, 0x0298, 0x0299, 0x029A, 0x029B, 0x029C, 0x029D, 0x029E, 0x029F,
    0x02A0, 0x02A1, 0x02A2, 0x02A3, 0x02A4, 0x02A5, 0x02A6, 0x02A7, 0x02A8, 0x02A9, 0x02AA, 0x02AB,
    0x02AC, 0x02AD, 0x02AE, 0x02AF, 0x02B0, 0x02B1, 0x02B2, 0x02B3, 0x02B4, 0x02B5, 0x02B6, 0x02B7,
    0x02B8, 0x02B9, 0x02BA, 0x02BB, 0x02BC, 0x02BD, 0x02BE, 0x02BF, 0x02C0, 0x02C1, 0x02C2, 0x02C3,
    0x02C4, 0x02C5, 0x02C6, 0x02C7, 0x02C8, 0x02C9, 0x02CA, 0x02CB, 0x02CC, 0x02CD, 0x02CE, 0x02CF,
    0x02D0, 0x02D1, 0x02D2, 0x02D3, 0x02D4, 0x02D5, 0x02D6, 0x02D7, 0x02D8, 0x02D9, 0x02DA, 0x02DB,
    0x02DC, 0x02DD, 0x02DE, 0x02DF, 0x02E0, 0x02E1, 0x02E2, 0x02E3, 0x02E4, 0x02E5, 0x02E6, 0x02E7,
    0x02E8, 0x02E9, 0x02EA, 0x02EB, 0x02EC, 0x02ED, 0x02EE, 0x02EF, 0x02F0, 0x02F1, 0x02F2, 0x02F3,
    0x02F4, 0x02F5, 0x02F6, 0x02F7, 0x02F8, 0x02F9, 0x02FA, 0x02FB, 0x02FC, 0x02FD, 0x02FE, 0x02FF,
    0x0300, 0x0301, 0x0302, 0x0303, 0x0304, 0x0305, 0x0306, 0x0307, 0x0308, 0x0309, 0x030A, 0x030B,
    0x030C, 0x030D, 0x030E, 0x030F, 0x0310, 0x0311, 0x0312, 0x0313, 0x0314, 0x0315, 0x0316, 0x0317,
    0x0318, 0x0319, 0x031A, 0x031B, 0x031C, 0x031D, 0x031E, 0x031F, 0x0320, 0x0321, 0x0322, 0x0323,
    0x0324, 0x0325, 0x0326, 0x0327, 0x0328, 0x0329, 0x032A, 0x032B, 0x032C, 0x032D, 0x032E, 0x032F,
    0x0330, 0x0331, 0x0332, 0x0333, 0x0334, 0x0335, 0x0336, 0x0337, 0x0338, 0x0339, 0x033A, 0x033B,
    0x033C, 0x033D, 0x033E, 0x033F, 0x0340, 0x0341, 0x0342, 0x0343, 0x0344, 0x0345, 0x0346, 0x0347,
    0x0348, 0x0349, 0x034A, 0x034B, 0x034C, 0x034D, 0x034E, 0x034F, 0x0350, 0x0351, 0x0352, 0x0353,
    0x0354, 0x0355, 0x0356, 0x0357, 0x0358, 0x0359, 0x035A, 0x035B, 0x035C, 0x035D, 0x035E, 0x035F,
    0x0360, 0x0361, 0x0362, 0x0363, 0x0364, 0x0365, 0x0366, 0x0367, 0x0368, 0x0369, 0x036A, 0x036B,
    0x036C, 0x036D, 0x036E, 0x036F, 0x0370, 0x0371, 0x0372, 0x0373, 0x0374, 0x0375, 0x0376, 0x0377,
    0x0378, 0x0379, 0x037A, 0x03FD, 0x03FE, 0x03FF, 0x037E, 0x037F, 0x0380, 0x0381, 0x0382, 0x0383,
    0x0384, 0x0385, 0x0386, 0x0387, 0x0388, 0x0389, 0x038A, 0x038B, 0x038C, 0x038D, 0x038E, 0x038F,
    0x0390, 0x0391, 0x0392, 0x0393, 0x0394, 0x0395, 0x0396, 0x0397, 0x0398, 0x0399, 0x039A, 0x039B,
    0x039C, 0x039D, 0x039E, 0x039F, 0x03A0, 0x03A1, 0x03A2, 0x03A3, 0x03A4, 0x03A5, 0x03A6, 0x03A7,
    0x03A8, 0x03A9, 0x03AA, 0x03AB, 0x0386, 0x0388, 0x0389, 0x038A, 0x03B0, 0x0391, 0x0392, 0x0393,
    0x0394, 0x0395, 0x0396, 0x0397, 0x0398, 0x0399, 0x039A, 0x039B, 0x039C, 0x039D, 0x039E, 0x039F,
    0x03A0, 0x03A1, 0x03A3, 0x03A3, 0x03A4, 0x03A5, 0x03A6, 0x03A7, 0x03A8, 0x03A9, 0x03AA, 0x03AB,
    0x038C, 0x038E, 0x038F, 0x03CF, 0x03D0, 0x03D1, 0x03D2, 0x03D3, 0x03D4, 0x03D5, 0x03D6, 0x03D7,
    0x03D8, 0x03D8, 0x03DA, 0x03DA, 0x03DC, 0x03DC, 0x03DE, 0x03DE, 0x03E0, 0x03E0, 0x03E2, 0x03E2,
    0x03E4, 0x03E4, 0x03E6, 0x03E6, 0x03E8, 0x03E8, 0x03EA, 0x03EA, 0x03EC, 0x03EC, 0x03EE, 0x03EE,
    0x03F0, 0x03F1, 0x03F9, 0x03F3, 0x03F4, 0x03F5, 0x03F6, 0x03F7, 0x03F7, 0x03F9, 0x03FA, 0x03FA,
    0x03FC, 0x03FD, 0x03FE, 0x03FF, 0x0400, 0x0401, 0x0402, 0x0403, 0x0404, 0x0405, 0x0406, 0x0407,
    0x0408, 0x0409, 0x040A, 0x040B, 0x040C, 0x040D, 0x040E, 0x040F, 0x0410, 0x0411, 0x0412, 0x0413,
    0x0414, 0x0415, 0x0416, 0x0417, 0x0418, 0x0419, 0x041A, 0x041B, 0x041C, 0x041D, 0x041E, 0x041F,
    0x0420, 0x0421, 0x0422, 0x0423, 0x0424, 0x0425, 0x0426, 0x0427, 0x0428, 0x0429, 0x042A, 0x042B,
    0x042C, 0x042D, 0x042E, 0x042F, 0x0410, 0x0411, 0x0412, 0x0413, 0x0414, 0x0415, 0x0416, 0x0417,
    0x0418, 0x0419, 0x041A, 0x041B, 0x041C, 0x041D, 0x041E, 0x041F, 0x0420, 0x0421, 0x0422, 0x0423,
    0x0424, 0x0425, 0x0426, 0x0427, 0x0428, 0x0429, 0x042A, 0x042B, 0x042C, 0x042D, 0x042E, 0x042F,
    0x0400, 0x0401, 0x0402, 0x0403, 0x0404, 0x0405, 0x0406, 0x0407, 0x0408, 0x0409, 0x040A, 0x040B,
    0x040C, 0x040D, 0x040E, 0x040F, 0x0460, 0x0460, 0x0462, 0x0462, 0x0464, 0x0464, 0x0466, 0x0466,
    0x0468, 0x0468, 0x046A, 0x046A, 0x046C, 0x046C, 0x046E, 0x046E, 0x0470, 0x0470, 0x0472, 0x0472,
    0x0474, 0x0474, 0x0476, 0x0476, 0x0478, 0x0478, 0x047A, 0x047A, 0x047C, 0x047C, 0x047E, 0x047E,
    0x0480, 0x0480, 0x0482, 0x0483, 0x0484, 0x0485, 0x0486, 0x0487, 0x0488, 0x0489, 0x048A, 0x048A,
    0x048C, 0x048C, 0x048E, 0x048E, 0x0490, 0x0490, 0x0492, 0x0492, 0x0494, 0x0494, 0x0496, 0x0496,
    0x0498, 0x0498, 0x049A, 0x049A, 0x049C, 0x049C, 0x049E, 0x049E, 0x04A0, 0x04A0, 0x04A2, 0x04A2,
    0x04A4, 0x04A4, 0x04A6, 0x04A6, 0x04A8, 0x04A8, 0x04AA, 0x04AA, 0x04AC, 0x04AC, 0x04AE, 0x04AE,
    0x04B0, 0x04B0, 0x04B2, 0x04B2, 0x04B4, 0x04B4, 0x04B6, 0x04B6, 0x04B8, 0x04B8, 0x04BA, 0x04BA,
    0x04BC, 0x04BC, 0x04BE, 0x04BE, 0x04C0, 0x04C1, 0x04C1, 0x04C3, 0x04C3, 0x04C5, 0x04C5, 0x04C7,
    0x04C7, 0x04C9, 0x04C9, 0x04CB, 0x04CB, 0x04CD, 0x04CD, 0x04C0, 0x04D0, 0x04D0, 0x04D2, 0x04D2,
    0x04D4, 0x04D4, 0x04D6, 0x04D6, 0x04D8, 0x04D8, 0x04DA, 0x04DA, 0x04DC, 0x04DC, 0x04DE, 0x04DE,
    0x04E0, 0x04E0, 0x04E2, 0x04E2, 0x04E4, 0x04E4, 0x04E6, 0x04E6, 0x04E8, 0x04E8, 0x04EA, 0x04EA,
    0x04EC, 0x04EC, 0x04EE, 0x04EE, 0x04F0, 0x04F0, 0x04F2, 0x04F2, 0x04F4, 0x04F4, 0x04F6, 0x04F6,
    0x04F8, 0x04F8, 0x04FA, 0x04FA, 0x04FC, 0x04FC, 0x04FE, 0x04FE, 0x0500, 0x0500, 0x0502, 0x0502,
    0x0504, 0x0504, 0x0506, 0x0506, 0x0508, 0x0508, 0x050A, 0x050A, 0x050C, 0x050C, 0x050E, 0x050E,
    0x0510, 0x0510, 0x0512, 0x0512, 0x0514, 0x0515, 0x0516, 0x0517, 0x0518, 0x0519, 0x051A, 0x051B,
    0x051C, 0x051D, 0x051E, 0x051F, 0x0520, 0x0521, 0x0522, 0x0523, 0x0524, 0x0525, 0x0526, 0x0527,
    0x0528, 0x0529, 0x052A, 0x052B, 0x052C, 0x052D, 0x052E, 0x052F, 0x0530, 0x0531, 0x0532, 0x0533,
    0x0534, 0x0535, 0x0536, 0x0537, 0x0538, 0x0539, 0x053A, 0x053B, 0x053C, 0x053D, 0x053E, 0x053F,
    0x0540, 0x0541, 0x0542, 0x0543, 0x0544, 0x0545, 0x0546, 0x0547, 0x0548, 0x0549, 0x054A, 0x054B,
    0x054C, 0x054D, 0x054E, 0x054F, 0x0550, 0x0551, 0x0552, 0x0553, 0x0554, 0x0555, 0x0556, 0x0557,
    0x0558, 0x0559, 0x055A, 0x055B, 0x055C, 0x055D, 0x055E, 0x055F, 0x0560, 0x0531, 0x0532, 0x0533,
    0x0534, 0x0535, 0x0536, 0x0537, 0x0538, 0x0539, 0x053A, 0x053B, 0x053C, 0x053D, 0x053E, 0x053F,
    0x0540, 0x0541, 0x0542, 0x0543, 0x0544, 0x0545, 0x0546, 0x0547, 0x0548, 0x0549, 0x054A, 0x054B,
    0x054C, 0x054D, 0x054E, 0x054F, 0x0550, 0x0551, 0x0552, 0x0553, 0x0554, 0x0555, 0x0556, 0xFFFF,
    0x17F6, 0x2C63, 0x1D7E, 0x1D7F, 0x1D80, 0x1D81, 0x1D82, 0x1D83, 0x1D84, 0x1D85, 0x1D86, 0x1D87,
    0x1D88, 0x1D89, 0x1D8A, 0x1D8B, 0x1D8C, 0x1D8D, 0x1D8E, 0x1D8F, 0x1D90, 0x1D91, 0x1D92, 0x1D93,
    0x1D94, 0x1D95, 0x1D96, 0x1D97, 0x1D98, 0x1D99, 0x1D9A, 0x1D9B, 0x1D9C, 0x1D9D, 0x1D9E, 0x1D9F,
    0x1DA0, 0x1DA1, 0x1DA2, 0x1DA3, 0x1DA4, 0x1DA5, 0x1DA6, 0x1DA7, 0x1DA8, 0x1DA9, 0x1DAA, 0x1DAB,
    0x1DAC, 0x1DAD, 0x1DAE, 0x1DAF, 0x1DB0, 0x1DB1, 0x1DB2, 0x1DB3, 0x1DB4, 0x1DB5, 0x1DB6, 0x1DB7,
    0x1DB8, 0x1DB9, 0x1DBA, 0x1DBB, 0x1DBC, 0x1DBD, 0x1DBE, 0x1DBF, 0x1DC0, 0x1DC1, 0x1DC2, 0x1DC3,
    0x1DC4, 0x1DC5, 0x1DC6, 0x1DC7, 0x1DC8, 0x1DC9, 0x1DCA, 0x1DCB, 0x1DCC, 0x1DCD, 0x1DCE, 0x1DCF,
    0x1DD0, 0x1DD1, 0x1DD2, 0x1DD3, 0x1DD4, 0x1DD5, 0x1DD6, 0x1DD7, 0x1DD8, 0x1DD9, 0x1DDA, 0x1DDB,
    0x1DDC, 0x1DDD, 0x1DDE, 0x1DDF, 0x1DE0, 0x1DE1, 0x1DE2, 0x1DE3, 0x1DE4, 0x1DE5, 0x1DE6, 0x1DE7,
    0x1DE8, 0x1DE9, 0x1DEA, 0x1DEB, 0x1DEC, 0x1DED, 0x1DEE, 0x1DEF, 0x1DF0, 0x1DF1, 0x1DF2, 0x1DF3,
    0x1DF4, 0x1DF5, 0x1DF6, 0x1DF7, 0x1DF8, 0x1DF9, 0x1DFA, 0x1DFB, 0x1DFC, 0x1DFD, 0x1DFE, 0x1DFF,
    0x1E00, 0x1E00, 0x1E02, 0x1E02, 0x1E04, 0x1E04, 0x1E06, 0x1E06, 0x1E08, 0x1E08, 0x1E0A, 0x1E0A,
    0x1E0C, 0x1E0C, 0x1E0E, 0x1E0E, 0x1E10, 0x1E10, 0x1E12, 0x1E12, 0x1E14, 0x1E14, 0x1E16, 0x1E16,
    0x1E18, 0x1E18, 0x1E1A, 0x1E1A, 0x1E1C, 0x1E1C, 0x1E1E, 0x1E1E, 0x1E20, 0x1E20, 0x1E22, 0x1E22,
    0x1E24, 0x1E24, 0x1E26, 0x1E26, 0x1E28, 0x1E28, 0x1E2A, 0x1E2A, 0x1E2C, 0x1E2C, 0x1E2E, 0x1E2E,
    0x1E30, 0x1E30, 0x1E32, 0x1E32, 0x1E34, 0x1E34, 0x1E36, 0x1E36, 0x1E38, 0x1E38, 0x1E3A, 0x1E3A,
    0x1E3C, 0x1E3C, 0x1E3E, 0x1E3E, 0x1E40, 0x1E40, 0x1E42, 0x1E42, 0x1E44, 0x1E44, 0x1E46, 0x1E46,
    0x1E48, 0x1E48, 0x1E4A, 0x1E4A, 0x1E4C, 0x1E4C, 0x1E4E, 0x1E4E, 0x1E50, 0x1E50, 0x1E52, 0x1E52,
    0x1E54, 0x1E54, 0x1E56, 0x1E56, 0x1E58, 0x1E58, 0x1E5A, 0x1E5A, 0x1E5C, 0x1E5C, 0x1E5E, 0x1E5E,
    0x1E60, 0x1E60, 0x1E62, 0x1E62, 0x1E64, 0x1E64, 0x1E66, 0x1E66, 0x1E68, 0x1E68, 0x1E6A, 0x1E6A,
    0x1E6C, 0x1E6C, 0x1E6E, 0x1E6E, 0x1E70, 0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1FF6, 0x1FF7,
    0x1FF8, 0x1FF9, 0x1FFA, 0x1FFB, 0x1FF3, 0x1FFD, 0x1FFE, 0x1FFF, 0x2000, 0x2001, 0x2002, 0x2003,
    0x2004, 0x2005, 0x2006, 0x2007, 0x2008, 0x2009, 0x200A, 0x200B, 0x200C, 0x200D, 0x200E, 0x200F,
    0x2010, 0x2011, 0x2012, 0x2013, 0x2014, 0x2015, 0x2016, 0x2017, 0x2018, 0x2019, 0x201A, 0x201B,
    0x201C, 0x201D, 0x201E, 0x201F, 0x2020, 0x2021, 0x2022, 0x2023, 0x2024, 0x2025, 0x2026, 0x2027,
    0x2028, 0x2029, 0x202A, 0x202B, 0x202C, 0x202D, 0x202E, 0x202F, 0x2030, 0x2031, 0x2032, 0x2033,
    0x2034, 0x2035, 0x2036, 0x2037, 0x2038, 0x2039, 0x203A, 0x203B, 0x203C, 0x203D, 0x203E, 0x203F,
    0x2040, 0x2041, 0x2042, 0x2043, 0x2044, 0x2045, 0x2046, 0x2047, 0x2048, 0x2049, 0x204A, 0x204B,
    0x204C, 0x204D, 0x204E, 0x204F, 0x2050, 0x2051, 0x2052, 0x2053, 0x2054, 0x2055, 0x2056, 0x2057,
    0x2058, 0x2059, 0x205A, 0x205B, 0x205C, 0x205D, 0x205E, 0x205F, 0x2060, 0x2061, 0x2062, 0x2063,
    0x2064, 0x2065, 0x2066, 0x2067, 0x2068, 0x2069, 0x206A, 0x206B, 0x206C, 0x206D, 0x206E, 0x206F,
    0x2070, 0x2071, 0x2072, 0x2073, 0x2074, 0x2075, 0x2076, 0x2077, 0x2078, 0x2079, 0x207A, 0x207B,
    0x207C, 0x207D, 0x207E, 0x207F, 0x2080, 0x2081, 0x2082, 0x2083, 0x2084, 0x2085, 0x2086, 0x2087,
    0x2088, 0x2089, 0x208A, 0x208B, 0x208C, 0x208D, 0x208E, 0x208F, 0x2090, 0x2091, 0x2092, 0x2093,
    0x2094, 0x2095, 0x2096, 0x2097, 0x2098, 0x2099, 0x209A, 0x209B, 0x209C, 0x209D, 0x209E, 0x209F,
    0x20A0, 0x20A1, 0x20A2, 0x20A3, 0x20A4, 0x20A5, 0x20A6, 0x20A7, 0x20A8, 0x20A9, 0x20AA, 0x20AB,
    0x20AC, 0x20AD, 0x20AE, 0x20AF, 0x20B0, 0x20B1, 0x20B2, 0x20B3, 0x20B4, 0x20B5, 0x20B6, 0x20B7,
    0x20B8, 0x20B9, 0x20BA, 0x20BB, 0x20BC, 0x20BD, 0x20BE, 0x20BF, 0x20C0, 0x20C1, 0x20C2, 0x20C3,
    0x20C4, 0x20C5, 0x20C6, 0x20C7, 0x20C8, 0x20C9, 0x20CA, 0x20CB, 0x20CC, 0x20CD, 0x20CE, 0x20CF,
    0x20D0, 0x20D1, 0x20D2, 0x20D3, 0x20D4, 0x20D5, 0x20D6, 0x20D7, 0x20D8, 0x20D9, 0x20DA, 0x20DB,
    0x20DC, 0x20DD, 0x20DE, 0x20DF, 0x20E0, 0x20E1, 0x20E2, 0x20E3, 0x20E4, 0x20E5, 0x20E6, 0x20E7,
    0x20E8, 0x20E9, 0x20EA, 0x20EB, 0x20EC, 0x20ED, 0x20EE, 0x20EF, 0x20F0, 0x20F1, 0x20F2, 0x20F3,
    0x20F4, 0x20F5, 0x20F6, 0x20F7, 0x20F8, 0x20F9, 0x20FA, 0x20FB, 0x20FC, 0x20FD, 0x20FE, 0x20FF,
    0x2100, 0x2101, 0x2102, 0x2103, 0x2104, 0x2105, 0x2106, 0x2107, 0x2108, 0x2109, 0x210A, 0x210B,
    0x210C, 0x210D, 0x210E, 0x210F, 0x2110, 0x2111, 0x2112, 0x2113, 0x2114, 0x2115, 0x2116, 0x2117,
    0x2118, 0x2119, 0x211A, 0x211B, 0x211C, 0x211D, 0x211E, 0x211F, 0x2120, 0x2121, 0x2122, 0x2123,
    0x2124, 0x2125, 0x2126, 0x2127, 0x2128, 0x2129, 0x212A, 0x212B, 0x212C, 0x212D, 0x212E, 0x212F,
    0x2130, 0x2131, 0x2132, 0x2133, 0x2134, 0x2135, 0x2136, 0x2137, 0x2138, 0x2139, 0x213A, 0x213B,
    0x213C, 0x213D, 0x213E, 0x213F, 0x2140, 0x2141, 0x2142, 0x2143, 0x2144, 0x2145, 0x2146, 0x2147,
    0x2148, 0x2149, 0x214A, 0x214B, 0x214C, 0x214D, 0x2132, 0x214F, 0x2150, 0x2151, 0x2152, 0x2153,
    0x2154, 0x2155, 0x2156, 0x2157, 0x2158, 0x2159, 0x215A, 0x215B, 0x215C, 0x215D, 0x215E, 0x215F,
    0x2160, 0x2161, 0x2162, 0x2163, 0x2164, 0x2165, 0x2166, 0x2167, 0x2168, 0x2169, 0x216A, 0x216B,
    0x216C, 0x216D, 0x216E, 0x216F, 0x2160, 0x2161, 0x2162, 0x2163, 0x2164, 0x2165, 0x2166, 0x2167,
    0x2168, 0x2169, 0x216A, 0x216B, 0x216C, 0x216D, 0x216E, 0x216F, 0x2180, 0x2181, 0x2182, 0x2183,
    0x2183, 0xFFFF, 0x034B, 0x24B6, 0x24B7, 0x24B8, 0x24B9, 0x24BA, 0x24BB, 0x24BC, 0x24BD, 0x24BE,
    0x24BF, 0x24C0, 0x24C1, 0x24C2, 0x24C3, 0x24C4, 0x24C5, 0x24C6, 0x24C7, 0x24C8, 0x24C9, 0x24CA,
    0x24CB, 0x24CC, 0x24CD, 0x24CE, 0x24CF, 0xFFFF, 0x0746, 0x2C00, 0x2C01, 0x2C02, 0x2C03, 0x2C04,
    0x2C05, 0x2C06, 0x2C07, 0x2C08, 0x2C09, 0x2C0A, 0x2C0B, 0x2C0C, 0x2C0D, 0x2C0E, 0x2C0F, 0x2C10,
    0x2C11, 0x2C12, 0x2C13, 0x2C14, 0x2C15, 0x2C16, 0x2C17, 0x2C18, 0x2C19, 0x2C1A, 0x2C1B, 0x2C1C,
    0x2C1D, 0x2C1E, 0x2C1F, 0x2C20, 0x2C21, 0x2C22, 0x2C23, 0x2C24, 0x2C25, 0x2C26, 0x2C27, 0x2C28,
    0x2C29, 0x2C2A, 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, 0x2CDE, 0x2CE0, 0x2CE0, 0x2CE2, 0x2CE2, 0x2CE4, 0x2CE5, 0x2CE6, 0x2CE7, 0x2CE8,
    0x2CE9, 0x2CEA, 0x2CEB, 0x2CEC, 0x2CED, 0x2CEE, 0x2CEF, 0x2CF0, 0x2CF1, 0x2CF2, 0x2CF3, 0x2CF4,
    0x2CF5, 0x2CF6, 0x2CF7, 0x2CF8, 0x2CF9, 0x2CFA, 0x2CFB, 0x2CFC, 0x2CFD, 0x2CFE, 0x2CFF, 0x10A0,
    0x10A1, 0x10A2, 0x10A3, 0x10A4, 0x10A5, 0x10A6, 0x10A7, 0x10A8, 0x10A9, 0x10AA, 0x10AB, 0x10AC,
    0x10AD, 0x10AE, 0x10AF, 0x10B0, 0x10B1, 0x10B2, 0x10B3, 0x10B4, 0x10B5, 0x10B6, 0x10B7, 0x10B8,
    0x10B9, 0x10BA, 0x10BB, 0x10BC, 0x10BD, 0x10BE, 0x10BF, 0x10C0, 0x10C1, 0x10C2, 0x10C3, 0x10C4,
    0x10C5, 0xFFFF, 0xD21B, 0xFF21, 0xFF22, 0xFF23, 0xFF24, 0xFF25, 0xFF26, 0xFF27, 0xFF28, 0xFF29,
    0xFF2A, 0xFF2B, 0xFF2C, 0xFF2D, 0xFF2E, 0xFF2F, 0xFF30, 0xFF31, 0xFF32, 0xFF33, 0xFF34, 0xFF35,
    0xFF36, 0xFF37, 0xFF38, 0xFF39, 0xFF3A, 0xFF5B, 0xFF5C, 0xFF5D, 0xFF5E, 0xFF5F, 0xFF60, 0xFF61,
    0xFF62, 0xFF63, 0xFF64, 0xFF65, 0xFF66, 0xFF67, 0xFF68, 0xFF69, 0xFF6A, 0xFF6B, 0xFF6C, 0xFF6D,
    0xFF6E, 0xFF6F, 0xFF70, 0xFF71, 0xFF72, 0xFF73, 0xFF74, 0xFF75, 0xFF76, 0xFF77, 0xFF78, 0xFF79,
    0xFF7A, 0xFF7B, 0xFF7C, 0xFF7D, 0xFF7E, 0xFF7F, 0x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table recommended by the format produces.
///
/// A table computed from its own bytes checks out however badly it was transcribed, the way
/// a self-signed certificate proves nothing — so the recommended table is recognized by a
/// value written down rather than by arithmetic over itself. A volume whose case-insensitive
/// lookups agree with every other implementation's carries a table with this checksum.
pub const RECOMMENDED_UPCASE_CHECKSUM: u32 = 0xE619_D30D;

/// The length, in bytes, of the up-case table recommended by the format.
///
/// Derived from the table rather than stated beside it, so the two cannot disagree. It does
/// not vary with the volume's geometry, so how many clusters the table occupies is a property
/// of the cluster size alone — which is what moves the root directory's cluster number
/// between two volumes of different shapes.
pub const RECOMMENDED_UPCASE_BYTES: u64 = (RECOMMENDED_UPCASE_TABLE.len() * 2) as u64;

/// The marker unit: the unit after it is a count of characters that map to themselves.
///
/// It is also a mapping in its own right where no count follows, which is how the recommended
/// table ends — `U+FFFF` maps to itself, and the table stops.
pub const UPCASE_IDENTITY_RUN: u16 = 0xFFFF;

/// Write `table`'s units into the start of `buf` as the little-endian bytes a volume stores.
///
/// # Errors
///
/// [`ParseError::TooShort`] when `buf` is shorter than the table's bytes.
pub fn write_upcase_table(table: &[u16], buf: &mut [u8]) -> Result<(), ParseError> {
    let need = table.len() * 2;
    if buf.len() < need {
        return Err(ParseError::TooShort {
            structure: "exFAT up-case table",
            need,
            got: buf.len(),
        });
    }
    for (at, unit) in table.iter().enumerate() {
        put_u16(buf, at * 2, *unit);
    }
    Ok(())
}

/// The case folding a volume's up-case table defines, decoded from the compressed form the
/// heap stores it in and ready to fold a name through.
///
/// Every comparison exFAT makes between two names goes through the table *the volume carries*,
/// and a volume is free to carry one that is not the recommended mapping. So this is built
/// from units rather than assumed: a writer builds it from [`RECOMMENDED_UPCASE_TABLE`],
/// because that is the table it also lays down, and a reader builds it from what it found in
/// the heap. A reader folding through its own copy instead would resolve names no driver on
/// that volume resolves, and miss names every driver on it finds.
///
/// # It folds units, not characters
///
/// The table maps each 16-bit code unit independently, so a character outside the Basic
/// Multilingual Plane is a surrogate pair and each half is folded on its own. Every
/// implementation does this, because the table is indexed by unit; the recommended mapping
/// leaves surrogates alone, so such a character folds to itself.
///
/// ```
/// use ferrosys::exfat::ondisk::UpcaseTable;
///
/// let table = UpcaseTable::recommended();
/// let fold = |s: &str| table.fold(&s.encode_utf16().collect::<Vec<_>>());
/// assert_eq!(fold("readme"), fold("README"));
/// assert_eq!(fold("Ünïcode"), fold("ÜNÏCODE"));
///
/// // Folding is upward, and it is the volume's own answer rather than the host's locale.
/// assert_eq!(String::from_utf16(&fold("ß")).unwrap(), "ß");
/// ```
#[derive(Clone, PartialEq, Eq, Debug)]
pub struct UpcaseTable {
    /// Only the units that fold to something other than themselves. Most of the plane does
    /// not, so this is a few hundred entries rather than sixty-five thousand.
    mapped: std::collections::HashMap<u16, u16>,
}

impl UpcaseTable {
    /// The folding the format recommends, which is what this crate's writer lays down.
    #[must_use]
    pub fn recommended() -> Self {
        Self::new(&RECOMMENDED_UPCASE_TABLE)
    }

    /// The folding `units` describes, decoding the run compression as it goes.
    ///
    /// A unit past what the table covers folds to itself, which is what a table shorter than
    /// the plane leaves unstated. Nothing here rejects a table: whether one is the mapping it
    /// claims to be is [`UpcaseTableEntry::table_checksum`](super::UpcaseTableEntry) to
    /// answer, and a table that failed that check is not one to fold through at all.
    #[must_use]
    pub fn new(units: &[u16]) -> Self {
        let mut mapped = std::collections::HashMap::new();
        let mut character = 0u32;
        let mut at = 0usize;
        while at < units.len() && character <= u32::from(u16::MAX) {
            match units[at] {
                // A marker and the count behind it: that many characters fold to themselves,
                // which is the whole reason the table is a fifth of the plane's size.
                UPCASE_IDENTITY_RUN if at + 1 < units.len() => {
                    character += u32::from(units[at + 1]);
                    at += 2;
                }
                unit => {
                    if u32::from(unit) != character {
                        // The cast is bounded by the loop's own condition.
                        mapped.insert(character as u16, unit);
                    }
                    character += 1;
                    at += 1;
                }
            }
        }
        Self { mapped }
    }

    /// What `unit` folds to.
    #[must_use]
    pub fn fold_unit(&self, unit: u16) -> u16 {
        self.mapped.get(&unit).copied().unwrap_or(unit)
    }

    /// `name` with every unit folded: the form two names are compared in, and the form the
    /// name hash is taken over.
    #[must_use]
    pub fn fold(&self, name: &[u16]) -> Vec<u16> {
        name.iter().map(|unit| self.fold_unit(*unit)).collect()
    }

    /// The first of the 128 characters whose mapping the format fixes that this table maps to
    /// something else, and what it maps it to — or `None` where all 128 fold as the format
    /// says: `a` through `z` to `A` through `Z`, and every other one to itself.
    ///
    /// A volume may fold every character past these its own way, so this is the whole of what
    /// a table's mappings can be held to. A table too short to state one of them leaves it
    /// folding to itself, which for `a` through `z` is a deviation this names too.
    #[must_use]
    pub fn mandatory_deviation(&self) -> Option<(u16, u16)> {
        (0u16..128).find_map(|character| {
            let required = if (u16::from(b'a')..=u16::from(b'z')).contains(&character) {
                character - 0x20
            } else {
                character
            };
            let maps_to = self.fold_unit(character);
            (maps_to != required).then_some((character, maps_to))
        })
    }

    /// How many units the table folds to something other than themselves.
    ///
    /// A volume whose table folds nothing is one whose lookups are case-*sensitive*, which is
    /// conformant and is not what any ordinary volume does — so this is worth being able to
    /// ask.
    #[must_use]
    pub fn folded_units(&self) -> usize {
        self.mapped.len()
    }
}

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

    #[test]
    fn the_recommended_table_is_the_one_the_format_recommends() {
        // The gate on the transcription, and the reason the checksum is a written-down
        // constant: every other property of this array would hold just as well for a table
        // with a character wrong in it.
        let mut bytes = vec![0u8; RECOMMENDED_UPCASE_BYTES as usize];
        write_upcase_table(&RECOMMENDED_UPCASE_TABLE, &mut bytes).expect("write");
        assert_eq!(upcase_checksum(&bytes), RECOMMENDED_UPCASE_CHECKSUM);
        assert_eq!(RECOMMENDED_UPCASE_BYTES, 5836);
    }

    #[test]
    fn the_table_covers_the_whole_basic_multilingual_plane() {
        // What the compression means, checked by walking it: each unit is one character's
        // mapping, and a marker's successor is a count of characters that map to themselves.
        // A table that covered fewer characters would leave the ones past its end folding to
        // whatever a reader decided, which is where two implementations stop agreeing.
        let units = &RECOMMENDED_UPCASE_TABLE;
        let mut character = 0u32;
        let mut at = 0;
        let mut runs = 0;
        while at < units.len() {
            if units[at] == UPCASE_IDENTITY_RUN && at + 1 < units.len() {
                character += u32::from(units[at + 1]);
                at += 2;
                runs += 1;
            } else {
                character += 1;
                at += 1;
            }
        }
        assert_eq!(
            character, 0x1_0000,
            "the table covers U+0000 through U+FFFF"
        );
        assert_eq!(
            runs, 4,
            "four runs, and the rest of the table stored outright"
        );
    }

    #[test]
    fn the_mappings_are_the_case_folding_every_implementation_agrees_on() {
        // A handful of characters read out of the table, spanning the scripts where a
        // transcription error would be least visible. A table that folded ASCII correctly and
        // Cyrillic wrongly would pass every test written against names this crate's own tests
        // use, and disagree with a driver about a name a user chose.
        let fold = |c: u32| -> u32 {
            let mut character = 0u32;
            let mut at = 0;
            while at < RECOMMENDED_UPCASE_TABLE.len() {
                let unit = RECOMMENDED_UPCASE_TABLE[at];
                if unit == UPCASE_IDENTITY_RUN && at + 1 < RECOMMENDED_UPCASE_TABLE.len() {
                    let run = u32::from(RECOMMENDED_UPCASE_TABLE[at + 1]);
                    if (character..character + run).contains(&c) {
                        return c;
                    }
                    character += run;
                    at += 2;
                } else {
                    if character == c {
                        return u32::from(unit);
                    }
                    character += 1;
                    at += 1;
                }
            }
            c
        };
        for (from, to) in [
            (u32::from('a'), u32::from('A')),
            (u32::from('z'), u32::from('Z')),
            (u32::from('A'), u32::from('A')),
            (0x00E9, 0x00C9), // é -> É
            (0x03B1, 0x0391), // α -> Α
            (0x0430, 0x0410), // а -> А
            // Two that fold to themselves for reasons no ASCII case has: ß has no single
            // upper-case form, and the dotless ı upper-cases to I only under a Turkish
            // locale, which a volume's table does not carry.
            (0x00DF, 0x00DF),
            (0x0131, 0x0131),
            // A character inside the largest identity run, which is stored nowhere.
            (0x4E00, 0x4E00),
        ] {
            assert_eq!(fold(from), to, "U+{from:04X}");
        }
    }

    #[test]
    fn a_buffer_too_short_for_the_table_is_refused_rather_than_filled_part_way() {
        let mut buf = vec![0u8; RECOMMENDED_UPCASE_BYTES as usize - 1];
        assert!(matches!(
            write_upcase_table(&RECOMMENDED_UPCASE_TABLE, &mut buf),
            Err(ParseError::TooShort { .. })
        ));
    }

    #[test]
    fn the_units_go_down_little_endian() {
        let mut buf = [0u8; 8];
        write_upcase_table(&[0x0061, 0xFFFF, 0x1234], &mut buf).expect("write");
        assert_eq!(&buf[..6], &[0x61, 0x00, 0xFF, 0xFF, 0x34, 0x12]);
    }

    #[test]
    fn the_decoded_table_folds_every_unit_the_way_a_walk_of_the_compressed_form_does() {
        // The decoder against the data, over the whole plane. The two disagreeing anywhere is
        // a name this crate would hash differently from every driver reading the volume, and
        // a wrong hash costs no data — it makes a file invisible, which is worse for being
        // silent.
        let table = UpcaseTable::recommended();
        let mut character = 0u32;
        let mut at = 0usize;
        let mut checked = 0u32;
        while at < RECOMMENDED_UPCASE_TABLE.len() {
            let unit = RECOMMENDED_UPCASE_TABLE[at];
            if unit == UPCASE_IDENTITY_RUN && at + 1 < RECOMMENDED_UPCASE_TABLE.len() {
                let run = u32::from(RECOMMENDED_UPCASE_TABLE[at + 1]);
                for c in character..character + run {
                    assert_eq!(table.fold_unit(c as u16), c as u16, "U+{c:04X} in a run");
                    checked += 1;
                }
                character += run;
                at += 2;
            } else {
                assert_eq!(
                    table.fold_unit(character as u16),
                    unit,
                    "U+{character:04X} stored outright"
                );
                character += 1;
                at += 1;
                checked += 1;
            }
        }
        assert_eq!(checked, 0x1_0000, "every unit of the plane was compared");
    }

    #[test]
    fn folding_is_what_makes_two_names_one_name() {
        let table = UpcaseTable::recommended();
        let units = |s: &str| s.encode_utf16().collect::<Vec<_>>();
        assert_eq!(table.fold(&units("readme")), table.fold(&units("README")));
        assert_eq!(table.fold(&units("Ünïcode")), table.fold(&units("ÜNÏCODE")));
        assert_ne!(table.fold(&units("readme")), table.fold(&units("read_me")));

        // A character outside the Basic Multilingual Plane is a surrogate pair, and the table
        // is indexed by unit — so each half is folded on its own and the recommended mapping
        // leaves both alone.
        let emoji = units("\u{1F600}");
        assert_eq!(emoji.len(), 2);
        assert_eq!(table.fold(&emoji), emoji);

        // And most of the plane folds to itself, which is what the run compression is for.
        assert!(
            table.folded_units() < 1500,
            "the recommended table folds {} units, which is more than it stores",
            table.folded_units()
        );
    }

    #[test]
    fn a_table_that_folds_nothing_is_decoded_as_one_rather_than_refused() {
        // A volume is free to carry a table that is not the recommended mapping, and the whole
        // of the plane mapping to itself is the conformant extreme: case-sensitive lookups.
        // Deciding whether a table is the mapping it claims to be is the entry's checksum, so
        // nothing here judges one.
        let identity = UpcaseTable::new(&[UPCASE_IDENTITY_RUN, 0]);
        assert_eq!(identity.folded_units(), 0);
        assert_eq!(identity.fold_unit(u16::from(b'a')), u16::from(b'a'));

        // A table shorter than the plane leaves the rest unstated, which is folding to itself.
        let ascii_only = UpcaseTable::new(&RECOMMENDED_UPCASE_TABLE[..0x80]);
        assert_eq!(ascii_only.fold_unit(u16::from(b'a')), u16::from(b'A'));
        assert_eq!(ascii_only.fold_unit(0x00E9), 0x00E9);

        // Runs summing past the plane stop at its end rather than wrapping into it — the
        // mapping behind them addresses a unit no name can hold, and a wrapped index would
        // have folded some ordinary character to whatever it says.
        let over = UpcaseTable::new(&[
            UPCASE_IDENTITY_RUN,
            u16::MAX,
            UPCASE_IDENTITY_RUN,
            u16::MAX,
            0x0041,
        ]);
        assert_eq!(over.folded_units(), 0);
    }
}