mirror of
https://github.com/RPCS3/discord-bot.git
synced 2026-01-31 01:25:22 +01:00
update tests with nunit analyzers suggestions
This commit is contained in:
@@ -10,9 +10,12 @@ public class FlagTests
|
||||
public void MultipleFlagTest()
|
||||
{
|
||||
var testVal = FilterAction.IssueWarning | FilterAction.MuteModQueue;
|
||||
Assert.That(testVal.HasFlag(FilterAction.IssueWarning), Is.True);
|
||||
Assert.That(testVal.HasFlag(FilterAction.IssueWarning | FilterAction.MuteModQueue), Is.True);
|
||||
Assert.That(testVal.HasFlag(FilterAction.IssueWarning | FilterAction.MuteModQueue | FilterAction.RemoveContent), Is.False);
|
||||
Assert.That(testVal.HasFlag(FilterAction.IssueWarning | FilterAction.SendMessage), Is.False);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(testVal.HasFlag(FilterAction.IssueWarning), Is.True);
|
||||
Assert.That(testVal.HasFlag(FilterAction.IssueWarning | FilterAction.MuteModQueue), Is.True);
|
||||
Assert.That(testVal.HasFlag(FilterAction.IssueWarning | FilterAction.MuteModQueue | FilterAction.RemoveContent), Is.False);
|
||||
Assert.That(testVal.HasFlag(FilterAction.IssueWarning | FilterAction.SendMessage), Is.False);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@ public class IrdTests
|
||||
{
|
||||
var baseDir = TestContext.CurrentContext.TestDirectory;
|
||||
var testFiles = Directory.GetFiles(baseDir, "*.ird", SearchOption.AllDirectories);
|
||||
Assert.That(testFiles.Length, Is.GreaterThan(0));
|
||||
Assert.That(testFiles, Is.Not.Empty);
|
||||
|
||||
foreach (var file in testFiles)
|
||||
{
|
||||
@@ -26,7 +26,7 @@ public class IrdTests
|
||||
{
|
||||
var baseDir = TestContext.CurrentContext.TestDirectory;
|
||||
var testFiles = Directory.GetFiles(baseDir, "*.ird", SearchOption.AllDirectories);
|
||||
Assert.That(testFiles.Length, Is.GreaterThan(0));
|
||||
Assert.That(testFiles, Is.Not.Empty);
|
||||
|
||||
foreach (var file in testFiles)
|
||||
{
|
||||
@@ -35,7 +35,7 @@ public class IrdTests
|
||||
Assert.That(ird.FileCount, Is.GreaterThan(0));
|
||||
|
||||
var fileList = ird.GetFilenames();
|
||||
Assert.That(fileList.Count, Is.EqualTo(ird.FileCount));
|
||||
Assert.That(fileList, Has.Count.EqualTo(ird.FileCount));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,19 +12,19 @@ public class MemoryCacheExtensionTests
|
||||
public void GetCacheKeysTest()
|
||||
{
|
||||
var cache = new MemoryCache(new MemoryCacheOptions { ExpirationScanFrequency = TimeSpan.FromHours(1) });
|
||||
Assert.That(cache.GetCacheKeys<int>().Count, Is.EqualTo(0));
|
||||
Assert.That(cache.GetCacheKeys<int>(), Is.Empty);
|
||||
|
||||
cache.Set(13, "val13");
|
||||
Assert.That(cache.GetCacheKeys<int>().Count, Is.EqualTo(1));
|
||||
Assert.That(cache.GetCacheKeys<int>(), Has.Count.EqualTo(1));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetCacheEntriesTest()
|
||||
{
|
||||
var cache = new MemoryCache(new MemoryCacheOptions { ExpirationScanFrequency = TimeSpan.FromHours(1) });
|
||||
Assert.That(cache.GetCacheKeys<int>().Count, Is.EqualTo(0));
|
||||
Assert.That(cache.GetCacheKeys<int>(), Is.Empty);
|
||||
|
||||
cache.Set(13, "val13");
|
||||
Assert.That(cache.GetCacheKeys<int>().Count, Is.EqualTo(1));
|
||||
Assert.That(cache.GetCacheKeys<int>(), Has.Count.EqualTo(1));
|
||||
}
|
||||
}
|
||||
@@ -9,51 +9,57 @@ public class RangeTests
|
||||
{
|
||||
[Test]
|
||||
public void UniqueListRangeAccessorTest()
|
||||
{
|
||||
var testValue = new[] {0, 1, 2, 3, 4};
|
||||
{
|
||||
var testValue = new[] {0, 1, 2, 3, 4};
|
||||
var list = new UniqueList<int>(testValue);
|
||||
Assert.That(list, Is.EqualTo(testValue));
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(list, Is.EqualTo(testValue));
|
||||
|
||||
Assert.That(list[0..], Is.EqualTo(testValue[0..]));
|
||||
Assert.That(list[1..], Is.EqualTo(testValue[1..]));
|
||||
Assert.That(list[4..], Is.EqualTo(testValue[4..]));
|
||||
Assert.That(list[5..], Is.EqualTo(testValue[5..]));
|
||||
Assert.That(list[0..], Is.EqualTo(testValue[0..]));
|
||||
Assert.That(list[1..], Is.EqualTo(testValue[1..]));
|
||||
Assert.That(list[4..], Is.EqualTo(testValue[4..]));
|
||||
Assert.That(list[5..], Is.EqualTo(testValue[5..]));
|
||||
|
||||
Assert.That(list[0..1], Is.EqualTo(testValue[0..1]));
|
||||
Assert.That(list[0..4], Is.EqualTo(testValue[0..4]));
|
||||
Assert.That(list[0..5], Is.EqualTo(testValue[0..5]));
|
||||
Assert.That(list[1..4], Is.EqualTo(testValue[1..4]));
|
||||
Assert.That(list[1..5], Is.EqualTo(testValue[1..5]));
|
||||
|
||||
Assert.That(list[..0], Is.EqualTo(testValue[..0]));
|
||||
Assert.That(list[..1], Is.EqualTo(testValue[..1]));
|
||||
Assert.That(list[..4], Is.EqualTo(testValue[..4]));
|
||||
Assert.That(list[..5], Is.EqualTo(testValue[..5]));
|
||||
Assert.That(list[0..1], Is.EqualTo(testValue[0..1]));
|
||||
Assert.That(list[0..4], Is.EqualTo(testValue[0..4]));
|
||||
Assert.That(list[0..5], Is.EqualTo(testValue[0..5]));
|
||||
Assert.That(list[1..4], Is.EqualTo(testValue[1..4]));
|
||||
Assert.That(list[1..5], Is.EqualTo(testValue[1..5]));
|
||||
|
||||
Assert.That(list[^0..], Is.EqualTo(testValue[^0..]));
|
||||
Assert.That(list[^1..], Is.EqualTo(testValue[^1..]));
|
||||
Assert.That(list[^4..], Is.EqualTo(testValue[^4..]));
|
||||
Assert.That(list[^5..], Is.EqualTo(testValue[^5..]));
|
||||
Assert.That(list[..0], Is.EqualTo(testValue[..0]));
|
||||
Assert.That(list[..1], Is.EqualTo(testValue[..1]));
|
||||
Assert.That(list[..4], Is.EqualTo(testValue[..4]));
|
||||
Assert.That(list[..5], Is.EqualTo(testValue[..5]));
|
||||
|
||||
Assert.That(list[^1..^0], Is.EqualTo(testValue[^1..^0]));
|
||||
Assert.That(list[^4..^0], Is.EqualTo(testValue[^4..^0]));
|
||||
Assert.That(list[^5..^0], Is.EqualTo(testValue[^5..^0]));
|
||||
Assert.That(list[^4..^1], Is.EqualTo(testValue[^4..^1]));
|
||||
Assert.That(list[^5..^1], Is.EqualTo(testValue[^5..^1]));
|
||||
Assert.That(list[^0..], Is.EqualTo(testValue[^0..]));
|
||||
Assert.That(list[^1..], Is.EqualTo(testValue[^1..]));
|
||||
Assert.That(list[^4..], Is.EqualTo(testValue[^4..]));
|
||||
Assert.That(list[^5..], Is.EqualTo(testValue[^5..]));
|
||||
|
||||
Assert.That(list[..^0], Is.EqualTo(testValue[..^0]));
|
||||
Assert.That(list[..^1], Is.EqualTo(testValue[..^1]));
|
||||
Assert.That(list[..^4], Is.EqualTo(testValue[..^4]));
|
||||
Assert.That(list[..^5], Is.EqualTo(testValue[..^5]));
|
||||
}
|
||||
Assert.That(list[^1..^0], Is.EqualTo(testValue[^1..^0]));
|
||||
Assert.That(list[^4..^0], Is.EqualTo(testValue[^4..^0]));
|
||||
Assert.That(list[^5..^0], Is.EqualTo(testValue[^5..^0]));
|
||||
Assert.That(list[^4..^1], Is.EqualTo(testValue[^4..^1]));
|
||||
Assert.That(list[^5..^1], Is.EqualTo(testValue[^5..^1]));
|
||||
|
||||
[Test]
|
||||
Assert.That(list[..^0], Is.EqualTo(testValue[..^0]));
|
||||
Assert.That(list[..^1], Is.EqualTo(testValue[..^1]));
|
||||
Assert.That(list[..^4], Is.EqualTo(testValue[..^4]));
|
||||
Assert.That(list[..^5], Is.EqualTo(testValue[..^5]));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SubstringTests()
|
||||
{
|
||||
var str = "abc";
|
||||
Assert.That(str[1..], Is.EqualTo(str.Substring(1)));
|
||||
Assert.That("a"[1..], Is.EqualTo("a".Substring(1)));
|
||||
Assert.That(str[0], Is.EqualTo('a'));
|
||||
Assert.That(str[^1], Is.EqualTo('c'));
|
||||
}
|
||||
{
|
||||
var str = "abc";
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(str[1..], Is.EqualTo(str.Substring(1)));
|
||||
Assert.That("a"[1..], Is.EqualTo("a".Substring(1)));
|
||||
Assert.That(str[0], Is.EqualTo('a'));
|
||||
Assert.That(str[^1], Is.EqualTo('c'));
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -16,8 +16,10 @@ public class RegexTest
|
||||
|
||||
var latin = input.ToLatin8BitEncoding();
|
||||
var match = Regex.Match(latin, @"Rap file not found: (\xE2\x80\x9C)?(?<rap_file>.*?)(\xE2\x80\x9D)?\r?$", DefaultOptions);
|
||||
Assert.That(match.Success, Is.True);
|
||||
Assert.That(match.Groups["rap_file"].Value, Is.EqualTo("/dev_hdd0/home/00000001/exdata/EP4062-NPEB02436_00-ADDCONTENT000001.rap"));
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(match.Success, Is.True);
|
||||
Assert.That(match.Groups["rap_file"].Value, Is.EqualTo("/dev_hdd0/home/00000001/exdata/EP4062-NPEB02436_00-ADDCONTENT000001.rap"));
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -23,9 +23,12 @@ public class StringUtilTests
|
||||
[Test]
|
||||
public void VisibleTrimTest()
|
||||
{
|
||||
Assert.That("abc".TrimVisible(100), Is.EqualTo("abc"));
|
||||
Assert.That("abc".TrimVisible(3), Is.EqualTo("abc"));
|
||||
Assert.That("abc".TrimVisible(2), Is.EqualTo("a…"));
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That("abc".TrimVisible(100), Is.EqualTo("abc"));
|
||||
Assert.That("abc".TrimVisible(3), Is.EqualTo("abc"));
|
||||
Assert.That("abc".TrimVisible(2), Is.EqualTo("a…"));
|
||||
});
|
||||
}
|
||||
|
||||
[TestCase("cockatrice", "сockаtrice")]
|
||||
@@ -115,10 +118,13 @@ ignorance the hard way.""
|
||||
[TestCase("camelCaseString13", "c", "cCS", "c13", "cCS13")]
|
||||
public void AcronymGenerationTest(string input, string expectedDefault, string expectedWithUpper, string expectedWithDigits, string expectedWithUpperAndDigits)
|
||||
{
|
||||
Assert.That(input.GetAcronym(), Is.EqualTo(expectedDefault));
|
||||
Assert.That(input.GetAcronym(includeAllCaps: true), Is.EqualTo(expectedWithUpper));
|
||||
Assert.That(input.GetAcronym(includeAllDigits: true), Is.EqualTo(expectedWithDigits));
|
||||
Assert.That(input.GetAcronym(includeAllCaps: true, includeAllDigits: true), Is.EqualTo(expectedWithUpperAndDigits));
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(input.GetAcronym(), Is.EqualTo(expectedDefault));
|
||||
Assert.That(input.GetAcronym(includeAllCaps: true), Is.EqualTo(expectedWithUpper));
|
||||
Assert.That(input.GetAcronym(includeAllDigits: true), Is.EqualTo(expectedWithDigits));
|
||||
Assert.That(input.GetAcronym(includeAllCaps: true, includeAllDigits: true), Is.EqualTo(expectedWithUpperAndDigits));
|
||||
});
|
||||
}
|
||||
|
||||
public static double DiceCoefficient(string input, string comparedTo)
|
||||
|
||||
@@ -13,14 +13,17 @@ public class TimeParserTests
|
||||
public void TimeZoneConverterTest(string input, string utcInput)
|
||||
{
|
||||
var utc = DateTime.Parse(utcInput).Normalize();
|
||||
Assert.That(TimeParser.TryParse(input, out var result), Is.True, $"{input} failed to parse\nSupported time zones: {string.Join(", ", TimeParser.GetSupportedTimeZoneAbbreviations())}");
|
||||
Assert.That(result, Is.EqualTo(utc));
|
||||
Assert.That(result.Kind, Is.EqualTo(DateTimeKind.Utc));
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(TimeParser.TryParse(input, out var result), Is.True, $"{input} failed to parse\nSupported time zones: {string.Join(", ", TimeParser.GetSupportedTimeZoneAbbreviations())}");
|
||||
Assert.That(result, Is.EqualTo(utc));
|
||||
Assert.That(result.Kind, Is.EqualTo(DateTimeKind.Utc));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TimeZoneInfoTest()
|
||||
{
|
||||
Assert.That(TimeParser.TimeZoneMap.Count, Is.GreaterThan(0));
|
||||
Assert.That(TimeParser.TimeZoneMap, Is.Not.Empty);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user