Skip to content

armgit / Filee

Public Imported from GitHub
0

Free, open-source file converter. Convert 263 formats offline by drag & drop — images, PDF, Word, Excel, PowerPoint, HWP/HWPX, video, audio, e-books and archives. No upload, no Office needed.

feat(formats): add format fields and grades table

SeoJCalivef3732a2041f9
diff --git a/docs/ADDING-A-CONVERTER.md b/docs/ADDING-A-CONVERTER.md
index e523110d..630a42ff 100644
--- a/docs/ADDING-A-CONVERTER.md
+++ b/docs/ADDING-A-CONVERTER.md
@@ -12,6 +12,12 @@ If the format is new, add one line to `FormatRegistry.Known` (`src/Filee.Core/Fo
new("epub", "EPUB", FormatCategory.Document, ["epub"]),
```
+Then add its id to one grade list in `FormatFields` (`src/Filee.Core/Formats/FormatFields.cs`): everyday, general,
+specialist or legacy, by how widely files in it are made today. It belongs to its category's field; if it belongs to
+other fields too, or only to a field that can be turned off, give it an `Overlaps` row. A new output format graded
+specialist or legacy must belong only to fields that can be turned off and are off by default. `FormatFieldsTests` fails
+until the format has a grade.
+
## 2. Write the converter
Create `src/Filee.Engines/<Area>/<Name>Converter.cs`:
diff --git a/src/Filee.Core/Formats/FormatFields.cs b/src/Filee.Core/Formats/FormatFields.cs
new file mode 100644
index 00000000..ad5c54f9
--- /dev/null
+++ b/src/Filee.Core/Formats/FormatFields.cs
@@ -0,0 +1,189 @@
+// Who makes each format (its fields) and how widely it is made today (its grade), issue #844.
+// The field switches of #806 ask IsShown; FormatCategory stays as it is, so engines, routes and the CLI don't see this.
+// Adding a format: put its id in one grade list below and, if people outside its category's field commonly make it or it
+// belongs to a field that can be turned off, give it an Overlaps row. A new output format graded specialist or legacy
+// belongs only to fields that can be turned off and are off by default.
+
+namespace Filee.Core.Formats;
+
+/// <summary>
+/// How widely files in a format are made today, whether or not Filee can write it. Check legacy first, then everyday,
+/// then specialist; anything else is general.
+/// </summary>
+public enum FormatGrade
+{
+ /// <summary>Made by mainstream consumer setups by default (stock OS and phone apps, major web services, a
+ /// country's de facto office suite).</summary>
+ Everyday,
+
+ /// <summary>Made across fields, but not a mainstream default.</summary>
+ General,
+
+ /// <summary>The common ways of making it are in one or more specialist fields.</summary>
+ Specialist,
+
+ /// <summary>Replaced by a successor, and hardly anyone makes new files in it.</summary>
+ Legacy,
+}
+
+/// <summary>A group of people who make formats. Fields that can be turned off hide the formats only they make.</summary>
+/// <param name="Id">Lower-case id: a category name (<c>image</c>, <c>model3d</c>) or one of the extra fields.</param>
+/// <param name="CanTurnOff">Whether a user can turn the field off.</param>
+/// <param name="OnByDefault">Whether the field is on in a new install.</param>
+public sealed record FormatField(string Id, bool CanTurnOff, bool OnByDefault);
+
+/// <summary>Fields and grades of every format, and whether a format is shown with some fields turned off.</summary>
+public static class FormatFields
+{
+ private static readonly HashSet<string> TurnOffCategories = new(["cad", "model3d", "geo", "font"], StringComparer.OrdinalIgnoreCase);
+
+ /// <summary>Every field: one per category (named after it), then the fields that aren't categories.</summary>
+ public static IReadOnlyList<FormatField> All { get; } =
+ [
+ .. Enum.GetValues<FormatCategory>().Select(category => category.ToString().ToLowerInvariant())
+ .Select(id => TurnOffCategories.Contains(id) ? new FormatField(id, true, false) : new FormatField(id, false, true)),
+ new("game", true, false),
+ new("design", true, false),
+ new("science", true, false),
+ // On for now as suggested in #844 (off would hide TAR, GZ, YAML, ... in new installs); the maintainer decides.
+ new("developer", true, true),
+ new("writing", true, false),
+ new("video-pro", true, false),
+ new("audio-pro", true, false),
+ new("legacy", true, false),
+ ];
+
+ private static readonly Dictionary<string, FormatField> FieldsById = All.ToDictionary(f => f.Id, StringComparer.OrdinalIgnoreCase);
+
+ private static readonly Dictionary<string, FormatGrade> Grades = BuildGrades(
+ [
+ (FormatGrade.Everyday,
+ [
+ "png", "jpg", "webp", "gif", "heic", "pdf", "docx", "hwpx", "hwp", "xlsx", "csv", "pptx", "txt", "mp4",
+ "mov", "mp3", "m4a", "wav", "zip"
+ ]),
+ (FormatGrade.General,
+ [
+ "tiff", "bmp", "ico", "avif", "jxl", "tga", "apng", "jxr", "livp", "svg", "svgz", "emf", "vsd", "odg",
+ "docm", "dotx", "dotm", "doc", "odt", "ott", "rtf", "wps", "ofd", "abw", "pages", "pub", "eml", "msg",
+ "xlsm", "xltx", "xls", "ods", "ots", "tsv", "et", "numbers", "pptm", "potx", "potm", "ppsx", "ppt",
+ "odp", "otp", "key", "dps", "md", "html", "mhtml", "opml", "json", "xml", "vcf", "ics", "epub", "kepub",
+ "azw3", "fb2", "cbz", "cbr", "cb7", "cbt", "cbc", "m4v", "mkv", "webm", "avi", "wmv", "mpg", "ts",
+ "m2ts", "ogv", "m4b", "aac", "flac", "ogg", "opus", "wma", "aiff", "weba", "mka", "qta", "7z", "rar",
+ "dmg", "iso", "img", "alz", "egg", "split", "dxf", "srt", "vtt", "smi", "lrc"
+ ]),
+ (FormatGrade.Specialist,
+ [
+ "jp2", "psd", "psb", "ppm", "icns", "qoi", "dds", "cur", "xpm", "xbm", "pam", "pfm", "miff", "dcm",
+ "exr", "hdr", "fits", "xcf", "raw", "eps", "ps", "ai", "cdr", "cgm", "plt", "dst", "fodg", "fodt",
+ "fods", "fodp", "rst", "tex", "org", "adoc", "typ", "mediawiki", "dbk", "ipynb", "textile", "man",
+ "jsonl", "yaml", "toml", "har", "htmlz", "txtz", "chm", "dv", "mxf", "cavs", "usm", "m4s", "dav", "bik",
+ "h265", "h264", "ac3", "caf", "mp2", "dss", "wv", "tta", "w64", "eac3", "ape", "tak", "dsf", "dff",
+ "dts", "tar", "tgz", "tbz2", "txz", "tar7z", "tlz", "gz", "bz2", "xz", "lz", "lzma", "jar", "cab",
+ "cpio", "deb", "rpm", "dwg", "ttf", "otf", "woff", "woff2", "ass", "ssa", "ttml", "scc", "glb", "gltf",
+ "stl", "obj", "3mf", "ply", "fbx", "geojson", "kml", "kmz", "gpx", "shp", "fit"
+ ]),
+ (FormatGrade.Legacy,
+ [
+ "mng", "pcx", "wbmp", "sgi", "ras", "pcd", "wmf", "dot", "wpd", "lwp", "sdw", "cwk", "mcw", "602", "psw",
+ "xlt", "sdc", "sda", "mobi", "azw", "azw4", "prc", "lit", "lrf", "pdb", "pml", "rb", "snb", "tcr", "oeb",
+ "flv", "3gp", "3g2", "vob", "mod", "rm", "swf", "wtv", "amr", "au", "voc", "mpc", "spx", "tz", "z",
+ "lha", "arj", "eot", "fon", "sub"
+ ]),
+ ]);
+
+ // Formats whose fields differ from their category's. A row replaces the category's field, it doesn't add to it.
+ private static readonly Dictionary<string, FormatField[]> Overlaps = BuildOverlaps(
+ [
+ // Layout, print, photo post-production, signs and embroidery.
+ (["psd", "psb", "exr", "hdr", "xcf", "raw", "eps", "ps", "ai", "cdr", "plt", "dst"], ["design"]),
+ // Game textures and cutscenes.
+ (["dds", "usm", "bik"], ["game"]),
+ // Medical imaging and astronomy.
+ (["dcm", "fits"], ["science"]),
+ // Software work: raw image formats of graphics tools, app icons and cursors, config and data files, flat XML
+ // ODF for version control, man pages, streaming segments, packages and compressed archives.
+ ([
+ "ppm", "icns", "qoi", "cur", "xpm", "xbm", "pam", "pfm", "miff", "fodg", "fodt", "fods", "fodp", "man",
+ "jsonl", "yaml", "toml", "har", "m4s", "tar", "tgz", "tbz2", "txz", "tar7z", "tlz", "gz", "bz2", "xz",
+ "lz", "lzma", "jar", "cab", "cpio", "deb", "rpm"
+ ], ["developer"]),
+ // Markup sources, papers and outlines, maintenance-doc drawings (CGM), Calibre's ebook formats.
+ (["cgm", "rst", "tex", "org", "adoc", "typ", "mediawiki", "dbk", "textile", "htmlz", "txtz"], ["writing"]),
+ // Broadcast and editing masters, broadcast audio and captions, fansub and delivery subtitles, CCTV and
+ // raw streams.
+ ([
+ "dv", "mxf", "cavs", "dav", "h265", "h264", "ac3", "mp2", "eac3", "dts", "ass", "ssa", "ttml", "scc"
+ ], ["video-pro"]),
+ // Lossless archiving and recorders.
+ (["dss", "wv", "tta", "w64", "ape", "tak", "dsf", "dff"], ["audio-pro"]),
+ // 3D printing exports from CAD designs (STL, 3MF) and CAD models handed to renderers (OBJ).
+ (["stl", "obj", "3mf"], ["model3d", "cad"]),
+ // JPEG 2000: digital cinema, archives and medical imaging.
+ (["jp2"], ["design", "science"]),
+ // Jupyter notebooks: development and data science.
+ (["ipynb"], ["developer", "science"]),
+ // Core Audio: app sound assets, and Apple Loops made by musicians.
+ (["caf"], ["developer", "audio-pro"]),
+ // Compiled help files for programs.
+ (["chm"], ["writing", "developer"]),
+ // Replaced by a successor and hardly made any more.
+ ([
+ "mng", "pcx", "wbmp", "sgi", "ras", "wmf", "dot", "wpd", "lwp", "sdw", "cwk", "mcw", "602", "psw", "xlt",
+ "sdc", "sda", "mobi", "azw", "azw4", "prc", "lit", "lrf", "pdb", "pml", "rb", "snb", "tcr", "oeb", "flv",
+ "3gp", "3g2", "vob", "mod", "rm", "swf", "wtv", "amr", "au", "voc", "spx", "tz", "z", "lha", "arj",
+ "sub"
+ ], ["legacy"]),
+ // Kodak Photo CD.
+ (["pcd"], ["legacy", "design"]),
+ // Musepack.
+ (["mpc"], ["legacy", "audio-pro"]),
+ // EOT gave way to WOFF, FON to TrueType.
+ (["eot", "fon"], ["legacy", "font"]),
+ // Alpha-channel image sequences in video and motion graphics, as well as game textures.
+ (["tga"], ["image", "game"]),
+ // Vector tools make it for laser cutting, plotters and CNC, not only CAD.
+ (["dxf"], ["cad", "vector"]),
+ // The video and audio donuts make it (subtitle extraction, AI captions).
+ (["srt"], ["subtitle", "video", "audio"]),
+ ]);
+
+ /// <summary>The fields a format belongs to: its Overlaps row, or else its category's field.</summary>
+ public static IReadOnlyList<FormatField> Of(FileFormat format) =>
+ Overlaps.TryGetValue(format.Id, out var fields) ? fields : [FieldsById[format.Category.ToString()]];
+
+ /// <summary>The grade of a format. The <see cref="FormatRegistry.Folder"/> target is not a format and has none.</summary>
+ public static FormatGrade GradeOf(FileFormat format) =>
+ Grades.TryGetValue(format.Id, out var grade) ? grade : throw new KeyNotFoundException($"Format '{format.Id}' has no grade.");
+
+ /// <summary>
+ /// Whether a format is shown when the given fields are turned off: hidden only when every field it belongs to can be
+ /// turned off and is off. Ids that aren't formats (<c>*</c> for "same as source") and the folder target are always
+ /// shown; turned-off ids of fields that can't be turned off, or don't exist, are ignored. Ids ignore case.
+ /// </summary>
+ public static bool IsShown(string formatId, IReadOnlySet<string> turnedOff)
+ {
+ // The folder target belongs to the archive field, which can't be turned off today; this keeps "Extract" if it can.
+ if (FormatRegistry.FindById(formatId) is not { } format || format.Id == FormatRegistry.Folder)
+ return true;
+ return Of(format).Any(field => !field.CanTurnOff || !turnedOff.Contains(field.Id, StringComparer.OrdinalIgnoreCase));
+ }
+
+ private static Dictionary<string, FormatGrade> BuildGrades((FormatGrade Grade, string[] Ids)[] lists)
+ {
+ var grades = new Dictionary<string, FormatGrade>(StringComparer.OrdinalIgnoreCase);
+ foreach (var (grade, ids) in lists)
+ foreach (var id in ids)
+ grades.Add(FormatRegistry.Get(id).Id, grade);
+ return grades;
+ }
+
+ private static Dictionary<string, FormatField[]> BuildOverlaps((string[] Ids, string[] Fields)[] rows)
+ {
+ var overlaps = new Dictionary<string, FormatField[]>(StringComparer.OrdinalIgnoreCase);
+ foreach (var (ids, fields) in rows)
+ foreach (var id in ids)
+ overlaps.Add(FormatRegistry.Get(id).Id, [.. fields.Select(f => FieldsById[f])]);
+ return overlaps;
+ }
+}
diff --git a/src/Filee.Core/Formats/FormatRegistry.cs b/src/Filee.Core/Formats/FormatRegistry.cs
index e3ca5105..41bb022d 100644
--- a/src/Filee.Core/Formats/FormatRegistry.cs
+++ b/src/Filee.Core/Formats/FormatRegistry.cs
@@ -1,5 +1,6 @@
// Central list of supported formats and extension lookup.
-// To add a new format: add one line to Known and give at least one converter an edge for it.
+// To add a new format: add one line to Known and give at least one converter an edge for it. Then give it a grade, and
+// any fields beyond its category's, in FormatFields.
namespace Filee.Core.Formats;
diff --git a/tests/Filee.Core.Tests/FormatFieldsTests.cs b/tests/Filee.Core.Tests/FormatFieldsTests.cs
new file mode 100644
index 00000000..fd61ce6e
--- /dev/null
+++ b/tests/Filee.Core.Tests/FormatFieldsTests.cs
@@ -0,0 +1,267 @@
+// Fields and grades of every format (#844): the table is complete, matches the classification published in #844, and
+// IsShown hides a format only when every field it belongs to can be turned off and is off.
+//
+// The id lists below are pinned on purpose (#844): adding a format or changing a grade or field must update them, so the
+// change shows up in review. They are written out here, not computed from FormatFields.
+
+using Filee.Core.Formats;
+
+namespace Filee.Core.Tests;
+
+public class FormatFieldsTests
+{
+ private static readonly FileFormat[] Formats = [.. FormatRegistry.Known.Where(f => f.Id != FormatRegistry.Folder)];
+
+ private static readonly string[] TurnOffFields =
+ ["cad", "model3d", "geo", "font", "game", "design", "science", "developer", "writing", "video-pro", "audio-pro", "legacy"];
+
+ private static HashSet<string> Off(params string[] fields) => new(fields);
+
+ private static string[] Hidden(IReadOnlySet<string> turnedOff) =>
+ [.. Formats.Where(f => !FormatFields.IsShown(f.Id, turnedOff)).Select(f => f.Id).Order(StringComparer.Ordinal)];
+
+ private static string[] Sorted(string[] ids) => [.. ids.Order(StringComparer.Ordinal)];
+
+ // Every specialist and legacy format.
+ private static readonly string[] HiddenWithEverythingOff =
+ [
+ "3g2", "3gp", "3mf", "602", "ac3", "adoc", "ai", "amr", "ape", "arj", "ass", "au", "azw", "azw4", "bik",
+ "bz2", "cab", "caf", "cavs", "cdr", "cgm", "chm", "cpio", "cur", "cwk", "dav", "dbk", "dcm", "dds", "deb",
+ "dff", "dot", "dsf", "dss", "dst", "dts", "dv", "dwg", "eac3", "eot", "eps", "exr", "fbx", "fit", "fits",
+ "flv", "fodg", "fodp", "fods", "fodt", "fon", "geojson", "glb", "gltf", "gpx", "gz", "h264", "h265", "har",
+ "hdr", "htmlz", "icns", "ipynb", "jar", "jp2", "jsonl", "kml", "kmz", "lha", "lit", "lrf", "lwp", "lz",
+ "lzma", "m4s", "man", "mcw", "mediawiki", "miff", "mng", "mobi", "mod", "mp2", "mpc", "mxf", "obj", "oeb",
+ "org", "otf", "pam", "pcd", "pcx", "pdb", "pfm", "plt", "ply", "pml", "ppm", "prc", "ps", "psb", "psd",
+ "psw", "qoi", "ras", "raw", "rb", "rm", "rpm", "rst", "scc", "sda", "sdc", "sdw", "sgi", "shp", "snb", "spx",
+ "ssa", "stl", "sub", "swf", "tak", "tar", "tar7z", "tbz2", "tcr", "tex", "textile", "tgz", "tlz", "toml",
+ "tta", "ttf", "ttml", "txtz", "txz", "typ", "tz", "usm", "vob", "voc", "w64", "wbmp", "wmf", "woff", "woff2",
+ "wpd", "wtv", "wv", "xbm", "xcf", "xlt", "xpm", "xz", "yaml", "z"
+ ];
+
+ public static TheoryData<string, string[]> HiddenWithOneFieldOff => new()
+ {
+ { "cad", ["dwg"] },
+ { "model3d", ["fbx", "glb", "gltf", "ply"] },
+ { "geo", ["fit", "geojson", "gpx", "kml", "kmz", "shp"] },
+ { "font", ["otf", "ttf", "woff", "woff2"] },
+ { "game", ["bik", "dds", "usm"] },
+ { "design", ["ai", "cdr", "dst", "eps", "exr", "hdr", "plt", "ps", "psb", "psd", "raw", "xcf"] },
+ { "science", ["dcm", "fits"] },
+ { "developer", [
+ "bz2", "cab", "cpio", "cur", "deb", "fodg", "fodp", "fods", "fodt", "gz", "har", "icns", "jar",
+ "jsonl", "lz", "lzma", "m4s", "man", "miff", "pam", "pfm", "ppm", "qoi", "rpm", "tar", "tar7z",
+ "tbz2", "tgz", "tlz", "toml", "txz", "xbm", "xpm", "xz", "yaml"
+ ] },
+ { "writing", ["adoc", "cgm", "dbk", "htmlz", "mediawiki", "org", "rst", "tex", "textile", "txtz", "typ"] },
+ { "video-pro", [
+ "ac3", "ass", "cavs", "dav", "dts", "dv", "eac3", "h264", "h265", "mp2", "mxf", "scc", "ssa", "ttml"
+ ] },
+ { "audio-pro", ["ape", "dff", "dsf", "dss", "tak", "tta", "w64", "wv"] },
+ { "legacy", [
+ "3g2", "3gp", "602", "amr", "arj", "au", "azw", "azw4", "cwk", "dot", "flv", "lha", "lit", "lrf",
+ "lwp", "mcw", "mng", "mobi", "mod", "oeb", "pcx", "pdb", "pml", "prc", "psw", "ras", "rb", "rm",
+ "sda", "sdc", "sdw", "sgi", "snb", "spx", "sub", "swf", "tcr", "tz", "vob", "voc", "wbmp", "wmf",
+ "wpd", "wtv", "xlt", "z"
+ ] },
+ };
+
+ public static TheoryData<string, string[]> FieldMembers => new()
+ {
+ { "cad", ["3mf", "dwg", "dxf", "obj", "stl"] },
+ { "model3d", ["3mf", "fbx", "glb", "gltf", "obj", "ply", "stl"] },
+ { "geo", ["fit", "geojson", "gpx", "kml", "kmz", "shp"] },
+ { "font", ["eot", "fon", "otf", "ttf", "woff", "woff2"] },
+ { "game", ["bik", "dds", "tga", "usm"] },
+ { "design", ["ai", "cdr", "dst", "eps", "exr", "hdr", "jp2", "pcd", "plt", "ps", "psb", "psd", "raw", "xcf"] },
+ { "science", ["dcm", "fits", "ipynb", "jp2"] },
+ { "developer", [
+ "bz2", "cab", "caf", "chm", "cpio", "cur", "deb", "fodg", "fodp", "fods", "fodt", "gz", "har",
+ "icns", "ipynb", "jar", "jsonl", "lz", "lzma", "m4s", "man", "miff", "pam", "pfm", "ppm", "qoi",
+ "rpm", "tar", "tar7z", "tbz2", "tgz", "tlz", "toml", "txz", "xbm", "xpm", "xz", "yaml"
+ ] },
+ { "writing", ["adoc", "cgm", "chm", "dbk", "htmlz", "mediawiki", "org", "rst", "tex", "textile", "txtz", "typ"] },
+ { "video-pro", [
+ "ac3", "ass", "cavs", "dav", "dts", "dv", "eac3", "h264", "h265", "mp2", "mxf", "scc", "ssa", "ttml"
+ ] },
+ { "audio-pro", ["ape", "caf", "dff", "dsf", "dss", "mpc", "tak", "tta", "w64", "wv"] },
+ { "legacy", [
+ "3g2", "3gp", "602", "amr", "arj", "au", "azw", "azw4", "cwk", "dot", "eot", "flv", "fon", "lha",
+ "lit", "lrf", "lwp", "mcw", "mng", "mobi", "mod", "mpc", "oeb", "pcd", "pcx", "pdb", "pml", "prc",
+ "psw", "ras", "rb", "rm", "sda", "sdc", "sdw", "sgi", "snb", "spx", "sub", "swf", "tcr", "tz", "vob",
+ "voc", "wbmp", "wmf", "wpd", "wtv", "xlt", "z"
+ ] },
+ };
+
+ // Every format registered when the admission rule came in (#844): they aren't held to it.
+ private static readonly HashSet<string> FormatsBeforeAdmissionRule =
+ [
+ "png", "jpg", "webp", "tiff", "bmp", "gif", "ico", "avif", "heic", "jxl", "jp2", "psd", "psb", "tga", "ppm",
+ "icns", "apng", "mng", "qoi", "dds", "pcx", "cur", "xpm", "xbm", "wbmp", "pam", "pfm", "sgi", "ras", "miff",
+ "dcm", "pcd", "exr", "hdr", "fits", "jxr", "xcf", "livp", "raw", "svg", "svgz", "eps", "ps", "ai", "emf",
+ "wmf", "cdr", "cgm", "plt", "vsd", "dst", "odg", "fodg", "pdf", "docx", "docm", "dotx", "dotm", "doc", "dot",
+ "odt", "fodt", "ott", "rtf", "wps", "ofd", "wpd", "lwp", "abw", "pages", "sdw", "cwk", "mcw", "602", "psw",
+ "pub", "eml", "msg", "hwpx", "hwp", "xlsx", "xlsm", "xltx", "xls", "xlt", "ods", "ots", "fods", "csv", "tsv",
+ "et", "numbers", "sdc", "pptx", "pptm", "potx", "potm", "ppsx", "ppt", "odp", "otp", "fodp", "key", "dps",
+ "sda", "txt", "md", "html", "mhtml", "rst", "tex", "org", "adoc", "typ", "mediawiki", "dbk", "ipynb",
+ "textile", "man", "opml", "json", "jsonl", "yaml", "toml", "xml", "vcf", "har", "ics", "epub", "kepub",
+ "mobi", "azw3", "azw", "azw4", "prc", "fb2", "cbz", "cbr", "cb7", "cbt", "cbc", "htmlz", "txtz", "chm",
+ "lit", "lrf", "pdb", "pml", "rb", "snb", "tcr", "oeb", "mp4", "m4v", "mov", "mkv", "webm", "avi", "wmv",
+ "flv", "mpg", "ts", "m2ts", "3gp", "3g2", "ogv", "vob", "mod", "dv", "mxf", "rm", "swf", "wtv", "cavs",
+ "usm", "m4s", "dav", "bik", "h265", "h264", "mp3", "m4a", "m4b", "aac", "wav", "flac", "ogg", "opus", "wma",
+ "aiff", "ac3", "amr", "au", "caf", "weba", "mka", "mp2", "dss", "voc", "wv", "tta", "w64", "eac3", "ape",
+ "mpc", "tak", "dsf", "dff", "dts", "spx", "qta", "zip", "7z", "rar", "tar", "tgz", "tbz2", "txz", "tar7z",
+ "tlz", "tz", "gz", "bz2", "xz", "lz", "lzma", "z", "jar", "cab", "cpio", "deb", "rpm", "dmg", "iso", "img",
+ "lha", "arj", "alz", "egg", "split", "dwg", "dxf", "ttf", "otf", "woff", "woff2", "eot", "fon", "srt", "ass",
+ "ssa", "vtt", "smi", "lrc", "ttml", "sub", "scc", "glb", "gltf", "stl", "obj", "3mf", "ply", "fbx",
+ "geojson", "kml", "kmz", "gpx", "shp", "fit"
+ ];
+
+ [Fact]
+ public void Every_format_has_a_grade_and_at_least_one_known_field()
+ {
+ var fieldIds = FormatFields.All.Select(f => f.Id).ToHashSet();
+
+ foreach (var format in Formats)
+ {
+ FormatFields.GradeOf(format);
+ var fields = FormatFields.Of(format);
+ Assert.NotEmpty(fields);
+ Assert.All(fields, field => Assert.Contains(field.Id, fieldIds));
+ }
+ }
+
+ [Fact]
+ public void Field_ids_are_unique() =>
+ Assert.Equal(FormatFields.All.Count, FormatFields.All.Select(f => f.Id).Distinct(StringComparer.OrdinalIgnoreCase).Count());
+
+ [Fact]
+ public void Grade_counts_match_the_published_table()
+ {
+ var counts = Formats.GroupBy(FormatFields.GradeOf).ToDictionary(g => g.Key, g => g.Count());
+
+ Assert.Equal(
+ new Dictionary<FormatGrade, int>
+ {
+ [FormatGrade.Everyday] = 19,
+ [FormatGrade.General] = 94,
+ [FormatGrade.Specialist] = 107,
+ [FormatGrade.Legacy] = 50,
+ },
+ counts);
+ }
+
+ [Fact]
+ public void Turning_every_field_off_hides_exactly_the_specialist_and_legacy_formats() =>
+ Assert.Equal(Sorted(HiddenWithEverythingOff), Hidden(Off(TurnOffFields)));
+
+ [Theory]
+ [MemberData(nameof(HiddenWithOneFieldOff))]
+ public void Turning_one_field_off_hides_only_the_formats_nobody_else_makes(string field, string[] hidden) =>
+ Assert.Equal(Sorted(hidden), Hidden(Off(field)));
+
+ [Fact]
+ public void A_format_in_two_fields_hides_only_when_both_are_off()
+ {
+ Assert.True(FormatFields.IsShown("stl", Off("cad")));
+ Assert.True(FormatFields.IsShown("stl", Off("model3d")));
+ Assert.False(FormatFields.IsShown("stl", Off("cad", "model3d")));
+ }
+
+ [Theory]
+ [MemberData(nameof(FieldMembers))]
+ public void Fields_that_can_be_turned_off_hold_the_published_formats(string field, string[] members) =>
+ Assert.Equal(
+ Sorted(members),
+ Formats.Where(f => FormatFields.Of(f).Any(x => x.Id == field)).Select(f => f.Id).Order(StringComparer.Ordinal));
+
+ [Theory]
+ [InlineData("tga", new[] { "image", "game" })]
+ [InlineData("dxf", new[] { "cad", "vector" })]
+ [InlineData("srt", new[] { "subtitle", "video", "audio" })]
+ [InlineData("png", new[] { "image" })]
+ public void Formats_get_their_exact_fields(string id, string[] fields) =>
+ Assert.Equal(fields, FormatFields.Of(FormatRegistry.Get(id)).Select(f => f.Id));
+
+ [Theory]
+ [InlineData("png")]
+ [InlineData("jpg")]
+ [InlineData("webp")]
+ [InlineData("gif")]
+ [InlineData("heic")]
+ [InlineData("pdf")]
+ [InlineData("docx")]
+ [InlineData("hwpx")]
+ [InlineData("hwp")]
+ [InlineData("xlsx")]
+ [InlineData("csv")]
+ [InlineData("pptx")]
+ [InlineData("txt")]
+ [InlineData("md")]
+ [InlineData("mp4")]
+ [InlineData("mp3")]
+ [InlineData("m4a")]
+ [InlineData("srt")]
+ [InlineData("zip")]
+ [InlineData("svg")]
+ [InlineData("json")]
+ [InlineData("epub")]
+ public void Everyday_formats_stay_with_every_field_off(string id) =>
+ Assert.True(FormatFields.IsShown(id, Off(TurnOffFields)));
+
+ [Fact]
+ public void Turning_off_fields_that_cant_be_turned_off_or_dont_exist_hides_nothing() =>
+ Assert.Empty(Hidden(Off("image", "video", "archive", "no-such-field")));
+
+ [Fact]
+ public void Ids_ignore_case()
+ {
+ Assert.False(FormatFields.IsShown("DWG", Off("cad")));
+ Assert.False(FormatFields.IsShown("dwg", Off("CAD")));
+ Assert.True(FormatFields.IsShown("DXF", Off("CAD")));
+ }
+
+ [Theory]
+ [InlineData("no-such-format")]
+ [InlineData("*")]
+ // Folder is in the archive field, which can't be turned off today; this guards "Extract" if that changes.
+ [InlineData(FormatRegistry.Folder)]
+ public void Ids_that_arent_formats_are_always_shown(string id) =>
+ Assert.True(FormatFields.IsShown(id, Off([.. TurnOffFields, "archive"])));
+
+ [Fact]
+ public void Specialist_and_legacy_formats_belong_only_to_fields_that_can_be_turned_off() =>
+ Assert.All(
+ Formats.Where(f => FormatFields.GradeOf(f) is FormatGrade.Specialist or FormatGrade.Legacy),
+ f => Assert.All(FormatFields.Of(f), field => Assert.True(field.CanTurnOff, $"{f.Id} is in {field.Id}")));
+
+ [Fact]
+ public void Legacy_formats_belong_to_the_legacy_field() =>
+ Assert.All(
+ Formats.Where(f => FormatFields.GradeOf(f) == FormatGrade.Legacy),
+ f => Assert.Contains(FormatFields.Of(f), field => field.Id == "legacy"));
+
+ [Fact]
+ public void Everyday_and_general_formats_belong_to_a_field_that_cant_be_turned_off() =>
+ Assert.All(
+ Formats.Where(f => FormatFields.GradeOf(f) is FormatGrade.Everyday or FormatGrade.General),
+ f => Assert.Contains(FormatFields.Of(f), field => !field.CanTurnOff));
+
+ [Fact]
+ public void New_specialist_and_legacy_outputs_go_only_into_fields_that_are_off_by_default() =>
+ Assert.All(
+ Formats.Where(f => f.Writable && !FormatsBeforeAdmissionRule.Contains(f.Id)
+ && FormatFields.GradeOf(f) is FormatGrade.Specialist or FormatGrade.Legacy),
+ f => Assert.All(FormatFields.Of(f), field => Assert.True(field.CanTurnOff && !field.OnByDefault, $"{f.Id} is in {field.Id}")));
+
+ [Fact]
+ public void Only_the_extra_fields_and_four_categories_can_be_turned_off_and_only_developer_starts_on()
+ {
+ Assert.Equal(TurnOffFields.Order(StringComparer.Ordinal), FormatFields.All.Where(f => f.CanTurnOff).Select(f => f.Id).Order(StringComparer.Ordinal));
+ Assert.Equal(["developer"], FormatFields.All.Where(f => f.CanTurnOff && f.OnByDefault).Select(f => f.Id));
+ Assert.All(FormatFields.All.Where(f => !f.CanTurnOff), f => Assert.True(f.OnByDefault, f.Id));
+ }
+
+ [Fact]
+ public void The_folder_target_has_no_grade() =>
+ Assert.Throws<KeyNotFoundException>(() => FormatFields.GradeOf(FormatRegistry.Get(FormatRegistry.Folder)));
+}