2021-07-13 10:14:25 +02:00
|
|
|
|
// ReSharper disable InconsistentNaming
|
|
|
|
|
|
|
|
|
|
using LibHac.Common;
|
|
|
|
|
using LibHac.Fs;
|
2021-07-12 08:09:39 +02:00
|
|
|
|
using Xunit;
|
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
namespace LibHac.Tests.Fs;
|
|
|
|
|
|
|
|
|
|
public class PathUtilityTests
|
2021-07-12 08:09:39 +02:00
|
|
|
|
{
|
2021-11-14 20:08:57 +01:00
|
|
|
|
public static TheoryData<string, string, bool> TestData_IsSubPath => new()
|
2021-07-12 08:09:39 +02:00
|
|
|
|
{
|
2021-11-14 20:08:57 +01:00
|
|
|
|
{ @"//a/b", @"/a", false },
|
|
|
|
|
{ @"/a", @"//a/b", false },
|
|
|
|
|
{ @"//a/b", @"\\a", false },
|
|
|
|
|
{ @"//a/b", @"//a", true },
|
|
|
|
|
{ @"/", @"/a", true },
|
|
|
|
|
{ @"/a", @"/", true },
|
|
|
|
|
{ @"/", @"/", false },
|
|
|
|
|
{ @"", @"", false },
|
|
|
|
|
{ @"/", @"", true },
|
|
|
|
|
{ @"/", @"mount:/a", false },
|
|
|
|
|
{ @"mount:/", @"mount:/", false },
|
|
|
|
|
{ @"mount:/a/b", @"mount:/a/b", false },
|
|
|
|
|
{ @"mount:/a/b", @"mount:/a/b/c", true },
|
|
|
|
|
{ @"/a/b", @"/a/b/c", true },
|
|
|
|
|
{ @"/a/b/c", @"/a/b", true },
|
|
|
|
|
{ @"/a/b", @"/a/b", false },
|
|
|
|
|
{ @"/a/b", @"/a/b\c", false }
|
|
|
|
|
};
|
2021-07-12 08:09:39 +02:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
[Theory, MemberData(nameof(TestData_IsSubPath))]
|
|
|
|
|
public static void IsSubPath(string path1, string path2, bool expectedResult)
|
|
|
|
|
{
|
|
|
|
|
bool result = PathUtility.IsSubPath(path1.ToU8Span(), path2.ToU8Span());
|
2021-07-12 08:09:39 +02:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
Assert.Equal(expectedResult, result);
|
2021-07-12 08:09:39 +02:00
|
|
|
|
}
|
|
|
|
|
}
|