summaryrefslogtreecommitdiff
path: root/src/SMAPI.Tests/Utilities
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2020-09-05 14:51:52 -0400
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2020-09-05 14:51:52 -0400
commitbe1df8e7050ff5872799f6bee7f8cb419d7a3f38 (patch)
tree3906e8f08b8bebb22754ca295fdda8eda428515c /src/SMAPI.Tests/Utilities
parent5d1c77884f6686a59f121639dc177b7095e8c477 (diff)
downloadSMAPI-be1df8e7050ff5872799f6bee7f8cb419d7a3f38.tar.gz
SMAPI-be1df8e7050ff5872799f6bee7f8cb419d7a3f38.tar.bz2
SMAPI-be1df8e7050ff5872799f6bee7f8cb419d7a3f38.zip
simplify path separator normalization
It no longer tries to clean up the path (e.g. "path/to///file/" => "path/to/file"), which means it can more intuitively handle cases like this: asset.AssetName.StartsWith(PathUtilities.NormalizePathSeparators("Characters/Dialogue/"))
Diffstat (limited to 'src/SMAPI.Tests/Utilities')
-rw-r--r--src/SMAPI.Tests/Utilities/PathUtilitiesTests.cs55
1 files changed, 52 insertions, 3 deletions
diff --git a/src/SMAPI.Tests/Utilities/PathUtilitiesTests.cs b/src/SMAPI.Tests/Utilities/PathUtilitiesTests.cs
index 1d6c371d..ea69a9ea 100644
--- a/src/SMAPI.Tests/Utilities/PathUtilitiesTests.cs
+++ b/src/SMAPI.Tests/Utilities/PathUtilitiesTests.cs
@@ -24,6 +24,18 @@ namespace SMAPI.Tests.Utilities
NormalizedOnUnix = @"C:/Program Files (x86)/Steam/steamapps/common/Stardew Valley"
},
+ // Windows absolute path (with trailing slash)
+ new SamplePath
+ {
+ OriginalPath = @"C:\Program Files (x86)\Steam\steamapps\common\Stardew Valley\",
+
+ Segments = new[] { "C:", "Program Files (x86)", "Steam", "steamapps", "common", "Stardew Valley" },
+ SegmentsLimit3 = new [] { "C:", "Program Files (x86)", @"Steam\steamapps\common\Stardew Valley\" },
+
+ NormalizedOnWindows = @"C:\Program Files (x86)\Steam\steamapps\common\Stardew Valley\",
+ NormalizedOnUnix = @"C:/Program Files (x86)/Steam/steamapps/common/Stardew Valley/"
+ },
+
// Windows relative path
new SamplePath
{
@@ -68,10 +80,22 @@ namespace SMAPI.Tests.Utilities
Segments = new [] { "home", ".steam", "steam", "steamapps", "common", "Stardew Valley" },
SegmentsLimit3 = new [] { "home", ".steam", "steam/steamapps/common/Stardew Valley" },
- NormalizedOnWindows = @"home\.steam\steam\steamapps\common\Stardew Valley",
+ NormalizedOnWindows = @"\home\.steam\steam\steamapps\common\Stardew Valley",
NormalizedOnUnix = @"/home/.steam/steam/steamapps/common/Stardew Valley"
},
+ // Linux absolute path (with trailing slash)
+ new SamplePath
+ {
+ OriginalPath = @"/home/.steam/steam/steamapps/common/Stardew Valley/",
+
+ Segments = new [] { "home", ".steam", "steam", "steamapps", "common", "Stardew Valley" },
+ SegmentsLimit3 = new [] { "home", ".steam", "steam/steamapps/common/Stardew Valley/" },
+
+ NormalizedOnWindows = @"\home\.steam\steam\steamapps\common\Stardew Valley\",
+ NormalizedOnUnix = @"/home/.steam/steam/steamapps/common/Stardew Valley/"
+ },
+
// Linux absolute path (with ~)
new SamplePath
{
@@ -199,15 +223,40 @@ namespace SMAPI.Tests.Utilities
ExpectedResult = @"\\adjacent\unc"
)]
[TestCase(
+ @"C:\same\path",
+ @"C:\same\path",
+ ExpectedResult = @"."
+ )]
+ [TestCase(
@"C:\parent",
@"C:\PARENT\child",
- ExpectedResult = @"child" // note: incorrect on Linux and sometimes MacOS, but not worth the complexity of detecting whether the filesystem is case-sensitive for SMAPI's purposes
+ ExpectedResult = @"child"
)]
#else
[TestCase(
@"~/.steam/steam/steamapps/common/Stardew Valley",
@"~/.steam/steam/steamapps/common/Stardew Valley/Mods/Automate",
- ExpectedResult = @"Mods\Automate"
+ ExpectedResult = @"Mods/Automate"
+ )]
+ [TestCase(
+ @"~/.steam/steam/steamapps/common/Stardew Valley/Mods/Automate",
+ @"~/.steam/steam/steamapps/common/Stardew Valley/Content",
+ ExpectedResult = @"../../Content"
+ )]
+ [TestCase(
+ @"~/.steam/steam/steamapps/common/Stardew Valley/Mods/Automate",
+ @"/mnt/another-drive",
+ ExpectedResult = @"/mnt/another-drive"
+ )]
+ [TestCase(
+ @"~/same/path",
+ @"~/same/path",
+ ExpectedResult = @"."
+ )]
+ [TestCase(
+ @"~/parent",
+ @"~/PARENT/child",
+ ExpectedResult = @"child" // note: incorrect on Linux and sometimes MacOS, but not worth the complexity of detecting whether the filesystem is case-sensitive for SMAPI's purposes
)]
#endif
public string GetRelativePath(string sourceDir, string targetPath)