Skip to content

Commit

Permalink
fix bad new lines in scrubber (#125)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp authored May 18, 2020
1 parent e9ead57 commit cf47b86
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 25 deletions.
4 changes: 2 additions & 2 deletions docs/named-tuples.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ static (bool Member1, string Member2, string Member3) MethodWithNamedTuple()
return (true, "A", "B");
}
```
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L287-L294' title='File snippet `methodwithnamedtuple` was extracted from'>snippet source</a> | <a href='#snippet-methodwithnamedtuple' title='Navigate to start of snippet `methodwithnamedtuple`'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L299-L306' title='File snippet `methodwithnamedtuple` was extracted from'>snippet source</a> | <a href='#snippet-methodwithnamedtuple' title='Navigate to start of snippet `methodwithnamedtuple`'>anchor</a></sup>
<!-- endsnippet -->

Can be verified:
Expand All @@ -31,7 +31,7 @@ Can be verified:
```cs
await Verify(() => MethodWithNamedTuple());
```
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L280-L284' title='File snippet `verifytuple` was extracted from'>snippet source</a> | <a href='#snippet-verifytuple' title='Navigate to start of snippet `verifytuple`'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L292-L296' title='File snippet `verifytuple` was extracted from'>snippet source</a> | <a href='#snippet-verifytuple' title='Navigate to start of snippet `verifytuple`'>anchor</a></sup>
<!-- endsnippet -->

Resulting in:
Expand Down
10 changes: 5 additions & 5 deletions docs/scrubbers.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ For example remove lines containing `text`:
```cs
verifySettings.ScrubLines(line => line.Contains("text"));
```
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L192-L196' title='File snippet `scrublines` was extracted from'>snippet source</a> | <a href='#snippet-scrublines' title='Navigate to start of snippet `scrublines`'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L204-L208' title='File snippet `scrublines` was extracted from'>snippet source</a> | <a href='#snippet-scrublines' title='Navigate to start of snippet `scrublines`'>anchor</a></sup>
<!-- endsnippet -->


Expand All @@ -45,7 +45,7 @@ For example remove lines containing `text1` or `text2`
```cs
verifySettings.ScrubLinesContaining("text1", "text2");
```
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L198-L202' title='File snippet `scrublinescontaining` was extracted from'>snippet source</a> | <a href='#snippet-scrublinescontaining' title='Navigate to start of snippet `scrublinescontaining`'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L210-L214' title='File snippet `scrublinescontaining` was extracted from'>snippet source</a> | <a href='#snippet-scrublinescontaining' title='Navigate to start of snippet `scrublinescontaining`'>anchor</a></sup>
<!-- endsnippet -->

Case insensitive by default (StringComparison.OrdinalIgnoreCase).
Expand All @@ -57,7 +57,7 @@ Case insensitive by default (StringComparison.OrdinalIgnoreCase).
```cs
verifySettings.ScrubLinesContaining(StringComparison.Ordinal, "text1", "text2");
```
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L204-L208' title='File snippet `scrublinescontainingordinal` was extracted from'>snippet source</a> | <a href='#snippet-scrublinescontainingordinal' title='Navigate to start of snippet `scrublinescontainingordinal`'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L216-L220' title='File snippet `scrublinescontainingordinal` was extracted from'>snippet source</a> | <a href='#snippet-scrublinescontainingordinal' title='Navigate to start of snippet `scrublinescontainingordinal`'>anchor</a></sup>
<!-- endsnippet -->


Expand All @@ -72,7 +72,7 @@ For example converts lines to upper case:
```cs
verifySettings.ScrubLinesWithReplace(line => line.ToUpper());
```
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L210-L214' title='File snippet `scrublineswithreplace` was extracted from'>snippet source</a> | <a href='#snippet-scrublineswithreplace' title='Navigate to start of snippet `scrublineswithreplace`'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L222-L226' title='File snippet `scrublineswithreplace` was extracted from'>snippet source</a> | <a href='#snippet-scrublineswithreplace' title='Navigate to start of snippet `scrublineswithreplace`'>anchor</a></sup>
<!-- endsnippet -->


Expand All @@ -85,7 +85,7 @@ Replaces `Environment.MachineName` with `TheMachineName`.
```cs
verifySettings.ScrubMachineName();
```
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L216-L220' title='File snippet `scrubmachinename` was extracted from'>snippet source</a> | <a href='#snippet-scrubmachinename' title='Navigate to start of snippet `scrubmachinename`'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L228-L232' title='File snippet `scrubmachinename` was extracted from'>snippet source</a> | <a href='#snippet-scrubmachinename' title='Navigate to start of snippet `scrubmachinename`'>anchor</a></sup>
<!-- endsnippet -->


Expand Down
32 changes: 16 additions & 16 deletions docs/serializer-settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ To disable this behavior globally use:
```cs
SharedVerifySettings.ModifySerialization(_ => _.DontIgnoreEmptyCollections());
```
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L144-L146' title='File snippet `dontignoreemptycollections` was extracted from'>snippet source</a> | <a href='#snippet-dontignoreemptycollections' title='Navigate to start of snippet `dontignoreemptycollections`'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L156-L158' title='File snippet `dontignoreemptycollections` was extracted from'>snippet source</a> | <a href='#snippet-dontignoreemptycollections' title='Navigate to start of snippet `dontignoreemptycollections`'>anchor</a></sup>
<!-- endsnippet -->


Expand All @@ -97,7 +97,7 @@ var target = new GuidTarget

await Verify(target);
```
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L299-L312' title='File snippet `guid` was extracted from'>snippet source</a> | <a href='#snippet-guid' title='Navigate to start of snippet `guid`'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L311-L324' title='File snippet `guid` was extracted from'>snippet source</a> | <a href='#snippet-guid' title='Navigate to start of snippet `guid`'>anchor</a></sup>
<!-- endsnippet -->

Results in the following:
Expand All @@ -122,7 +122,7 @@ To disable this behavior globally use:
```cs
SharedVerifySettings.ModifySerialization(_ => _.DontScrubGuids());
```
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L151-L153' title='File snippet `dontscrubguids` was extracted from'>snippet source</a> | <a href='#snippet-dontscrubguids' title='Navigate to start of snippet `dontscrubguids`'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L163-L165' title='File snippet `dontscrubguids` was extracted from'>snippet source</a> | <a href='#snippet-dontscrubguids' title='Navigate to start of snippet `dontscrubguids`'>anchor</a></sup>
<!-- endsnippet -->


Expand Down Expand Up @@ -174,7 +174,7 @@ To disable this behavior globally use:
```cs
SharedVerifySettings.ModifySerialization(_ => _.DontScrubDateTimes());
```
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L158-L160' title='File snippet `dontscrubdatetimes` was extracted from'>snippet source</a> | <a href='#snippet-dontscrubdatetimes' title='Navigate to start of snippet `dontscrubdatetimes`'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L170-L172' title='File snippet `dontscrubdatetimes` was extracted from'>snippet source</a> | <a href='#snippet-dontscrubdatetimes' title='Navigate to start of snippet `dontscrubdatetimes`'>anchor</a></sup>
<!-- endsnippet -->


Expand All @@ -189,7 +189,7 @@ To disable this behavior globally use:
```cs
SharedVerifySettings.ModifySerialization(_ => _.DontIgnoreFalse());
```
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L165-L167' title='File snippet `dontignorefalse` was extracted from'>snippet source</a> | <a href='#snippet-dontignorefalse' title='Navigate to start of snippet `dontignorefalse`'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L177-L179' title='File snippet `dontignorefalse` was extracted from'>snippet source</a> | <a href='#snippet-dontignorefalse' title='Navigate to start of snippet `dontignorefalse`'>anchor</a></sup>
<!-- endsnippet -->


Expand Down Expand Up @@ -262,7 +262,7 @@ settings.ModifySerialization(
settings.AddExtraSettings(
_ => { _.DateFormatHandling = DateFormatHandling.MicrosoftDateFormat; });
```
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L754-L768' title='File snippet `scopedserializer` was extracted from'>snippet source</a> | <a href='#snippet-scopedserializer' title='Navigate to start of snippet `scopedserializer`'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L766-L780' title='File snippet `scopedserializer` was extracted from'>snippet source</a> | <a href='#snippet-scopedserializer' title='Navigate to start of snippet `scopedserializer`'>anchor</a></sup>
<!-- endsnippet -->

Result:
Expand Down Expand Up @@ -303,7 +303,7 @@ var target = new IgnoreTypeTarget
};
await Verify(target, settings);
```
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L507-L525' title='File snippet `addignoretype` was extracted from'>snippet source</a> | <a href='#snippet-addignoretype' title='Navigate to start of snippet `addignoretype`'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L519-L537' title='File snippet `addignoretype` was extracted from'>snippet source</a> | <a href='#snippet-addignoretype' title='Navigate to start of snippet `addignoretype`'>anchor</a></sup>
<!-- endsnippet -->

Result:
Expand Down Expand Up @@ -345,7 +345,7 @@ var target = new IgnoreInstanceTarget
};
await Verify(target, settings);
```
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L471-L490' title='File snippet `addignoreinstance` was extracted from'>snippet source</a> | <a href='#snippet-addignoreinstance' title='Navigate to start of snippet `addignoreinstance`'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L483-L502' title='File snippet `addignoreinstance` was extracted from'>snippet source</a> | <a href='#snippet-addignoreinstance' title='Navigate to start of snippet `addignoreinstance`'>anchor</a></sup>
<!-- endsnippet -->

Result:
Expand Down Expand Up @@ -387,7 +387,7 @@ public Task WithObsoleteProp()
return Verify(target);
}
```
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L716-L735' title='File snippet `withobsoleteprop` was extracted from'>snippet source</a> | <a href='#snippet-withobsoleteprop' title='Navigate to start of snippet `withobsoleteprop`'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L728-L747' title='File snippet `withobsoleteprop` was extracted from'>snippet source</a> | <a href='#snippet-withobsoleteprop' title='Navigate to start of snippet `withobsoleteprop`'>anchor</a></sup>
<!-- endsnippet -->

Result:
Expand Down Expand Up @@ -423,7 +423,7 @@ public Task WithObsoletePropIncluded()
return Verify(target, settings);
}
```
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L700-L715' title='File snippet `withobsoletepropincluded` was extracted from'>snippet source</a> | <a href='#snippet-withobsoletepropincluded' title='Navigate to start of snippet `withobsoletepropincluded`'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L712-L727' title='File snippet `withobsoletepropincluded` was extracted from'>snippet source</a> | <a href='#snippet-withobsoletepropincluded' title='Navigate to start of snippet `withobsoletepropincluded`'>anchor</a></sup>
<!-- endsnippet -->

Result:
Expand Down Expand Up @@ -464,7 +464,7 @@ var target = new IgnoreExplicitTarget
};
await Verify(target, settings);
```
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L547-L566' title='File snippet `ignorememberbyexpression` was extracted from'>snippet source</a> | <a href='#snippet-ignorememberbyexpression' title='Navigate to start of snippet `ignorememberbyexpression`'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L559-L578' title='File snippet `ignorememberbyexpression` was extracted from'>snippet source</a> | <a href='#snippet-ignorememberbyexpression' title='Navigate to start of snippet `ignorememberbyexpression`'>anchor</a></sup>
<!-- endsnippet -->

Result:
Expand Down Expand Up @@ -507,7 +507,7 @@ var target = new IgnoreExplicitTarget
};
await Verify(target, settings);
```
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L572-L594' title='File snippet `ignorememberbyname` was extracted from'>snippet source</a> | <a href='#snippet-ignorememberbyname' title='Navigate to start of snippet `ignorememberbyname`'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L584-L606' title='File snippet `ignorememberbyname` was extracted from'>snippet source</a> | <a href='#snippet-ignorememberbyname' title='Navigate to start of snippet `ignorememberbyname`'>anchor</a></sup>
<!-- endsnippet -->

Result:
Expand Down Expand Up @@ -542,7 +542,7 @@ settings.ModifySerialization(_ => _.IgnoreMembersThatThrow<CustomException>());
var target = new WithCustomException();
await Verify(target, settings);
```
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L610-L618' title='File snippet `ignoremembersthatthrow` was extracted from'>snippet source</a> | <a href='#snippet-ignoremembersthatthrow' title='Navigate to start of snippet `ignoremembersthatthrow`'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L622-L630' title='File snippet `ignoremembersthatthrow` was extracted from'>snippet source</a> | <a href='#snippet-ignoremembersthatthrow' title='Navigate to start of snippet `ignoremembersthatthrow`'>anchor</a></sup>
<!-- endsnippet -->

Result:
Expand All @@ -567,7 +567,7 @@ settings.ModifySerialization(
var target = new WithExceptionIgnoreMessage();
await Verify(target, settings);
```
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L426-L435' title='File snippet `ignoremembersthatthrowexpression` was extracted from'>snippet source</a> | <a href='#snippet-ignoremembersthatthrowexpression' title='Navigate to start of snippet `ignoremembersthatthrowexpression`'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L438-L447' title='File snippet `ignoremembersthatthrowexpression` was extracted from'>snippet source</a> | <a href='#snippet-ignoremembersthatthrowexpression' title='Navigate to start of snippet `ignoremembersthatthrowexpression`'>anchor</a></sup>
<!-- endsnippet -->

Result:
Expand All @@ -590,7 +590,7 @@ By default newlines in json are escaped with `\r\n`:
```cs
return Verify(new {Property = "a\r\nb\\nc"});
```
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L173-L175' title='File snippet `newlineescapedinproperty` was extracted from'>snippet source</a> | <a href='#snippet-newlineescapedinproperty' title='Navigate to start of snippet `newlineescapedinproperty`'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L185-L187' title='File snippet `newlineescapedinproperty` was extracted from'>snippet source</a> | <a href='#snippet-newlineescapedinproperty' title='Navigate to start of snippet `newlineescapedinproperty`'>anchor</a></sup>
<!-- endsnippet -->

<!-- snippet: SerializationTests.NewLineEscapedInProperty.verified.txt -->
Expand All @@ -612,7 +612,7 @@ var settings = new VerifySettings();
settings.DisableNewLineEscaping();
await Verify(new {Property = "a\r\nb\\nc"}, settings);
```
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L181-L185' title='File snippet `disablenewlineescaping` was extracted from'>snippet source</a> | <a href='#snippet-disablenewlineescaping' title='Navigate to start of snippet `disablenewlineescaping`'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L193-L197' title='File snippet `disablenewlineescaping` was extracted from'>snippet source</a> | <a href='#snippet-disablenewlineescaping' title='Navigate to start of snippet `disablenewlineescaping`'>anchor</a></sup>
<!-- endsnippet -->

<!-- snippet: SerializationTests.NewLineNotEscapedInProperty.verified.txt -->
Expand Down
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>CS1591;CS0649</NoWarn>
<Version>3.0.3</Version>
<Version>3.0.4</Version>
<AssemblyVersion>1.0.0</AssemblyVersion>
<PackageTags>Json, Testing, Verify, Snapshot, Approvals</PackageTags>
<Description>Enables simple verification of complex models and documents.</Description>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ab
c
12 changes: 12 additions & 0 deletions src/Verify.Tests/Serialization/SerializationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,18 @@ public Task ShouldScrubDatetime()
return Verify(target);
}

[Fact]
public Task ScrubberWithBadNewLine()
{
var settings = new VerifySettings();
settings.AddScrubber(s =>
{
s.AppendLine("b");
s.AppendLine("c");
});
return Verify("a", settings);
}

[Fact]
public Task ExampleNonDefaults()
{
Expand Down
6 changes: 6 additions & 0 deletions src/Verify/Serialization/Scrubbers/ApplyScrubbers.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Verify;

Expand Down Expand Up @@ -35,6 +36,11 @@ public static void Apply(StringBuilder target, List<Action<StringBuilder>> scrub
{
scrubber(target);
}

if (scrubbers.Any() || SharedVerifySettings.GlobalScrubbers.Any())
{
target.FixNewlines();
}
}

static string CleanPath(string directory)
Expand Down
1 change: 1 addition & 0 deletions src/Verify/Verifier/InnerVerifier_Json.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public async Task Verify<T>(T input, VerifySettings? settings = null)
input,
settings.serialization.currentSettings,
settings.IsNewLineEscapingDisabled);
var s = formatJson.ToString();
await Verify(formatJson, settings);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Verify/Verifier/InnerVerifier_Text.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ async Task Verify(StringBuilder input, VerifySettings? settings)
var file = GetFileNames(extension, settings.Namer);

ApplyScrubbers.Apply(input, settings.instanceScrubbers);

var s = input.ToString();
var result = await Comparer.Text(file, input, settings);
engine.HandleCompareResult(result, file);
await engine.ThrowIfRequired();
Expand Down

0 comments on commit cf47b86

Please sign in to comment.