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

Diffplex implemented to compare strings in TestUtils.cs #426

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 20 additions & 13 deletions TypeCobol.Test/TestUtils.cs
Expand Up @@ -4,6 +4,9 @@
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using DiffPlex;
using DiffPlex.DiffBuilder;
using DiffPlex.DiffBuilder.Model;

namespace TypeCobol.Test
{
Expand All @@ -20,24 +23,28 @@ public class TestUtils
public static void compareLines(string testName, string result, string expectedResult)
{
StringBuilder errors = new StringBuilder();
var linefaults = new List<int?>();

result = Regex.Replace(result, "(?<!\r)\n", "\r\n");
expectedResult = Regex.Replace(expectedResult, "(?<!\r)\n", "\r\n");
var d = new Differ();
var inlineBuilder = new InlineDiffBuilder(d);
var result1 = inlineBuilder.BuildDiffModel(result, expectedResult);

String[] expectedResultLines = expectedResult.Split('\r', '\n' );
String[] resultLines = result.Split('\r', '\n');

var linefaults = new List<int>();
for (int c = 0; c < resultLines.Length && c < expectedResultLines.Length; c++) {
if (expectedResultLines[c] != resultLines[c]) linefaults.Add(c/2+1);
foreach (var line in result1.Lines)
{
if (line.Type == ChangeType.Deleted)
errors.Append(line.Text + "\n");
else if (line.Type == ChangeType.Inserted)
linefaults.Add(line.Position);
}

if (result != expectedResult)
if (errors.Length > 0)
{
errors.Append("result != expectedResult In test:" + testName)
.AppendLine(" at line"+(linefaults.Count>1?"s":"")+": "+string.Join(",", linefaults));
errors.Append("=== RESULT ==========\n" + result + "====================");
throw new Exception(errors.ToString());
StringBuilder errorMessage = new StringBuilder();
errorMessage.Append("result != expectedResult In test:" + testName)
.AppendLine(" at line" + (linefaults.Count > 1 ? "s" : "") + ": " + string.Join(",", linefaults));

errorMessage.Append(errors);
throw new Exception(errorMessage.ToString());
}
}
}
Expand Down