mirror of
https://github.com/oliverbooth/X10D
synced 2024-11-22 19:18:46 +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]
|
||||
public void CountSubstring_ShouldHonor_StringComparison()
|
||||
{
|
||||
Assert.AreEqual(0, "Hello World".AsSpan().CountSubstring('E'));
|
||||
Assert.AreEqual(0, "Hello World".AsSpan().CountSubstring("E".AsSpan()));
|
||||
Assert.AreEqual(1, "Hello World".AsSpan().CountSubstring("E".AsSpan(), StringComparison.OrdinalIgnoreCase));
|
||||
var readOnlySpan = "Hello World".AsSpan();
|
||||
Span<char> span = stackalloc char[readOnlySpan.Length];
|
||||
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]
|
||||
public void CountSubstring_ShouldReturn0_GivenNoInstanceChar()
|
||||
{
|
||||
Assert.AreEqual(0, "Hello World".AsSpan().CountSubstring('z'));
|
||||
Assert.AreEqual(0, "Hello World".AsSpan().CountSubstring("z".AsSpan()));
|
||||
Assert.AreEqual(0, "Hello World".AsSpan().CountSubstring("z".AsSpan(), StringComparison.OrdinalIgnoreCase));
|
||||
var readOnlySpan = "Hello World".AsSpan();
|
||||
Span<char> span = stackalloc char[readOnlySpan.Length];
|
||||
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]
|
||||
public void CountSubstring_ShouldReturn1_GivenSingleInstanceChar()
|
||||
{
|
||||
Assert.AreEqual(1, "Hello World".AsSpan().CountSubstring('e'));
|
||||
Assert.AreEqual(1, "Hello World".AsSpan().CountSubstring("e".AsSpan()));
|
||||
Assert.AreEqual(1, "Hello World".AsSpan().CountSubstring("e".AsSpan(), StringComparison.OrdinalIgnoreCase));
|
||||
var readOnlySpan = "Hello World".AsSpan();
|
||||
Span<char> span = stackalloc char[readOnlySpan.Length];
|
||||
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]
|
||||
|
Loading…
Reference in New Issue
Block a user