summaryrefslogtreecommitdiff
path: root/src/SMAPI.Tests/Toolkit/PathUtilitiesTests.cs
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2018-06-02 17:54:01 -0400
committerJesse Plamondon-Willard <github@jplamondonw.com>2018-06-02 17:54:01 -0400
commitb6cda8f0d32898f34b5c7dc703a85aa823c317ce (patch)
tree91d95583b6af5ce842a3d8208aacb225bdd822d6 /src/SMAPI.Tests/Toolkit/PathUtilitiesTests.cs
parent2e3c42130358734a6fcf547745324dd272176f9c (diff)
parent9945408aa4ea2f6e07c2820f6aa1c160c68423d5 (diff)
downloadSMAPI-b6cda8f0d32898f34b5c7dc703a85aa823c317ce.tar.gz
SMAPI-b6cda8f0d32898f34b5c7dc703a85aa823c317ce.tar.bz2
SMAPI-b6cda8f0d32898f34b5c7dc703a85aa823c317ce.zip
Merge branch 'create-toolkit' into develop
Diffstat (limited to 'src/SMAPI.Tests/Toolkit/PathUtilitiesTests.cs')
-rw-r--r--src/SMAPI.Tests/Toolkit/PathUtilitiesTests.cs70
1 files changed, 70 insertions, 0 deletions
diff --git a/src/SMAPI.Tests/Toolkit/PathUtilitiesTests.cs b/src/SMAPI.Tests/Toolkit/PathUtilitiesTests.cs
new file mode 100644
index 00000000..229b9a14
--- /dev/null
+++ b/src/SMAPI.Tests/Toolkit/PathUtilitiesTests.cs
@@ -0,0 +1,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);
+ }
+ }
+}