Add unit test for duplicate firmware filenames

This commit is contained in:
YoshiRulz 2024-12-07 08:25:45 +10:00
parent 69b61b574d
commit 384b6f17a7
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
1 changed files with 27 additions and 0 deletions

View File

@ -1,3 +1,7 @@
using System.Collections.Generic;
using System.Linq;
using BizHawk.Common.CollectionExtensions;
using BizHawk.Common.StringExtensions;
using BizHawk.Emulation.Common;
@ -20,5 +24,28 @@ namespace BizHawk.Tests.Emulation.Common
foreach (var hash in FirmwareDatabase.FirmwareFilesByHash.Keys) CustomAssert(hash);
foreach (var fo in FirmwareDatabase.FirmwareOptions) CustomAssert(fo.Hash);
}
[TestMethod]
public void CheckOrganizeFilenames()
{
SortedList<string, FirmwareFile> seen = new();
List<FirmwareFile> dupes = new();
foreach (var ff in FirmwareDatabase.FirmwareFilesByHash.Values)
{
if (seen.TryGetValue(ff.RecommendedName, out var ffExisting))
{
dupes.Add(ffExisting);
dupes.Add(ff);
}
else
{
seen.Add(ff.RecommendedName, ff);
}
}
if (dupes.Count is 0) return;
Assert.Fail($"multiple {nameof(FirmwareFile)}s have the same suggested filename (breaks Organize function):\n{
string.Join("\n", dupes.Select(static ff => $"\t{ff.RecommendedName} {ff.Hash}").Order())
}");
}
}
}