Minor respath improvements (#5876)

* Minor respath improvements

* Add helpers

* tweak helper

* Throw on more than 1 char

* comments

* No emoji separators
This commit is contained in:
Leon Friedrich
2025-05-12 13:04:40 +10:00
committed by GitHub
parent 2b1d755d9f
commit 4d47cfa1a6
2 changed files with 43 additions and 16 deletions

View File

@@ -36,13 +36,17 @@ public sealed class ResPathTest
[TestCase("x/y/z", ExpectedResult = "z")]
[TestCase("/bar", ExpectedResult = "bar")]
[TestCase("bar/", ExpectedResult = "bar")] // Trailing / gets trimmed.
[TestCase("/foo/bar/", ExpectedResult = "bar")]
// These next two tests are the current behaviour. I don't know if this is how it should behave, these tests just
// ensure that it doesn't change unintentionally
[TestCase("/foo/bar//", ExpectedResult = "")]
[TestCase("/foo/bar///", ExpectedResult = "")]
public string FilenameTest(string input)
{
var resPathFilename = new ResPath(input).Filename;
return resPathFilename;
}
[Test]
[TestCase(@"", ExpectedResult = @".")]
[TestCase(@".", ExpectedResult = @".")]
@@ -66,6 +70,11 @@ public sealed class ResPathTest
[TestCase(@"/foo/bar/x", ExpectedResult = @"/foo/bar")]
[TestCase(@"/foo/bar.txt", ExpectedResult = @"/foo")]
[TestCase(@"/bar.txt", ExpectedResult = @"/")]
// These next three tests are the current behaviour. I don't know if this is how it should behave, these tests just
// ensure that it doesn't change unintentionally
[TestCase(@"/foo/bar//", ExpectedResult = "/foo/bar")]
[TestCase(@"/foo/bar///", ExpectedResult = "/foo/bar/")]
[TestCase(@"/foo/bar////", ExpectedResult = "/foo/bar//")]
public string DirectoryTest(string path)
{
var resPathDirectory = new ResPath(path).Directory.ToString();
@@ -73,8 +82,7 @@ public sealed class ResPathTest
}
[Test]
[TestCase(@"a/b/c", "👏", ExpectedResult = "a👏b👏c")]
[TestCase(@"/a/b/c", "👏", ExpectedResult = "👏a👏b👏c")]
[TestCase(@"a/b/c", "\\", ExpectedResult = @"a\b\c")]
[TestCase(@"/a/b/c", "\\", ExpectedResult = @"\a\b\c")]
public string ChangeSeparatorTest(string input, string separator)
{