Skip to content

Commit 88bf24d

Browse files
feat: validate SplitToLines arguments
1 parent ed55ced commit 88bf24d

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

ECoreNetto.Extensions.Tests/StringExtensionsTestFixture.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ public void Verify_that_SplitToLines_returns_expected_results()
4343
Assert.That(lines, Is.EquivalentTo(new List<string> {"ab", "c", "def"}));
4444
}
4545

46+
[Test]
47+
public void Verify_that_SplitToLines_validates_arguments()
48+
{
49+
Assert.Throws<ArgumentException>(() => StringExtensions.SplitToLines(null, 1));
50+
Assert.Throws<ArgumentException>(() => "".SplitToLines(1));
51+
Assert.Throws<ArgumentException>(() => "test".SplitToLines(0));
52+
}
53+
4654
[Test]
4755
public void Verify_that_CapitalizeFirstLetter_returns_expected_result()
4856
{

ECoreNetto.Extensions/StringExtensions.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@ public static class StringExtensions
4444
/// </returns>
4545
public static IEnumerable<string> SplitToLines(this string input, int maximumLineLength)
4646
{
47+
if (string.IsNullOrWhiteSpace(input))
48+
{
49+
throw new ArgumentException("string can't be empty!");
50+
}
51+
52+
if (maximumLineLength <= 0)
53+
{
54+
throw new ArgumentException("maximumLineLength must be greater than zero");
55+
}
56+
4757
input = input.Replace("\r\n", " ").Trim();
4858

4959
var words = input.Split(' ');

0 commit comments

Comments
 (0)