Skip to content

Commit

Permalink
Support multiple scrubbers on same extension (#5488)
Browse files Browse the repository at this point in the history
  • Loading branch information
JanKrivanek authored Oct 25, 2022
1 parent e477590 commit c215fb1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,18 @@ public ScrubbersDefinition AddScrubber(Action<StringBuilder> scrubber, string? e
// This is to get the same behavior as Verify.NET
else
{
ScrubersByExtension[extension.Trim()] = extension.Trim().StartsWith('.')
? throw new TemplateVerificationException(LocalizableStrings.VerificationEngine_Error_ScrubberExtension, TemplateVerificationErrorCode.InvalidOption)
: scrubber;
extension = extension.Trim();
if (extension.StartsWith('.'))
{
throw new TemplateVerificationException(LocalizableStrings.VerificationEngine_Error_ScrubberExtension, TemplateVerificationErrorCode.InvalidOption);
}

if (ScrubersByExtension.TryGetValue(extension, out var origScrubber))
{
scrubber = origScrubber + scrubber;
}

ScrubersByExtension[extension] = scrubber;
}

return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ public async void CreateVerificationTaskWithCustomScrubbersAndVerifier()
.AddScrubber(sb => sb.Replace("bb", "xx"), "cs")
.AddScrubber(sb => sb.Replace("cc", "yy"), "dll")
.AddScrubber(sb => sb.Replace("123", "yy"), "dll")
.AddScrubber(sb => sb.Replace("aa", "zz")))
.AddScrubber(sb => sb.Replace("aa", "zz"))
// supports multiple scrubbers per extension
.AddScrubber(sb => sb.Replace("cc", "**"), "cs"))
.WithCustomDirectoryVerifier(
async (content, contentFetcher) =>
{
Expand All @@ -66,7 +68,7 @@ public async void CreateVerificationTaskWithCustomScrubbersAndVerifier()
await VerificationEngine.CreateVerificationTask(verifyLocation, "callerLocation", null, options, fileSystem);

resultContents.Keys.Count.Should().Be(2);
resultContents["Program.cs"].Should().BeEquivalentTo("zz xx cc");
resultContents["Program.cs"].Should().BeEquivalentTo("zz xx **");
resultContents["Subfolder\\Class.cs"].Should().BeEquivalentTo("123 456 789 zz");
}

Expand Down

0 comments on commit c215fb1

Please sign in to comment.