Skip to content

Commit e2f4e26

Browse files
authored
Add OutputType.Minimal (#185)
1 parent 5a4eb9b commit e2f4e26

File tree

6 files changed

+83
-6
lines changed

6 files changed

+83
-6
lines changed

readme.md

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ https://nuget.org/packages/Verify.DiffPlex/
2020

2121
### Initialize
2222

23-
Call `VerifyDiffPlex.Initialize()` in a `[ModuleInitializer]`. Alternatively, use `VerifyDiffPlex.Initialize(OutputType.Full)` or `VerifyDiffPlex.Initialize(OutputType.Compact)` to specify the type of output (see below).
23+
Call `VerifyDiffPlex.Initialize()` in a `[ModuleInitializer]`. Alternatively, use `VerifyDiffPlex.Initialize(OutputType.Full)`, `VerifyDiffPlex.Initialize(OutputType.Compact)` or `VerifyDiffPlex.Initialize(OutputType.Minimal)` to specify the type of output (see below).
2424

2525
<!-- snippet: ModuleInitializer.cs -->
2626
<a id='snippet-ModuleInitializer.cs'></a>
@@ -89,7 +89,7 @@ Compare Result:
8989

9090
### Output types
9191

92-
The library currently supports two different types of diff outputs; the desired type can be specified during library initialization.
92+
The library currently supports three different types of diff outputs; the desired type can be specified during library initialization.
9393

9494
<!-- snippet: OutputTypeCompact -->
9595
<a id='snippet-outputtypecompact'></a>
@@ -116,7 +116,7 @@ public static void Init() =>
116116
Eighth line
117117
```
118118

119-
This output type gives the most information, but if verified files are long, it can be difficult to read through and find the actual differences. `OutputType.Compact` will show only the changed lines, with one line of context (with line number) before and after each changed section to help identify where the change is. The `Full` output above would look like this as `Compact`.
119+
This output type gives the most information, but if verified files are long, it can be difficult to read through and find the actual differences. `OutputType.Compact` will show only the changed lines, with one line of context (with line number) before and after each changed section to help identify where the change is.
120120

121121
```
122122
1 First line
@@ -130,6 +130,15 @@ This output type gives the most information, but if verified files are long, it
130130
7 Seventh line
131131
```
132132

133+
Lastly, there is `OutputType.Minimal` which will show only the changed lines.
134+
135+
```
136+
- Second line
137+
+ Second line changed
138+
- Sixth line
139+
+ Sixth line changed
140+
```
141+
133142

134143
### Test level settings
135144

@@ -147,7 +156,7 @@ public Task TestLevelUsage()
147156
return Verify(target, settings);
148157
}
149158
```
150-
<sup><a href='/src/Tests/Tests.cs#L93-L104' title='Snippet source file'>snippet source</a> | <a href='#snippet-testlevelusage' title='Start of snippet'>anchor</a></sup>
159+
<sup><a href='/src/Tests/Tests.cs#L111-L122' title='Snippet source file'>snippet source</a> | <a href='#snippet-testlevelusage' title='Start of snippet'>anchor</a></sup>
151160
<!-- endSnippet -->
152161

153162
Or Fluently
@@ -163,5 +172,5 @@ public Task TestLevelUsageFluent()
163172
.UseDiffPlex();
164173
}
165174
```
166-
<sup><a href='/src/Tests/Tests.cs#L106-L116' title='Snippet source file'>snippet source</a> | <a href='#snippet-testlevelusagefluent' title='Start of snippet'>anchor</a></sup>
175+
<sup><a href='/src/Tests/Tests.cs#L124-L134' title='Snippet source file'>snippet source</a> | <a href='#snippet-testlevelusagefluent' title='Start of snippet'>anchor</a></sup>
167176
<!-- endSnippet -->
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
Type: VerifyException,
3+
Message:
4+
Directory: {ProjectDirectory}
5+
NotEqual:
6+
- Received: Tests.AtTestLevelMinimalFake.received.txt
7+
Verified: Tests.AtTestLevelMinimalFake.verified.txt
8+
9+
FileContent:
10+
11+
NotEqual:
12+
13+
Received: Tests.AtTestLevelMinimalFake.received.txt
14+
Verified: Tests.AtTestLevelMinimalFake.verified.txt
15+
Compare Result:
16+
- before
17+
+ after
18+
19+
20+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
The
2+
before
3+
text

src/Tests/Tests.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,24 @@ public Task AtTestLevelCompact()
7979
settings));
8080
}
8181

82+
[Test]
83+
public Task AtTestLevelMinimal()
84+
{
85+
var settings = new VerifySettings();
86+
settings.UseMethodName("AtTestLevelMinimalFake");
87+
settings.DisableDiff();
88+
settings.UseDiffPlex(OutputType.Minimal);
89+
90+
return ThrowsTask(() =>
91+
Verify(
92+
"""
93+
The
94+
after
95+
text
96+
""",
97+
settings));
98+
}
99+
82100
[Test]
83101
public Task Sample()
84102
{

src/Verify.DiffPlex/OutputType.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
namespace VerifyTests.DiffPlex;
22

3-
public enum OutputType { Full, Compact }
3+
public enum OutputType { Full, Compact, Minimal }

src/Verify.DiffPlex/VerifyDiffPlex.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ static Func<string, string, StringBuilder> GetCompareFunc(OutputType outputType)
1010
outputType switch
1111
{
1212
OutputType.Compact => CompactCompare,
13+
OutputType.Minimal => MinimalCompare,
1314
_ => VerboseCompare
1415
};
1516

@@ -69,6 +70,32 @@ static StringBuilder VerboseCompare(string received, string verified)
6970
return builder;
7071
}
7172

73+
static StringBuilder MinimalCompare(string received, string verified)
74+
{
75+
var diff = InlineDiffBuilder.Diff(verified, received);
76+
77+
var builder = new StringBuilder();
78+
foreach (var line in diff.Lines)
79+
{
80+
switch (line.Type)
81+
{
82+
case ChangeType.Inserted:
83+
builder.Append("+ ");
84+
break;
85+
case ChangeType.Deleted:
86+
builder.Append("- ");
87+
break;
88+
default:
89+
// omit unchanged files
90+
continue;
91+
}
92+
93+
builder.AppendLine(line.Text);
94+
}
95+
96+
return builder;
97+
}
98+
7299
static StringBuilder CompactCompare(string received, string verified)
73100
{
74101
var diff = InlineDiffBuilder.Diff(verified, received);

0 commit comments

Comments
 (0)