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:
parent
b424a4b8ec
commit
2cf508f253
@ -9,6 +9,30 @@
|
||||
[TestClass]
|
||||
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>
|
||||
/// Tests for <see cref="StringExtensions.Repeat" />.
|
||||
/// </summary>
|
||||
@ -18,6 +42,16 @@
|
||||
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>
|
||||
/// Tests for <see cref="StringExtensions.Split" />.
|
||||
/// </summary>
|
||||
@ -30,5 +64,18 @@
|
||||
var arr = str.Split(2).ToArray();
|
||||
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"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user