Simplify tests for GetRelativePath and MakeRelativeTo
This commit is contained in:
parent
68659055cb
commit
fb03771bb7
|
@ -59,55 +59,33 @@ namespace BizHawk.Tests.Common.PathExtensions
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
[DataRow("./share", "/usr/share", "/usr")]
|
[DataRow("./share", true, "/usr/share", "/usr")]
|
||||||
[DataRow(".", "/usr", "/usr")]
|
[DataRow(".", true, "/usr", "/usr")]
|
||||||
[DataRow("..", "/usr", "/usr/share")]
|
[DataRow("..", false, "/usr", "/usr/share")]
|
||||||
[DataRow("../bin", "/usr/bin", "/usr/share")]
|
[DataRow("../bin", false, "/usr/bin", "/usr/share")]
|
||||||
[DataRow("../../etc", "/etc", "/usr/share")]
|
[DataRow("../../etc", false, "/etc", "/usr/share")]
|
||||||
public void TestGetRelativePathUnix(string expectedRelPath, string toPath, string fromPath) // swapped here instead of in data
|
public void TestGetRelativeUnix(string expectedRelPath, bool isChild, string absolutePath, string basePath)
|
||||||
{
|
{
|
||||||
PlatformTestUtils.OnlyRunOnRealUnix();
|
PlatformTestUtils.OnlyRunOnRealUnix();
|
||||||
|
|
||||||
Assert.AreEqual(expectedRelPath, PE.GetRelativePath(fromPath: fromPath, toPath: toPath));
|
Assert.AreEqual(expectedRelPath, PE.GetRelativePath(fromPath: basePath, toPath: absolutePath)); // params swapped w.r.t. `MakeRelativeTo`
|
||||||
|
// `MakeRelativeTo` is supposed to return an absolute path (the receiver is assumed to be absolute) iff the receiver isn't a child of the given base path
|
||||||
|
Assert.AreEqual(isChild ? expectedRelPath : absolutePath, absolutePath.MakeRelativeTo(basePath));
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
[DataRow("./share", "/usr/share", "/usr")]
|
[DataRow(@".\SysWOW64", true, @"C:\Windows\SysWOW64", @"C:\Windows")]
|
||||||
[DataRow(".", "/usr", "/usr")]
|
[DataRow(@".", true, @"C:\Windows", @"C:\Windows")]
|
||||||
[DataRow("/usr", "/usr", "/usr/share")] // not `..`
|
[DataRow(@"..", false, @"C:\Windows", @"C:\Windows\SysWOW64")]
|
||||||
[DataRow("/usr/bin", "/usr/bin", "/usr/share")] // not `../bin`
|
[DataRow(@"..\System32", false, @"C:\Windows\System32", @"C:\Windows\SysWOW64")]
|
||||||
[DataRow("/etc", "/etc", "/usr/share")] // not `../../etc`
|
[DataRow(@"..\..\Program Files", false, @"C:\Program Files", @"C:\Windows\SysWOW64")]
|
||||||
public void TestMakeRelativeToUnix(string expectedRelPath, string absolutePath, string basePath)
|
public void TestGetRelativeWindows(string expectedRelPath, bool isChild, string absolutePath, string basePath)
|
||||||
{
|
|
||||||
PlatformTestUtils.OnlyRunOnRealUnix();
|
|
||||||
|
|
||||||
Assert.AreEqual(expectedRelPath, absolutePath.MakeRelativeTo(basePath));
|
|
||||||
}
|
|
||||||
|
|
||||||
[TestMethod]
|
|
||||||
[DataRow(@".\SysWOW64", @"C:\Windows\SysWOW64", @"C:\Windows")]
|
|
||||||
[DataRow(@".", @"C:\Windows", @"C:\Windows")]
|
|
||||||
[DataRow(@"..", @"C:\Windows", @"C:\Windows\SysWOW64")]
|
|
||||||
[DataRow(@"..\System32", @"C:\Windows\System32", @"C:\Windows\SysWOW64")]
|
|
||||||
[DataRow(@"..\..\Program Files", @"C:\Program Files", @"C:\Windows\SysWOW64")]
|
|
||||||
public void TestGetRelativePathWindows(string expectedRelPath, string toPath, string fromPath) // swapped here instead of in data
|
|
||||||
{
|
{
|
||||||
PlatformTestUtils.OnlyRunOnWindows();
|
PlatformTestUtils.OnlyRunOnWindows();
|
||||||
|
|
||||||
Assert.AreEqual(expectedRelPath, PE.GetRelativePath(fromPath: fromPath, toPath: toPath));
|
Assert.AreEqual(expectedRelPath, PE.GetRelativePath(fromPath: basePath, toPath: absolutePath)); // params swapped w.r.t. `MakeRelativeTo`
|
||||||
}
|
// `MakeRelativeTo` is supposed to return an absolute path (the receiver is assumed to be absolute) iff the receiver isn't a child of the given base path
|
||||||
|
Assert.AreEqual(isChild ? expectedRelPath : absolutePath, absolutePath.MakeRelativeTo(basePath));
|
||||||
[TestMethod]
|
|
||||||
[DataRow(@".\SysWOW64", @"C:\Windows\SysWOW64", @"C:\Windows")]
|
|
||||||
[DataRow(@".", @"C:\Windows", @"C:\Windows")]
|
|
||||||
[DataRow(@"C:\Windows", @"C:\Windows", @"C:\Windows\SysWOW64")] // not `..`
|
|
||||||
[DataRow(@"C:\Windows\System32", @"C:\Windows\System32", @"C:\Windows\SysWOW64")] // not `..\System32`
|
|
||||||
[DataRow(@"C:\Program Files", @"C:\Program Files", @"C:\Windows\SysWOW64")] // not `..\..\Program Files`
|
|
||||||
public void TestMakeRelativeToWindows(string expectedRelPath, string absolutePath, string basePath)
|
|
||||||
{
|
|
||||||
PlatformTestUtils.OnlyRunOnWindows();
|
|
||||||
|
|
||||||
Assert.AreEqual(expectedRelPath, absolutePath.MakeRelativeTo(basePath));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue