Skip to content

Commit

Permalink
Expose VerifySettings in AddScrubber (#1381)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp authored Jan 6, 2025
1 parent 31f5371 commit 50ba6b3
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project>
<PropertyGroup>
<NoWarn>CA1822;CS1591;CS0649;xUnit1026;xUnit1013;CS1573;VerifyTestsProjectDir;VerifySetParameters;PolyFillTargetsForNuget</NoWarn>
<Version>28.7.1</Version>
<Version>28.8.0</Version>
<ImplicitUsings>enable</ImplicitUsings>
<LangVersion>preview</LangVersion>
<AssemblyVersion>1.0.0</AssemblyVersion>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
new value
15 changes: 15 additions & 0 deletions src/Verify.Tests/Serialization/EnsureScrubbingParameters.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
public class EnsureScrubbingParameters
{
[ModuleInitializer]
public static void Initialize() =>
VerifierSettings.AddScrubber((builder, counter, settings) =>
{
Assert.NotNull(counter);
Assert.NotNull(settings);
builder.Replace("EnsureScrubbingParameters", "new value");
});

[Fact]
public Task Test() =>
Verify("EnsureScrubbingParameters");
}
4 changes: 2 additions & 2 deletions src/Verify/Serialization/Scrubbers/ApplyScrubbers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public static void ApplyForExtension(string extension, StringBuilder target, Ver

foreach (var scrubber in VerifierSettings.GlobalScrubbers)
{
scrubber(target, counter);
scrubber(target, counter, settings);
}

foreach (var replace in replacements)
Expand Down Expand Up @@ -157,7 +157,7 @@ public static void ApplyForPropertyValue(VerifySettings settings, Counter counte

foreach (var scrubber in VerifierSettings.GlobalScrubbers)
{
scrubber(builder, counter);
scrubber(builder, counter, settings);
}

foreach (var replace in replacements)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,24 @@

public static partial class VerifierSettings
{
internal static List<Action<StringBuilder, Counter>> GlobalScrubbers = [];
internal static List<Action<StringBuilder, Counter, VerifySettings>> GlobalScrubbers = [];

/// <summary>
/// Modify the resulting test content using custom code.
/// </summary>
public static void AddScrubber(Action<StringBuilder> scrubber, ScrubberLocation location = ScrubberLocation.First)
{
InnerVerifier.ThrowIfVerifyHasBeenRun();
AddScrubber((builder, _) => scrubber(builder), location);
}
public static void AddScrubber(Action<StringBuilder> scrubber, ScrubberLocation location = ScrubberLocation.First) =>
AddScrubber((builder, _, _) => scrubber(builder), location);

/// <summary>
/// Modify the resulting test content using custom code.
/// </summary>
public static void AddScrubber(Action<StringBuilder, Counter> scrubber, ScrubberLocation location = ScrubberLocation.First) =>
AddScrubber((builder, counter, _) => scrubber(builder, counter), location);

/// <summary>
/// Modify the resulting test content using custom code.
/// </summary>
public static void AddScrubber(Action<StringBuilder, Counter> scrubber, ScrubberLocation location = ScrubberLocation.First)
public static void AddScrubber(Action<StringBuilder, Counter, VerifySettings> scrubber, ScrubberLocation location = ScrubberLocation.First)
{
InnerVerifier.ThrowIfVerifyHasBeenRun();
switch (location)
Expand Down

0 comments on commit 50ba6b3

Please sign in to comment.