1
0
mirror of https://github.com/oliverbooth/X10D synced 2024-11-09 23:25:43 +00:00

🚨 Add tests for latest methods

AsNullIfEmpty
AsNullIfWhiteSpace
Reverse
WithAlternative
This commit is contained in:
Oliver Booth 2020-10-20 15:08:20 +01:00
parent b424a4b8ec
commit 2cf508f253

View File

@ -9,6 +9,30 @@
[TestClass] [TestClass]
public class StringTests public class StringTests
{ {
/// <summary>
/// Tests for <see cref="StringExtensions.AsNullIfEmpty" />.
/// </summary>
[TestMethod]
public void AsNullIfEmpty()
{
Assert.AreEqual(null, string.Empty.AsNullIfEmpty());
Assert.AreEqual(null, ((string)null).AsNullIfEmpty());
Assert.AreEqual(" ", " ".AsNullIfEmpty());
Assert.AreEqual("foo", "foo".AsNullIfEmpty());
}
/// <summary>
/// Tests for <see cref="StringExtensions.AsNullIfWhiteSpace" />.
/// </summary>
[TestMethod]
public void AsNullIfWhiteSpace()
{
Assert.AreEqual(null, string.Empty.AsNullIfWhiteSpace());
Assert.AreEqual(null, ((string)null).AsNullIfWhiteSpace());
Assert.AreEqual(null, " ".AsNullIfWhiteSpace());
Assert.AreEqual("foo", "foo".AsNullIfWhiteSpace());
}
/// <summary> /// <summary>
/// Tests for <see cref="StringExtensions.Repeat" />. /// Tests for <see cref="StringExtensions.Repeat" />.
/// </summary> /// </summary>
@ -18,6 +42,16 @@
Assert.AreEqual("foofoofoofoofoo", "foo".Repeat(5)); Assert.AreEqual("foofoofoofoofoo", "foo".Repeat(5));
} }
/// <summary>
/// Tests for <see cref="StringExtensions.Reverse" />.
/// </summary>
[TestMethod]
public void Reverse()
{
Assert.AreEqual("dlroW olleH", StringExtensions.Reverse("Hello World"));
Assert.AreEqual("Foobar", StringExtensions.Reverse("rabooF"));
}
/// <summary> /// <summary>
/// Tests for <see cref="StringExtensions.Split" />. /// Tests for <see cref="StringExtensions.Split" />.
/// </summary> /// </summary>
@ -30,5 +64,18 @@
var arr = str.Split(2).ToArray(); var arr = str.Split(2).ToArray();
CollectionAssert.AreEqual(new[] { "He", "ll", "o ", "Wo", "rl", "d" }, arr); CollectionAssert.AreEqual(new[] { "He", "ll", "o ", "Wo", "rl", "d" }, arr);
} }
/// <summary>
/// Tests for <see cref="StringExtensions.WithAlternative" />.
/// </summary>
[TestMethod]
public void WithAlternative()
{
Assert.AreEqual("Hello", "Hello".WithAlternative("Discarded"));
Assert.AreEqual("Alternative", string.Empty.WithAlternative("Alternative"));
Assert.AreEqual(" ", " ".WithAlternative("Discarded"));
Assert.AreEqual("Alternative", " ".WithAlternative("Alternative", true));
Assert.AreEqual("Alternative", ((string)null).WithAlternative("Alternative"));
}
} }
} }