Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose VerifySettings in AddScrubber #1381

Merged
merged 1 commit into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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