LibHac/tests/LibHac.Tests/PathToolsTests.cs

46 lines
1.3 KiB
C#
Raw Normal View History

2018-12-23 22:49:28 +01:00
using System.IO;
using LibHac.IO;
using Xunit;
namespace LibHac.Tests
{
public class PathToolsTests
{
public static object[][] NormalizedPathTestItems =
{
new object[] {"", "/"},
new object[] {"/", "/"},
new object[] {"/.", "/"},
new object[] {"/a/b/c", "/a/b/c"},
new object[] {"/a/b/../c", "/a/c"},
new object[] {"/a/b/c/..", "/a/b"},
new object[] {"/a/b/c/.", "/a/b/c"},
new object[] {"/a/../../..", "/"},
new object[] {"/a/../../../a/b/c", "/a/b/c"},
new object[] {"//a/b//.//c", "/a/b/c"},
new object[] {"/a/b/c/", "/a/b/c/"},
new object[] {"/a/./b/../c/", "/a/c/"},
new object[] {"/a/../../../", "/"},
new object[] {"//a/b//.//c/", "/a/b/c/"},
new object[] {@"/tmp/../", @"/"},
};
[Theory]
[MemberData(nameof(NormalizedPathTestItems))]
public static void NormalizePath(string path, string expected)
{
string actual = PathTools.Normalize(path);
Assert.Equal(expected, actual);
}
[Fact]
public static void NormalizeThrowsOnInvalidStartChar()
{
Assert.Throws<InvalidDataException>(() => PathTools.Normalize(@"c:\a\b\c"));
}
}
}