Skip to content

Commit 4440b77

Browse files
committed
Added more tests
1 parent 90d5417 commit 4440b77

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

tests/LinkDotNet.StringBuilder.UnitTests/ValueStringBuilder.Replace.Tests.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using System;
2+
13
namespace LinkDotNet.StringBuilder.UnitTests;
24

35
public class ValueStringBuilderReplaceTests
@@ -24,6 +26,26 @@ public void ShouldReplaceAllCharactersInGivenSpan()
2426
builder.ToString().Should().Be("CBBC");
2527
}
2628

29+
[Theory]
30+
[InlineData(-1, 1)]
31+
[InlineData(1, 1)]
32+
public void ShouldThrowExceptionWhenOutOfRange(int startIndex, int count)
33+
{
34+
var builder = new ValueStringBuilder();
35+
36+
try
37+
{
38+
builder.Replace('a', 'b', startIndex, count);
39+
}
40+
catch (ArgumentOutOfRangeException)
41+
{
42+
Assert.True(true);
43+
return;
44+
}
45+
46+
Assert.True(false);
47+
}
48+
2749
[Fact]
2850
public void ShouldReplaceAllText()
2951
{

tests/LinkDotNet.StringBuilder.UnitTests/ValueStringBuilderTests.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,42 @@ public void ShouldFindInSubstring()
159159
index.Should().Be(3);
160160
}
161161

162+
[Fact]
163+
public void ShouldThrowExceptionWhenNegativeStartIndex()
164+
{
165+
var stringBuilder = new ValueStringBuilder();
166+
167+
try
168+
{
169+
stringBuilder.IndexOf("l", -1);
170+
}
171+
catch (ArgumentOutOfRangeException)
172+
{
173+
Assert.True(true);
174+
return;
175+
}
176+
177+
Assert.True(false);
178+
}
179+
180+
[Fact]
181+
public void ShouldThrowExceptionWhenNegativeStartIndexLastIndex()
182+
{
183+
var stringBuilder = new ValueStringBuilder();
184+
185+
try
186+
{
187+
stringBuilder.LastIndexOf("l", -1);
188+
}
189+
catch (ArgumentOutOfRangeException)
190+
{
191+
Assert.True(true);
192+
return;
193+
}
194+
195+
Assert.True(false);
196+
}
197+
162198
[Fact]
163199
public void ShouldReturnMinusOneIfNotFound()
164200
{

0 commit comments

Comments
 (0)