-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
435503f
commit e391e3b
Showing
3 changed files
with
56 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
samples/Dressca/dressca-backend/src/Dressca.SystemCommon/StringExtentions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
namespace System; | ||
|
||
/// <summary> | ||
/// <see cref="string"/> クラスの拡張メソッドを提供します。 | ||
/// </summary> | ||
public static class StringExtentions | ||
{ | ||
/// <summary> | ||
/// 対象の文字列から改行文字(\r、\n)を取り除きます。 | ||
/// </summary> | ||
/// <param name="target">対象の文字列。</param> | ||
/// <returns>元の文字列から改行文字を取り除いた文字列。</returns> | ||
/// <exception cref="ArgumentNullException"> | ||
/// <paramref name="str"/> が <see langword="null"/> です。 | ||
/// </exception> | ||
public static string RemoveNewLines(this string? target) | ||
{ | ||
ArgumentNullException.ThrowIfNull(target); | ||
return target.Replace("\n", string.Empty).Replace("\r", string.Empty); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
samples/Dressca/dressca-backend/tests/Dressca.UnitTests.SystemCommon/StringExtentionsTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
namespace Dressca.UnitTests.SystemCommon; | ||
|
||
public class StringExtentionsTest | ||
{ | ||
[Fact] | ||
public void RemoveNewLines_null_ArgumentNullExceptionが発生する() | ||
{ | ||
// Arrange | ||
string? target = null; | ||
|
||
// Act | ||
var action = () => StringExtentions.RemoveNewLines(target); | ||
|
||
// Assert | ||
Assert.Throws<ArgumentNullException>("target", action); | ||
} | ||
|
||
[Theory] | ||
[InlineData("Line1\r\nLine2", "Line1Line2")] // CRとLFを含む場合 | ||
[InlineData("Line1\rLine2", "Line1Line2")] // CRのみを含む場合 | ||
[InlineData("Line1\nLine2", "Line1Line2")] // LFのみを含む場合 | ||
[InlineData("", "")] // 空文字の場合 | ||
[InlineData("Line1Line2", "Line1Line2")] // 改行文字を含まない場合 | ||
public void RemoveNewLines_改行文字があれば取り除かれる(string input, string expected) | ||
{ | ||
// Arrange | ||
|
||
// Act | ||
var actual = input.RemoveNewLines(); | ||
|
||
// Assert | ||
Assert.Equal(expected, actual); | ||
} | ||
} |