mirror of
https://github.com/oliverbooth/X10D
synced 2024-11-09 23:25:43 +00:00
test: cover Span<char> overloads of CountSubstring
This commit is contained in:
parent
f360311d9c
commit
4c62367303
@ -9,25 +9,49 @@ public class CharSpanTests
|
|||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void CountSubstring_ShouldHonor_StringComparison()
|
public void CountSubstring_ShouldHonor_StringComparison()
|
||||||
{
|
{
|
||||||
Assert.AreEqual(0, "Hello World".AsSpan().CountSubstring('E'));
|
var readOnlySpan = "Hello World".AsSpan();
|
||||||
Assert.AreEqual(0, "Hello World".AsSpan().CountSubstring("E".AsSpan()));
|
Span<char> span = stackalloc char[readOnlySpan.Length];
|
||||||
Assert.AreEqual(1, "Hello World".AsSpan().CountSubstring("E".AsSpan(), StringComparison.OrdinalIgnoreCase));
|
readOnlySpan.CopyTo(span);
|
||||||
|
|
||||||
|
Assert.AreEqual(0, readOnlySpan.CountSubstring('E'));
|
||||||
|
Assert.AreEqual(0, readOnlySpan.CountSubstring("E".AsSpan()));
|
||||||
|
Assert.AreEqual(1, readOnlySpan.CountSubstring("E".AsSpan(), StringComparison.OrdinalIgnoreCase));
|
||||||
|
|
||||||
|
Assert.AreEqual(0, span.CountSubstring('E'));
|
||||||
|
Assert.AreEqual(0, span.CountSubstring("E".AsSpan()));
|
||||||
|
Assert.AreEqual(1, span.CountSubstring("E".AsSpan(), StringComparison.OrdinalIgnoreCase));
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void CountSubstring_ShouldReturn0_GivenNoInstanceChar()
|
public void CountSubstring_ShouldReturn0_GivenNoInstanceChar()
|
||||||
{
|
{
|
||||||
Assert.AreEqual(0, "Hello World".AsSpan().CountSubstring('z'));
|
var readOnlySpan = "Hello World".AsSpan();
|
||||||
Assert.AreEqual(0, "Hello World".AsSpan().CountSubstring("z".AsSpan()));
|
Span<char> span = stackalloc char[readOnlySpan.Length];
|
||||||
Assert.AreEqual(0, "Hello World".AsSpan().CountSubstring("z".AsSpan(), StringComparison.OrdinalIgnoreCase));
|
readOnlySpan.CopyTo(span);
|
||||||
|
|
||||||
|
Assert.AreEqual(0, readOnlySpan.CountSubstring('z'));
|
||||||
|
Assert.AreEqual(0, readOnlySpan.CountSubstring("z".AsSpan()));
|
||||||
|
Assert.AreEqual(0, readOnlySpan.CountSubstring("z".AsSpan(), StringComparison.OrdinalIgnoreCase));
|
||||||
|
|
||||||
|
Assert.AreEqual(0, span.CountSubstring('z'));
|
||||||
|
Assert.AreEqual(0, span.CountSubstring("z".AsSpan()));
|
||||||
|
Assert.AreEqual(0, span.CountSubstring("z".AsSpan(), StringComparison.OrdinalIgnoreCase));
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void CountSubstring_ShouldReturn1_GivenSingleInstanceChar()
|
public void CountSubstring_ShouldReturn1_GivenSingleInstanceChar()
|
||||||
{
|
{
|
||||||
Assert.AreEqual(1, "Hello World".AsSpan().CountSubstring('e'));
|
var readOnlySpan = "Hello World".AsSpan();
|
||||||
Assert.AreEqual(1, "Hello World".AsSpan().CountSubstring("e".AsSpan()));
|
Span<char> span = stackalloc char[readOnlySpan.Length];
|
||||||
Assert.AreEqual(1, "Hello World".AsSpan().CountSubstring("e".AsSpan(), StringComparison.OrdinalIgnoreCase));
|
readOnlySpan.CopyTo(span);
|
||||||
|
|
||||||
|
Assert.AreEqual(1, readOnlySpan.CountSubstring('e'));
|
||||||
|
Assert.AreEqual(1, readOnlySpan.CountSubstring("e".AsSpan()));
|
||||||
|
Assert.AreEqual(1, readOnlySpan.CountSubstring("e".AsSpan(), StringComparison.OrdinalIgnoreCase));
|
||||||
|
|
||||||
|
Assert.AreEqual(1, span.CountSubstring('e'));
|
||||||
|
Assert.AreEqual(1, span.CountSubstring("e".AsSpan()));
|
||||||
|
Assert.AreEqual(1, span.CountSubstring("e".AsSpan(), StringComparison.OrdinalIgnoreCase));
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
|
Loading…
Reference in New Issue
Block a user