From 0792ce2e782f0cd3d93c0e5e9a22f01f55780dd7 Mon Sep 17 00:00:00 2001 From: AnalogFeelings <51166756+AnalogFeelings@users.noreply.github.com> Date: Tue, 13 Feb 2024 03:37:53 +0100 Subject: [PATCH] [Tests -> Extensions] Add string extensions tests. --- .../Extensions/StringExtensionsTests.cs | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 Source/SammBot.Tests/Extensions/StringExtensionsTests.cs diff --git a/Source/SammBot.Tests/Extensions/StringExtensionsTests.cs b/Source/SammBot.Tests/Extensions/StringExtensionsTests.cs new file mode 100644 index 0000000..59e26b8 --- /dev/null +++ b/Source/SammBot.Tests/Extensions/StringExtensionsTests.cs @@ -0,0 +1,71 @@ +#region License Information (GPLv3) +// Samm-Bot - A lightweight Discord.NET bot for moderation and other purposes. +// Copyright (C) 2021-2024 Analog Feelings +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +#endregion + +using SammBot.Library.Extensions; + +namespace SammBot.Tests.Extensions; + +[TestClass] +public class StringExtensionsTests +{ + [TestMethod] + public void TruncateTest() + { + string actual = "Lorem ipsum dolor sit amet".Truncate(11); + string expected = "Lorem ipsum..."; + + Assert.IsTrue(actual == expected, $"Expected \"{expected}\", got \"{actual}\"."); + } + + [TestMethod] + public void CountryCodeToFlagTest() + { + string actualFirst = "ES".CountryCodeToFlag(); + string expectedFirst = "\U0001f1ea\U0001f1f8"; + + Assert.IsTrue(actualFirst == expectedFirst, $"Expected \"{expectedFirst}\", got \"{actualFirst}\"."); + + string actualSecond = "US".CountryCodeToFlag(); + string expectedSecond = "\U0001f1fa\U0001f1f8"; + + Assert.IsTrue(actualSecond == expectedSecond, $"Expected \"{expectedSecond}\", got \"{actualSecond}\"."); + } + + [TestMethod] + public void CapitalizeFirstTest() + { + string actual = "lorem ipsum".CapitalizeFirst(); + string expected = "Lorem ipsum"; + + Assert.IsTrue(actual == expected, $"Expected \"{expected}\", got \"{actual}\"."); + } + + [TestMethod] + public void DamerauDistanceTest() + { + int actualFirst = "lorem psum".DamerauDistance("lorem ipsum", 3); + int expectedFirst = 1; + + Assert.IsTrue(actualFirst == expectedFirst, $"Expected {expectedFirst}, got {actualFirst}."); + + int actualSecond = "loren ipun".DamerauDistance("lorem ipsum", 2); + int expectedSecond = int.MaxValue; + + Assert.IsTrue(actualSecond == expectedSecond, $"Expected {expectedSecond}, got {actualSecond}."); + } +} \ No newline at end of file