1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
using NUnit.Framework;
using StardewModdingAPI.Toolkit.Utilities;
namespace StardewModdingAPI.Tests.Toolkit
{
/// <summary>Unit tests for <see cref="PathUtilities"/>.</summary>
[TestFixture]
public class PathUtilitiesTests
{
/*********
** Unit tests
*********/
[Test(Description = "Assert that GetSegments returns the expected values.")]
[TestCase("", ExpectedResult = "")]
[TestCase("/", ExpectedResult = "")]
[TestCase("///", ExpectedResult = "")]
[TestCase("/usr/bin", ExpectedResult = "usr|bin")]
[TestCase("/usr//bin//", ExpectedResult = "usr|bin")]
[TestCase("/usr//bin//.././boop.exe", ExpectedResult = "usr|bin|..|.|boop.exe")]
[TestCase(@"C:", ExpectedResult = "C:")]
[TestCase(@"C:/boop", ExpectedResult = "C:|boop")]
[TestCase(@"C:\boop\/usr//bin//.././boop.exe", ExpectedResult = "C:|boop|usr|bin|..|.|boop.exe")]
public string GetSegments(string path)
{
return string.Join("|", PathUtilities.GetSegments(path));
}
[Test(Description = "Assert that NormalisePathSeparators returns the expected values.")]
#if SMAPI_FOR_WINDOWS
[TestCase("", ExpectedResult = "")]
[TestCase("/", ExpectedResult = "")]
[TestCase("///", ExpectedResult = "")]
[TestCase("/usr/bin", ExpectedResult = @"usr\bin")]
[TestCase("/usr//bin//", ExpectedResult = @"usr\bin")]
[TestCase("/usr//bin//.././boop.exe", ExpectedResult = @"usr\bin\..\.\boop.exe")]
[TestCase("C:", ExpectedResult = "C:")]
[TestCase("C:/boop", ExpectedResult = @"C:\boop")]
[TestCase(@"C:\usr\bin//.././boop.exe", ExpectedResult = @"C:\usr\bin\..\.\boop.exe")]
#else
[TestCase("", ExpectedResult = "")]
[TestCase("/", ExpectedResult = "/")]
[TestCase("///", ExpectedResult = "/")]
[TestCase("/usr/bin", ExpectedResult = "/usr/bin")]
[TestCase("/usr//bin//", ExpectedResult = "/usr/bin")]
[TestCase("/usr//bin//.././boop.exe", ExpectedResult = "/usr/bin/.././boop.exe")]
[TestCase("C:", ExpectedResult = "C:")]
[TestCase("C:/boop", ExpectedResult = "C:/boop")]
[TestCase(@"C:\usr\bin//.././boop.exe", ExpectedResult = "C:/usr/bin/.././boop.exe")]
#endif
public string NormalisePathSeparators(string path)
{
return PathUtilities.NormalisePathSeparators(path);
}
[Test(Description = "Assert that GetRelativePath returns the expected values.")]
#if SMAPI_FOR_WINDOWS
[TestCase(@"C:\", @"C:\", ExpectedResult = "./")]
[TestCase(@"C:\grandparent\parent\child", @"C:\grandparent\parent\sibling", ExpectedResult = @"..\sibling")]
[TestCase(@"C:\grandparent\parent\child", @"C:\cousin\file.exe", ExpectedResult = @"..\..\..\cousin\file.exe")]
#else
[TestCase("/", "/", ExpectedResult = "./")]
[TestCase("/grandparent/parent/child", "/grandparent/parent/sibling", ExpectedResult = "../sibling")]
[TestCase("/grandparent/parent/child", "/cousin/file.exe", ExpectedResult = "../../../cousin/file.exe")]
#endif
public string GetRelativePath(string sourceDir, string targetPath)
{
return PathUtilities.GetRelativePath(sourceDir, targetPath);
}
}
}
|