wabbajack/Wabbajack.Paths.Test/ExtensionTests.cs

61 lines
1.5 KiB
C#
Raw Permalink Normal View History

2021-09-27 12:42:46 +00:00
using System;
using Xunit;
2021-10-23 16:51:17 +00:00
namespace Wabbajack.Paths.Test;
public class ExtensionTests
2021-09-27 12:42:46 +00:00
{
2021-10-23 16:51:17 +00:00
public static Extension DDS = new(".DDS");
public static Extension Dds = new(".Dds");
public static Extension DDS2 = new(".DDS");
public static Extension EMPTY = new("");
[Fact]
public void ExtensionsAreEqual()
{
Assert.Equal(DDS, DDS);
Assert.Equal(DDS, DDS2);
Assert.Equal(DDS, Dds);
Assert.True(DDS == Dds);
Assert.True(DDS != EMPTY);
Assert.NotEqual(EMPTY, DDS);
Assert.NotEqual(DDS, (object) 42);
}
[Fact]
public void CanGetExtensionOfPath()
{
Assert.Equal(DDS, ((AbsolutePath) @"c:\foo\bar.dds").Extension);
}
[Fact]
public void ExtensionsHaveConversionOperators()
{
Assert.True(".DDS" == (string) DDS);
Assert.True(DDS == (Extension) ".DDs");
}
[Fact]
public void ExtensionsRequireDots()
{
Assert.Throws<PathException>(() => new Extension("foo"));
}
[Fact]
public void ExtensionsOverrideObjectMethods()
{
Assert.Equal(".DDS", DDS.ToString());
Assert.Equal(".DDS".GetHashCode(StringComparison.InvariantCultureIgnoreCase), DDS.GetHashCode());
}
[Fact]
public void CanGetExtensionFromPath()
2021-09-27 12:42:46 +00:00
{
2021-10-23 16:51:17 +00:00
Assert.Equal(DDS, Extension.FromPath("myfoo.DDS"));
Assert.Equal(DDS, Extension.FromPath("myfoo.bar.DDS"));
Assert.Equal(EMPTY, Extension.FromPath("baz"));
2021-09-27 12:42:46 +00:00
}
}