directly add tests over the trailing slash.

This commit is contained in:
atravita-mods 2022-11-11 06:38:35 -05:00
parent 303b3924ae
commit 4ca546a7a8
2 changed files with 21 additions and 1 deletions

View File

@ -265,6 +265,26 @@ namespace SMAPI.Tests.Core
return name.StartsWith(otherAssetName, allowPartialWord: true, allowSubfolder: allowSubfolder);
}
// the enumerator strips the trailing path seperator
// so each of these cases has to be handled on each branch.
[TestCase("Mods/SomeMod", "Mods/", false, ExpectedResult = true)]
[TestCase("Mods/SomeMod", "Mods", false, ExpectedResult = false)]
[TestCase("Mods/Jasper/Data", "Mods/Jas/", false, ExpectedResult = false)]
[TestCase("Mods/Jasper/Data", "Mods/Jas", false, ExpectedResult = false)]
[TestCase("Mods/Jas", "Mods/Jas/", false, ExpectedResult = false)]
[TestCase("Mods/Jas", "Mods/Jas", false, ExpectedResult = true)]
public bool StartsWith_PrefixHasSeperator(string mainAssetName, string otherAssetName, bool allowSubfolder)
{
// arrange
mainAssetName = PathUtilities.NormalizeAssetName(mainAssetName);
// act
AssetName name = AssetName.Parse(mainAssetName, _ => null);
// assert value
return name.StartsWith(otherAssetName, allowPartialWord: true, allowSubfolder: allowSubfolder);
}
/****
** GetHashCode

View File

@ -163,7 +163,7 @@ namespace StardewModdingAPI.Framework.Content
return false;
// match if subfolder paths are fine (e.g. prefix 'Data/Events' with target 'Data/Events/Beach')
return allowSubfolder;
return allowSubfolder || (pathSeparators.Contains(trimmedPrefix[^1]) && curParts.Remainder.Length == 0);
}
// previous segments matched exactly and both reached the end