mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Add cleaner cleaning tests, pt. 2
This commit is contained in:
@@ -242,7 +242,7 @@ namespace SabreTools.Filtering
|
|||||||
public void CleanDatItem(DatItem datItem)
|
public void CleanDatItem(DatItem datItem)
|
||||||
{
|
{
|
||||||
// If we're stripping unicode characters, strip machine name and description
|
// If we're stripping unicode characters, strip machine name and description
|
||||||
if (RemoveUnicode == true)
|
if (RemoveUnicode)
|
||||||
{
|
{
|
||||||
datItem.Machine.Name = RemoveUnicodeCharacters(datItem.Machine.Name);
|
datItem.Machine.Name = RemoveUnicodeCharacters(datItem.Machine.Name);
|
||||||
datItem.Machine.Description = RemoveUnicodeCharacters(datItem.Machine.Description);
|
datItem.Machine.Description = RemoveUnicodeCharacters(datItem.Machine.Description);
|
||||||
@@ -250,18 +250,18 @@ namespace SabreTools.Filtering
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If we're in cleaning mode, sanitize machine name and description
|
// If we're in cleaning mode, sanitize machine name and description
|
||||||
if (Clean == true)
|
if (Clean)
|
||||||
{
|
{
|
||||||
datItem.Machine.Name = CleanGameName(datItem.Machine.Name);
|
datItem.Machine.Name = CleanGameName(datItem.Machine.Name);
|
||||||
datItem.Machine.Description = CleanGameName(datItem.Machine.Description);
|
datItem.Machine.Description = CleanGameName(datItem.Machine.Description);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we are in single game mode, rename the machine
|
// If we are in single game mode, rename the machine
|
||||||
if (Single == true)
|
if (Single)
|
||||||
datItem.Machine.Name = "!";
|
datItem.Machine.Name = "!";
|
||||||
|
|
||||||
// If we are in NTFS trim mode, trim the item name
|
// If we are in NTFS trim mode, trim the item name
|
||||||
if (Trim == true && datItem.GetName() != null)
|
if (Trim && datItem.GetName() != null)
|
||||||
{
|
{
|
||||||
// Windows max name length is 260
|
// Windows max name length is 260
|
||||||
int usableLength = 260 - datItem.Machine.Name.Length - (Root?.Length ?? 0);
|
int usableLength = 260 - datItem.Machine.Name.Length - (Root?.Length ?? 0);
|
||||||
|
|||||||
130
SabreTools.Test/Filtering/CleanerCleaningTests.cs
Normal file
130
SabreTools.Test/Filtering/CleanerCleaningTests.cs
Normal file
@@ -0,0 +1,130 @@
|
|||||||
|
using SabreTools.DatItems;
|
||||||
|
using SabreTools.Filtering;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace SabreTools.Test.Filtering
|
||||||
|
{
|
||||||
|
public class CleanerCleaningTests
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public void CleanDatItemRemoveUnicodeTest()
|
||||||
|
{
|
||||||
|
// Setup cleaner
|
||||||
|
var cleaner = new Cleaner
|
||||||
|
{
|
||||||
|
RemoveUnicode = true,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Setup DatItem
|
||||||
|
var datItem = new Rom
|
||||||
|
{
|
||||||
|
Name = "nam诶",
|
||||||
|
Machine = new Machine
|
||||||
|
{
|
||||||
|
Name = "nam诶-2",
|
||||||
|
Description = "nam诶-3",
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Run cleaning
|
||||||
|
cleaner.CleanDatItem(datItem);
|
||||||
|
|
||||||
|
// Check the fields
|
||||||
|
Assert.Equal("nam", datItem.Name);
|
||||||
|
Assert.Equal("nam-2", datItem.Machine.Name);
|
||||||
|
Assert.Equal("nam-3", datItem.Machine.Description);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void CleanDatItemCleanTest()
|
||||||
|
{
|
||||||
|
// Setup cleaner
|
||||||
|
var cleaner = new Cleaner
|
||||||
|
{
|
||||||
|
Clean = true,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Setup DatItem
|
||||||
|
var datItem = new Rom
|
||||||
|
{
|
||||||
|
Name = "name",
|
||||||
|
Machine = new Machine
|
||||||
|
{
|
||||||
|
Name = "\"ÁБ\"",
|
||||||
|
Description = "ä|/Ж",
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Run cleaning
|
||||||
|
cleaner.CleanDatItem(datItem);
|
||||||
|
|
||||||
|
// Check the fields
|
||||||
|
Assert.Equal("name", datItem.Name);
|
||||||
|
Assert.Equal("'AB'", datItem.Machine.Name);
|
||||||
|
Assert.Equal("ae-Zh", datItem.Machine.Description);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void CleanDatItemSingleTest()
|
||||||
|
{
|
||||||
|
// Setup cleaner
|
||||||
|
var cleaner = new Cleaner
|
||||||
|
{
|
||||||
|
Single = true,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Setup DatItem
|
||||||
|
var datItem = new Rom
|
||||||
|
{
|
||||||
|
Name = "name",
|
||||||
|
Machine = new Machine
|
||||||
|
{
|
||||||
|
Name = "name-2",
|
||||||
|
Description = "name-3",
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Run cleaning
|
||||||
|
cleaner.CleanDatItem(datItem);
|
||||||
|
|
||||||
|
// Check the fields
|
||||||
|
Assert.Equal("name", datItem.Name);
|
||||||
|
Assert.Equal("!", datItem.Machine.Name);
|
||||||
|
Assert.Equal("name-3", datItem.Machine.Description);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData(null, "name")]
|
||||||
|
[InlineData("", "name")]
|
||||||
|
[InlineData("C:\\Normal\\Depth\\Path", "name")]
|
||||||
|
[InlineData("C:\\AbnormalFolderLengthPath\\ThatReallyPushesTheLimit\\OfHowLongYou\\ReallyShouldNameThings\\AndItGetsEvenWorse\\TheMoreSubfoldersThatYouTraverse\\BecauseWhyWouldYouStop\\AtSomethingReasonable\\LikeReallyThisIsGettingDumb\\AndIKnowItsJustATest\\ButNotAsMuchAsMe", "nam")]
|
||||||
|
public void CleanDatItemTrimTest(string root, string expected)
|
||||||
|
{
|
||||||
|
// Setup cleaner
|
||||||
|
var cleaner = new Cleaner
|
||||||
|
{
|
||||||
|
Trim = true,
|
||||||
|
Root = root,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Setup DatItem
|
||||||
|
var datItem = new Rom
|
||||||
|
{
|
||||||
|
Name = "name",
|
||||||
|
Machine = new Machine
|
||||||
|
{
|
||||||
|
Name = "name-2",
|
||||||
|
Description = "name-3",
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Run cleaning
|
||||||
|
cleaner.CleanDatItem(datItem);
|
||||||
|
|
||||||
|
// Check the fields
|
||||||
|
Assert.Equal(expected, datItem.Name);
|
||||||
|
Assert.Equal("name-2", datItem.Machine.Name);
|
||||||
|
Assert.Equal("name-3", datItem.Machine.Description);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\SabreTools.Core\SabreTools.Core.csproj" />
|
<ProjectReference Include="..\SabreTools.Core\SabreTools.Core.csproj" />
|
||||||
|
<ProjectReference Include="..\SabreTools.DatItems\SabreTools.DatItems.csproj" />
|
||||||
<ProjectReference Include="..\SabreTools.Filtering\SabreTools.Filtering.csproj" />
|
<ProjectReference Include="..\SabreTools.Filtering\SabreTools.Filtering.csproj" />
|
||||||
<ProjectReference Include="..\SabreTools.IO\SabreTools.IO.csproj" />
|
<ProjectReference Include="..\SabreTools.IO\SabreTools.IO.csproj" />
|
||||||
<ProjectReference Include="..\SabreTools.Skippers\SabreTools.Skippers.csproj" />
|
<ProjectReference Include="..\SabreTools.Skippers\SabreTools.Skippers.csproj" />
|
||||||
|
|||||||
Reference in New Issue
Block a user