Skip to content

Commit

Permalink
[Tests -> Extensions] Add string extensions tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
AnalogFeelings committed Feb 13, 2024
1 parent 90f5825 commit 0792ce2
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions Source/SammBot.Tests/Extensions/StringExtensionsTests.cs
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.
#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}.");
}
}

0 comments on commit 0792ce2

Please sign in to comment.