-
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.
* アセットコードから改行文字を取り除いてからログ出力する * 改行文字を取り除くstringの拡張メソッドを定義 * テストスイートの単位を修正 * null の入力に対して null を返却するように修正 * メソッド名を NewlineCharacters に変更
- Loading branch information
1 parent
f378a30
commit d25d012
Showing
4 changed files
with
118 additions
and
4 deletions.
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
3 changes: 1 addition & 2 deletions
3
...a/dressca-backend/src/Dressca.EfInfrastructure/Migrations/20241211091203_InitialCreate.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
25 changes: 25 additions & 0 deletions
25
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,25 @@ | ||
using System.Diagnostics.CodeAnalysis; | ||
|
||
namespace System; | ||
|
||
/// <summary> | ||
/// <see cref="string"/> クラスの拡張メソッドを提供します。 | ||
/// </summary> | ||
public static class StringExtentions | ||
{ | ||
/// <summary> | ||
/// 対象の文字列から改行文字(\r、\n)を取り除きます。 | ||
/// </summary> | ||
/// <param name="target">対象の文字列。</param> | ||
/// <returns>元の文字列から改行文字を取り除いた文字列。</returns> | ||
[return: NotNullIfNotNull(nameof(target))] | ||
public static string? RemoveNewlineCharacters(this string? target) | ||
{ | ||
if (target == null) | ||
{ | ||
return null; | ||
} | ||
|
||
return target.Replace("\n", string.Empty).Replace("\r", string.Empty); | ||
} | ||
} |
88 changes: 88 additions & 0 deletions
88
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,88 @@ | ||
namespace Dressca.UnitTests.SystemCommon; | ||
|
||
public class StringExtentionsTest | ||
{ | ||
[Theory] | ||
[InlineData("\r\nLine1Line2", "Line1Line2")] // CRとLFを含む、先頭 | ||
[InlineData("Line1\rLine2", "Line1Line2")] // CRのみを含む、中間 | ||
[InlineData("Line1Line2\n", "Line1Line2")] // LFのみを含む、末尾 | ||
public void RemoveNewlineCharacters_改行文字があれば取り除かれる(string input, string expected) | ||
{ | ||
// Arrange | ||
|
||
// Act | ||
var actual = input.RemoveNewlineCharacters(); | ||
|
||
// Assert | ||
Assert.Equal(expected, actual); | ||
} | ||
|
||
[Fact] | ||
public void RemoveNewlineCharacters_改行文字なし_変化なし() | ||
{ | ||
// Arrange | ||
var target = "Line1Line2"; | ||
|
||
// Act | ||
var actual = target.RemoveNewlineCharacters(); | ||
|
||
// Assert | ||
Assert.Equal(target, actual); | ||
} | ||
|
||
[Fact] | ||
public void RemoveNewlineCharacters_null_nullを返却() | ||
{ | ||
// Arrange | ||
string? target = null; | ||
|
||
// Act | ||
var actual = target.RemoveNewlineCharacters(); | ||
|
||
// Assert | ||
Assert.Null(actual); | ||
} | ||
|
||
[Fact] | ||
public void RemoveNewlineCharacters_空文字_変化なし() | ||
{ | ||
// Arrange | ||
var target = string.Empty; | ||
|
||
// Act | ||
var actual = target.RemoveNewlineCharacters(); | ||
|
||
// Assert | ||
Assert.Equal(target, actual); | ||
} | ||
|
||
[Theory] | ||
[InlineData(" ")] | ||
[InlineData(" ")] | ||
public void RemoveNewlineCharacters_空白文字_変化なし(string target) | ||
{ | ||
// Arrange | ||
|
||
// Act | ||
var actual = target.RemoveNewlineCharacters(); | ||
|
||
// Assert | ||
Assert.Equal(target, actual); | ||
} | ||
|
||
[Theory] | ||
[InlineData("\r\n")] | ||
[InlineData("\r")] | ||
[InlineData("\n")] | ||
public void RemoveNewlineCharacters_改行コードのみ_取り除かれて空文字になる(string target) | ||
{ | ||
// Arrange | ||
var expected = string.Empty; | ||
|
||
// Act | ||
var actual = target.RemoveNewlineCharacters(); | ||
|
||
// Assert | ||
Assert.Equal(expected, actual); | ||
} | ||
} |