Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions ECoreNetto.Extensions.Tests/StringExtensionsTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ public void Verify_that_SplitToLines_returns_expected_results()
Assert.That(lines, Is.EquivalentTo(new List<string> {"ab", "c", "def"}));
}

[Test]
public void Verify_that_SplitToLines_validates_arguments()
{
Assert.Throws<ArgumentException>(() => StringExtensions.SplitToLines(null, 1));
Assert.Throws<ArgumentException>(() => "".SplitToLines(1));
Assert.Throws<ArgumentException>(() => "test".SplitToLines(0));
}

[Test]
public void Verify_that_CapitalizeFirstLetter_returns_expected_result()
{
Expand Down
10 changes: 10 additions & 0 deletions ECoreNetto.Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,18 @@
/// <returns>
/// an <see cref="IEnumerable{String}"/>
/// </returns>
public static IEnumerable<string> SplitToLines(this string input, int maximumLineLength)

Check warning on line 45 in ECoreNetto.Extensions/StringExtensions.cs

View workflow job for this annotation

GitHub Actions / Build

Split this method into two, one handling parameters check and the other handling the iterator. (https://rules.sonarsource.com/csharp/RSPEC-4456)
{
if (string.IsNullOrWhiteSpace(input))
{
throw new ArgumentException("string can't be empty!");
}

if (maximumLineLength <= 0)
{
throw new ArgumentException("maximumLineLength must be greater than zero");
}

input = input.Replace("\r\n", " ").Trim();

var words = input.Split(' ');
Expand Down
Loading