2021-09-27 12:42:46 +00:00
|
|
|
using System.Linq;
|
|
|
|
using Xunit;
|
|
|
|
|
2021-10-23 16:51:17 +00:00
|
|
|
namespace Wabbajack.Paths.Test;
|
|
|
|
|
|
|
|
public class RelativePathTests
|
2021-09-27 12:42:46 +00:00
|
|
|
{
|
2021-10-23 16:51:17 +00:00
|
|
|
[Fact]
|
|
|
|
public void CanReplaceExtensions()
|
2021-09-27 12:42:46 +00:00
|
|
|
{
|
2021-10-23 16:51:17 +00:00
|
|
|
Assert.Equal(new Extension(".dds"), ((RelativePath) @"foo\bar.dds").Extension);
|
|
|
|
Assert.Equal((RelativePath) @"foo\bar.zip",
|
|
|
|
((RelativePath) @"foo\bar.dds").ReplaceExtension(new Extension(".zip")));
|
|
|
|
Assert.NotEqual((RelativePath) @"foo\bar\z.zip",
|
|
|
|
((RelativePath) @"foo\bar.dds").ReplaceExtension(new Extension(".zip")));
|
|
|
|
Assert.Equal((RelativePath) @"foo\bar.zip",
|
|
|
|
((RelativePath) @"foo\bar").ReplaceExtension(new Extension(".zip")));
|
|
|
|
}
|
2021-09-27 12:42:46 +00:00
|
|
|
|
2021-10-23 16:51:17 +00:00
|
|
|
[Fact]
|
|
|
|
public void PathsAreValidated()
|
|
|
|
{
|
|
|
|
Assert.Throws<PathException>(() => @"c:\foo".ToRelativePath());
|
|
|
|
}
|
2021-09-27 12:42:46 +00:00
|
|
|
|
2021-10-23 16:51:17 +00:00
|
|
|
[Fact]
|
|
|
|
public void CanCreatePathsRelativeTo()
|
|
|
|
{
|
|
|
|
Assert.Equal((AbsolutePath) @"c:\foo\bar\baz.zip",
|
|
|
|
((RelativePath) @"baz.zip").RelativeTo((AbsolutePath) @"c:\foo\bar"));
|
|
|
|
}
|
2021-09-27 12:42:46 +00:00
|
|
|
|
2021-10-23 16:51:17 +00:00
|
|
|
[Fact]
|
|
|
|
public void ObjectMethods()
|
|
|
|
{
|
|
|
|
Assert.Equal(@"foo\bar", ((RelativePath) @"foo\bar").ToString());
|
2021-09-27 12:42:46 +00:00
|
|
|
|
2021-10-23 16:51:17 +00:00
|
|
|
Assert.Equal((RelativePath) @"foo\bar", (RelativePath) @"foo/bar");
|
|
|
|
Assert.NotEqual((RelativePath) @"foo\bar", (object) 42);
|
|
|
|
Assert.True((RelativePath) @"foo\bar" == (RelativePath) @"foo/bar");
|
|
|
|
Assert.True((RelativePath) @"foo\bar" != (RelativePath) @"foo/baz");
|
2021-09-27 12:42:46 +00:00
|
|
|
|
2021-10-23 16:51:17 +00:00
|
|
|
Assert.Equal(((RelativePath) @"foo\bar").GetHashCode(), ((RelativePath) @"Foo\bar").GetHashCode());
|
|
|
|
}
|
2021-09-27 12:42:46 +00:00
|
|
|
|
|
|
|
|
2021-10-23 16:51:17 +00:00
|
|
|
[Fact]
|
|
|
|
public void CanGetPathHashCodes()
|
|
|
|
{
|
|
|
|
Assert.Equal(@"foo\bar.baz".ToRelativePath().GetHashCode(), @"Foo\Bar.bAz".ToRelativePath().GetHashCode());
|
|
|
|
}
|
2021-09-27 12:42:46 +00:00
|
|
|
|
|
|
|
|
2021-10-23 16:51:17 +00:00
|
|
|
[Fact]
|
|
|
|
public void CaseInsensitiveEquality()
|
|
|
|
{
|
|
|
|
Assert.Equal(@"foo\bar.baz".ToRelativePath(), @"Foo\Bar.bAz".ToRelativePath());
|
|
|
|
Assert.NotEqual(@"foo\bar.baz".ToRelativePath(), (object) 42);
|
|
|
|
}
|
2021-09-27 12:42:46 +00:00
|
|
|
|
2021-10-23 16:51:17 +00:00
|
|
|
[Fact]
|
|
|
|
public void CanGetFilenameFromRelativePath()
|
|
|
|
{
|
|
|
|
Assert.Equal((RelativePath) "bar.dds", @"foo\bar.dds".ToRelativePath().FileName);
|
|
|
|
}
|
2021-09-27 12:42:46 +00:00
|
|
|
|
2021-10-23 16:51:17 +00:00
|
|
|
[Fact]
|
|
|
|
public void PathsAreComparable()
|
|
|
|
{
|
|
|
|
var data = new[]
|
2021-09-27 12:42:46 +00:00
|
|
|
{
|
2021-10-23 16:51:17 +00:00
|
|
|
(RelativePath) @"a",
|
|
|
|
(RelativePath) @"b\c",
|
|
|
|
(RelativePath) @"d\e\f",
|
|
|
|
(RelativePath) @"b"
|
|
|
|
};
|
|
|
|
var data2 = data.OrderBy(a => a).ToArray();
|
2021-09-27 12:42:46 +00:00
|
|
|
|
2021-10-23 16:51:17 +00:00
|
|
|
var data3 = new[]
|
|
|
|
{
|
|
|
|
(RelativePath) @"a",
|
|
|
|
(RelativePath) @"b",
|
|
|
|
(RelativePath) @"b\c",
|
|
|
|
(RelativePath) @"d\e\f"
|
|
|
|
};
|
|
|
|
Assert.Equal(data3, data2);
|
2021-09-27 12:42:46 +00:00
|
|
|
}
|
|
|
|
}
|