-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8d3e24c
commit 608af94
Showing
27 changed files
with
541 additions
and
471 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace TestsHelper.SourceGenerator.Tests; | ||
|
||
public static class DictionaryHelper | ||
{ | ||
public static Dictionary<TKey, TValue> MergeRight<TKey, TValue>(params Dictionary<TKey, TValue>[] dictionaries) | ||
where TKey : notnull | ||
{ | ||
Dictionary<TKey, TValue> dictionary = new Dictionary<TKey, TValue>(); | ||
|
||
foreach (Dictionary<TKey,TValue> d in dictionaries) | ||
{ | ||
foreach ((TKey key, TValue value) in d) | ||
{ | ||
dictionary[key] = value; | ||
} | ||
} | ||
return dictionary; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Linq; | ||
using System.Text; | ||
using DiffPlex; | ||
using DiffPlex.Chunkers; | ||
using DiffPlex.DiffBuilder; | ||
using DiffPlex.DiffBuilder.Model; | ||
|
||
namespace TestsHelper.SourceGenerator.Tests; | ||
|
||
public static class Diff | ||
{ | ||
private static readonly IChunker _lineChunker = new LineChunker(); | ||
private static readonly IChunker _lineEndingsPreservingChunker = new LineEndingsPreservingChunker(); | ||
private static readonly InlineDiffBuilder _diffBuilder = new InlineDiffBuilder(new Differ()); | ||
|
||
public static bool IsDifferent(string expected, string actual, [NotNullWhen(true)] out string? displayMessage) | ||
{ | ||
displayMessage = default; | ||
if (expected == actual) return false; | ||
|
||
DiffPaneModel? diff = _diffBuilder.BuildDiffModel(expected, actual, ignoreWhitespace: false, ignoreCase: false, _lineChunker); | ||
var messageBuilder = new StringBuilder(); | ||
messageBuilder.AppendLine("Actual and expected values differ. Expected shown in baseline of diff:"); | ||
|
||
if (!diff.Lines.Any(line => line.Type is ChangeType.Inserted or ChangeType.Deleted)) | ||
{ | ||
// We have a failure only caused by line ending differences; recalculate with line endings visible | ||
diff = _diffBuilder.BuildDiffModel(expected, actual, ignoreWhitespace: false, ignoreCase: false, | ||
_lineEndingsPreservingChunker); | ||
} | ||
|
||
foreach (DiffPiece? line in diff.Lines) | ||
{ | ||
switch (line.Type) | ||
{ | ||
case ChangeType.Inserted: | ||
messageBuilder.Append('+'); | ||
break; | ||
case ChangeType.Deleted: | ||
messageBuilder.Append('-'); | ||
break; | ||
default: | ||
messageBuilder.Append(' '); | ||
break; | ||
} | ||
|
||
messageBuilder.AppendLine(line.Text.Replace("\r", "<CR>").Replace("\n", "<LF>")); | ||
} | ||
|
||
displayMessage = messageBuilder.ToString(); | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using NUnit.Framework.Constraints; | ||
|
||
namespace TestsHelper.SourceGenerator.Tests; | ||
|
||
public class DiffConstraint : Constraint | ||
{ | ||
private readonly string _expected; | ||
|
||
public DiffConstraint(string expected) | ||
{ | ||
_expected = expected; | ||
} | ||
|
||
public override ConstraintResult ApplyTo<TActual>(TActual actual) | ||
{ | ||
if (actual is string actualValue) | ||
{ | ||
if (Diff.IsDifferent(_expected, actualValue, out var message)) | ||
{ | ||
return new Result(this, actual, ConstraintStatus.Failure, message); | ||
} | ||
|
||
return new Result(this, actual, ConstraintStatus.Success, string.Empty); | ||
} | ||
|
||
return new Result(this, actual, ConstraintStatus.Failure, "Expected is not string"); | ||
} | ||
|
||
private sealed class Result : ConstraintResult | ||
{ | ||
private readonly string _diffDisplay; | ||
|
||
public Result(IConstraint constraint, object actualValue, ConstraintStatus status, string diffDisplay) | ||
: base(constraint, actualValue, status) | ||
{ | ||
_diffDisplay = diffDisplay; | ||
} | ||
|
||
public override void WriteMessageTo(MessageWriter writer) | ||
{ | ||
writer.WriteMessageLine(_diffDisplay); | ||
} | ||
} | ||
} |
228 changes: 0 additions & 228 deletions
228
TestsHelper.SourceGenerator.Tests/MockFillerSourceGeneratorTests.cs
This file was deleted.
Oops, something went wrong.
18 changes: 0 additions & 18 deletions
18
TestsHelper.SourceGenerator.Tests/Sources/ATestFixture.FilledMock.WithWrappers.generated.cs
This file was deleted.
Oops, something went wrong.
16 changes: 0 additions & 16 deletions
16
TestsHelper.SourceGenerator.Tests/Sources/ATestFixture.FilledMock.generated.cs
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.