DiffPlexReporter.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the MIT License.
  3. // See the LICENSE file in the project root for more information.
  4. #nullable enable
  5. using System;
  6. using System.IO;
  7. using System.Threading.Tasks;
  8. using DiffPlex;
  9. using DiffPlex.DiffBuilder;
  10. using DiffPlex.DiffBuilder.Model;
  11. namespace ReactiveTests.Tests
  12. {
  13. public static class DiffPlexReporter
  14. {
  15. public static Task Report(string receivedFile, string verifiedFile, string? message)
  16. {
  17. #if (!DEBUG)
  18. var receivedText = File.ReadAllText(receivedFile);
  19. var verifiedText = File.ReadAllText(verifiedFile);
  20. var diffBuilder = new InlineDiffBuilder(new Differ());
  21. var diff = diffBuilder.BuildDiffModel(verifiedText, receivedText);
  22. foreach (var line in diff.Lines)
  23. {
  24. if (line.Type == ChangeType.Unchanged) continue;
  25. var prefix = " ";
  26. switch (line.Type)
  27. {
  28. case ChangeType.Inserted:
  29. prefix = "+ ";
  30. break;
  31. case ChangeType.Deleted:
  32. prefix = "- ";
  33. break;
  34. }
  35. Console.WriteLine("{0}{1}", prefix, line.Text);
  36. }
  37. #endif
  38. return Task.CompletedTask;
  39. }
  40. }
  41. }