chore: Add TrimNewlines() string extension method

pull/47/head
Robert Dailey 3 years ago
parent 3641b93dbb
commit a64347e96f

@ -0,0 +1,22 @@
using Common.Extensions;
using FluentAssertions;
using NUnit.Framework;
namespace Common.Tests.Extensions;
[TestFixture]
[Parallelizable(ParallelScope.All)]
public class StringExtensionsTest
{
[Test]
public void Carriage_returns_and_newlines_are_stripped_from_front_and_back()
{
"\r\ntest\n\r".TrimNewlines().Should().Be("test");
}
[Test]
public void Spaces_are_ignored_when_stripping_newlines()
{
"\n test \r".TrimNewlines().Should().Be(" test ");
}
}

@ -29,4 +29,9 @@ public static class StringExtensions
{
return string.Format(value, args);
}
public static string TrimNewlines(this string value)
{
return value.Trim('\r', '\n');
}
}

@ -1,6 +1,8 @@
namespace TestLibrary;
using Common.Extensions;
namespace TestLibrary;
public static class StringUtils
{
public static string TrimmedString(string value) => value.Trim('\r', '\n');
public static string TrimmedString(string value) => value.TrimNewlines();
}

Loading…
Cancel
Save