Files
SabreTools/SabreTools.Test/Core/UtilitiesTests.cs

54 lines
1.9 KiB
C#
Raw Normal View History

2020-12-18 14:22:56 -08:00
using SabreTools.Core.Tools;
using Xunit;
namespace SabreTools.Test.Core
{
public class UtiltiesTests
{
[Theory]
[InlineData(null, null)]
[InlineData("null", null)]
[InlineData("0b00001", null)]
2022-12-22 09:27:31 -08:00
[InlineData("12345", 12345L)]
[InlineData("00000000012345", 12345L)]
2020-12-18 14:22:56 -08:00
[InlineData("10h", null)]
2022-12-22 09:27:31 -08:00
[InlineData("0x10", 16L)]
[InlineData(" 12345 ", 12345L)]
2024-03-05 13:32:49 -05:00
public void CleanLongTest(string? input, long? expected)
2020-12-18 14:22:56 -08:00
{
2023-08-11 14:30:31 -04:00
long? actual = NumberHelper.ConvertToInt64(input);
2020-12-18 14:22:56 -08:00
Assert.Equal(expected, actual);
}
[Theory]
[InlineData(null, 0, null)]
[InlineData(null, 4, null)]
[InlineData("123456", 0, null)]
[InlineData("123456", 4, null)]
[InlineData("da39a3ee5e6b4b0d3255bfef95601890afd80709", -1, "da39a3ee5e6b4b0d3255bfef95601890afd80709.gz")]
[InlineData("da39a3ee5e6b4b0d3255bfef95601890afd80709", 0, "da39a3ee5e6b4b0d3255bfef95601890afd80709.gz")]
[InlineData("da39a3ee5e6b4b0d3255bfef95601890afd80709", 1, "da\\da39a3ee5e6b4b0d3255bfef95601890afd80709.gz")]
2024-03-05 13:32:49 -05:00
public void GetDepotPathTest(string? hash, int depth, string? expected)
2020-12-18 14:22:56 -08:00
{
2024-03-05 13:32:49 -05:00
string? actual = Utilities.GetDepotPath(hash, depth);
2024-07-16 00:27:12 -04:00
if (System.IO.Path.DirectorySeparatorChar == '/')
expected = expected?.Replace('\\', '/');
2020-12-18 14:22:56 -08:00
Assert.Equal(expected, actual);
}
[Theory]
[InlineData(null, false)]
[InlineData("", false)]
[InlineData("no-extension", false)]
[InlineData("invalid.ext", false)]
[InlineData("INVALID.EXT", false)]
[InlineData("valid_extension.dat", true)]
[InlineData("valid_extension.DAT", true)]
2024-03-05 13:32:49 -05:00
public void HasValidDatExtensionTest(string? path, bool expected)
2020-12-18 14:22:56 -08:00
{
bool actual = Utilities.HasValidDatExtension(path);
Assert.Equal(expected, actual);
}
}
}