Skip to content

Commit 72bb5a1

Browse files
committed
feat: add case tests
1 parent 82edf12 commit 72bb5a1

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

tests/LinkDotNet.StringBuilder.UnitTests/ValueStringBuilderTests.cs

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,4 +519,80 @@ public void ShouldInitializeWithCapacity()
519519

520520
builder.Capacity.ShouldBe(128);
521521
}
522+
523+
[Fact]
524+
public void IndexOf_WithOrdinalComparison_ReturnsMinus1ForCaseInsensitiveMatch()
525+
{
526+
using var builder = new ValueStringBuilder("Hello World");
527+
528+
var index = builder.IndexOf("world", StringComparison.Ordinal);
529+
530+
index.ShouldBe(-1);
531+
}
532+
533+
[Theory]
534+
[InlineData(StringComparison.OrdinalIgnoreCase)]
535+
[InlineData(StringComparison.InvariantCultureIgnoreCase)]
536+
public void IndexOf_WithCaseInsensitiveComparison_FindsMatchRegardlessOfCase(StringComparison comparison)
537+
{
538+
using var builder = new ValueStringBuilder("Hello World");
539+
540+
var index = builder.IndexOf("world", comparison);
541+
542+
index.ShouldBe(6);
543+
}
544+
545+
[Fact]
546+
public void LastIndexOf_WithOrdinalComparison_ReturnsMinus1ForCaseInsensitiveMatch()
547+
{
548+
using var builder = new ValueStringBuilder("Hello World hello world");
549+
550+
var index = builder.LastIndexOf("WORLD", StringComparison.InvariantCulture);
551+
552+
index.ShouldBe(-1);
553+
}
554+
555+
[Theory]
556+
[InlineData(StringComparison.OrdinalIgnoreCase)]
557+
[InlineData(StringComparison.InvariantCultureIgnoreCase)]
558+
public void LastIndexOf_WithCaseInsensitiveComparison_FindsMatchRegardlessOfCase(StringComparison comparison)
559+
{
560+
using var builder = new ValueStringBuilder("Hello World hello world");
561+
562+
var index = builder.LastIndexOf("WORLD", comparison);
563+
564+
index.ShouldBe(18);
565+
}
566+
567+
[Fact]
568+
public void LastIndexOf_WithStartIndexAndOrdinalComparison_ReturnsMinus1ForCaseInsensitiveMatch()
569+
{
570+
using var builder = new ValueStringBuilder("Hello World hello world");
571+
572+
var index = builder.LastIndexOf("WORLD", 15, StringComparison.Ordinal);
573+
574+
index.ShouldBe(-1);
575+
}
576+
577+
[Fact]
578+
public void Contains_WithOrdinalComparison_ReturnsFalseForCaseInsensitiveMatch()
579+
{
580+
using var builder = new ValueStringBuilder("Hello World");
581+
582+
var contains = builder.Contains("WORLD", StringComparison.Ordinal);
583+
584+
contains.ShouldBe(false);
585+
}
586+
587+
[Theory]
588+
[InlineData(StringComparison.OrdinalIgnoreCase)]
589+
[InlineData(StringComparison.InvariantCultureIgnoreCase)]
590+
public void Contains_WithCaseInsensitiveComparison_FindsMatchRegardlessOfCase(StringComparison comparison)
591+
{
592+
using var builder = new ValueStringBuilder("Hello World");
593+
594+
var contains = builder.Contains("WORLD", comparison);
595+
596+
contains.ShouldBe(true);
597+
}
522598
}

0 commit comments

Comments
 (0)