Skip to content

Commit

Permalink
add missing static date scrubbing (#1106)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp authored Dec 24, 2023
1 parent ec9aac5 commit 9ee23af
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a DateTime_1 b
14 changes: 14 additions & 0 deletions src/StaticSettingsTests/DateTimeScrubbingTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[UsesVerify]
public class DateTimeScrubbingTests :
BaseTest
{
public DateTimeScrubbingTests() =>
VerifierSettings.ScrubInlineDateTimes("F");

[Fact]
public Task Test()
{
var dateTime = DateTime.Now;
return Verify($"a {dateTime:F} b");
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Directory: CustomReplace\StaticSettingsTests
Directory: {ProjectDirectory}
NotEqual:
- Received: OmitContentFromExceptionTests.String.received.txt
Verified: OmitContentFromExceptionTests.String.verified.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,34 @@ public static void ScrubEmptyLines(ScrubberLocation location = ScrubberLocation.
AddScrubber(_ => _.RemoveEmptyLines(), location);
}

/// <summary>
/// Replace inline <see cref="DateTime" />s with a placeholder.
/// </summary>
public static void ScrubInlineDateTimes(string format, Culture? culture = null, ScrubberLocation location = ScrubberLocation.First) =>
AddScrubber(
(builder, counter) => DateScrubber.ReplaceDateTimes(builder, format, counter, culture ?? Culture.CurrentCulture),
location);

/// <summary>
/// Replace inline <see cref="DateTime" />s with a placeholder.
/// </summary>
public static void ScrubInlineDateTimeOffsets(string format, Culture? culture = null, ScrubberLocation location = ScrubberLocation.First) =>
AddScrubber(
(builder, counter) => DateScrubber.ReplaceDateTimeOffsets(builder, format, counter, culture ?? Culture.CurrentCulture),
location);

#if NET5_0_OR_GREATER

/// <summary>
/// Replace inline <see cref="Date" />s with a placeholder.
/// </summary>
public static void ScrubInlineDates(string format, Culture? culture = null, ScrubberLocation location = ScrubberLocation.First) =>
AddScrubber(
(builder, counter) => DateScrubber.ReplaceDates(builder, format, counter, culture ?? Culture.CurrentCulture),
location);

#endif

/// <summary>
/// Replace inline <see cref="Guid" />s with a placeholder.
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions src/Verify/Serialization/VerifierSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ internal static void Reset()
UseUniqueDirectorySplitMode = false;
omitContentFromException = false;
encoding = new UTF8Encoding(true, true);
GlobalScrubbers.Clear();
}

public static void UseStrictJson()
Expand Down

0 comments on commit 9ee23af

Please sign in to comment.