mirror of
https://github.com/oliverbooth/X10D
synced 2024-11-22 23:58:48 +00:00
test: 100% coverage on Enumerable and String methods in Text namespace
This commit is contained in:
parent
369882c1e8
commit
e852726b66
@ -19,6 +19,18 @@ public class EnumerableTests
|
|||||||
CollectionAssert.AreEqual(expectedResult, actualResult);
|
CollectionAssert.AreEqual(expectedResult, actualResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void Grep_ShouldYieldNoResults_GivenEmptySource()
|
||||||
|
{
|
||||||
|
string[] source = Array.Empty<string>();
|
||||||
|
string[] expectedResult = Array.Empty<string>();
|
||||||
|
|
||||||
|
const string pattern = /*lang=regex*/@"[0-9]+";
|
||||||
|
string[] actualResult = source.Grep(pattern).ToArray();
|
||||||
|
|
||||||
|
CollectionAssert.AreEqual(expectedResult, actualResult);
|
||||||
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void Grep_ShouldMatchUpperCase_GivenIgnoreCaseTrue()
|
public void Grep_ShouldMatchUpperCase_GivenIgnoreCaseTrue()
|
||||||
{
|
{
|
||||||
|
@ -195,6 +195,22 @@ public class StringTests
|
|||||||
Assert.AreEqual(substring, substring.EnsureEndsWith(substring));
|
Assert.AreEqual(substring, substring.EnsureEndsWith(substring));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void EnsureEndsWith_ShouldReturnString_GivenEmptySourceString()
|
||||||
|
{
|
||||||
|
const string substring = "World";
|
||||||
|
|
||||||
|
Assert.AreEqual(substring, string.Empty.EnsureEndsWith(substring));
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void EnsureEndsWith_ShouldReturnString_GivenEmptySubString()
|
||||||
|
{
|
||||||
|
const string substring = "World";
|
||||||
|
|
||||||
|
Assert.AreEqual(substring, substring.EnsureEndsWith(string.Empty));
|
||||||
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void EnsureStartsWith_ShouldAppendSubstring_GivenEndsWithReturnFalse()
|
public void EnsureStartsWith_ShouldAppendSubstring_GivenEndsWithReturnFalse()
|
||||||
{
|
{
|
||||||
@ -212,6 +228,22 @@ public class StringTests
|
|||||||
Assert.AreEqual(substring, substring.EnsureStartsWith(substring));
|
Assert.AreEqual(substring, substring.EnsureStartsWith(substring));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void EnsureStartsWith_ShouldReturnString_GivenEmptySourceString()
|
||||||
|
{
|
||||||
|
const string substring = "World";
|
||||||
|
|
||||||
|
Assert.AreEqual(substring, string.Empty.EnsureStartsWith(substring));
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void EnsureStartsWith_ShouldReturnString_GivenEmptySubString()
|
||||||
|
{
|
||||||
|
const string substring = "World";
|
||||||
|
|
||||||
|
Assert.AreEqual(substring, substring.EnsureStartsWith(string.Empty));
|
||||||
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void EnumParse_ShouldReturnCorrectValue_GivenString()
|
public void EnumParse_ShouldReturnCorrectValue_GivenString()
|
||||||
{
|
{
|
||||||
@ -665,6 +697,66 @@ public class StringTests
|
|||||||
Assert.ThrowsException<ArgumentNullException>(() => value!.Split(0).ToArray());
|
Assert.ThrowsException<ArgumentNullException>(() => value!.Split(0).ToArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void StartsWithAny_ShouldReturnFalse_GivenNullInput()
|
||||||
|
{
|
||||||
|
string? value = null;
|
||||||
|
Assert.IsFalse(value.StartsWithAny());
|
||||||
|
Assert.IsFalse(value.StartsWithAny(StringComparison.Ordinal));
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void StartsWithAny_ShouldReturnFalse_GivenEmptyInput()
|
||||||
|
{
|
||||||
|
Assert.IsFalse(string.Empty.StartsWithAny());
|
||||||
|
Assert.IsFalse(string.Empty.StartsWithAny(StringComparison.Ordinal));
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void StartsWithAny_ShouldReturnFalse_GivenValuesThatDontMatch()
|
||||||
|
{
|
||||||
|
const string value = "Hello World";
|
||||||
|
Assert.IsFalse(value.StartsWithAny("World", "Goodbye"));
|
||||||
|
Assert.IsFalse(value.StartsWithAny(StringComparison.Ordinal, "World", "Goodbye"));
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void StartsWithAny_ShouldReturnTrue_GivenValuesThatMatch()
|
||||||
|
{
|
||||||
|
const string value = "Hello World";
|
||||||
|
Assert.IsTrue(value.StartsWithAny("World", "Hello"));
|
||||||
|
Assert.IsTrue(value.StartsWithAny(StringComparison.Ordinal, "World", "Hello"));
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void StartsWithAny_ShouldReturnTrue_GivenValuesThatMatch_WithIgnoreCaseComparison()
|
||||||
|
{
|
||||||
|
const string value = "Hello World";
|
||||||
|
Assert.IsTrue(value.StartsWithAny(StringComparison.OrdinalIgnoreCase, "WORLD", "HELLO"));
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void StartsWithAny_ShouldReturnFalse_GivenEmptyValues()
|
||||||
|
{
|
||||||
|
const string input = "Hello World";
|
||||||
|
Assert.IsFalse(input.StartsWithAny());
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void StartsWithAny_ShouldThrowArgumentNullException_GivenNullValues()
|
||||||
|
{
|
||||||
|
Assert.ThrowsException<ArgumentNullException>(() => string.Empty.StartsWithAny(null!));
|
||||||
|
Assert.ThrowsException<ArgumentNullException>(() => string.Empty.StartsWithAny(StringComparison.Ordinal, null!));
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void StartsWithAny_ShouldThrowArgumentNullException_GivenANullValue()
|
||||||
|
{
|
||||||
|
var values = new[] {"Hello", null!, "World"};
|
||||||
|
Assert.ThrowsException<ArgumentNullException>(() => "Foobar".StartsWithAny(values));
|
||||||
|
Assert.ThrowsException<ArgumentNullException>(() => "Foobar".StartsWithAny(StringComparison.Ordinal, values));
|
||||||
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void WithEmptyAlternative_ShouldBeCorrect()
|
public void WithEmptyAlternative_ShouldBeCorrect()
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user