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

ChangeType.Modified is not working, instead it shows the changed line as deleted and added #108

Open
veteda opened this issue Jul 12, 2023 · 1 comment

Comments

@veteda
Copy link

veteda commented Jul 12, 2023

Hello,
In the following code ChangeType.Modified is not working. When there is a change within a line, it's detected as deleted and added and is counted as two changes instead of one. Could you please provide more info about why the ChangeType.Modified is not working and how to fix it? Thank you in advance

public static int CompareTwoNCFiles(string expectedResultFile, string newGeneratedFile, string comparisonFile)
{

        StringBuilder sb = new StringBuilder();
        var d = new Differ();
        var builder = new InlineDiffBuilder(d);
        var result = builder.BuildDiffModel(expectedResultFile, newGeneratedFile, ignoreWhitespace: true);
        int countOfChanges = 0;
        List<string> exceptions = new List<string>
        {
            "PPF VERSION",
            "POST VERSION",
            "PROJECT NAME",
            "PROGRAM DATE",
            "UNIQUEJOBID"
        };

        foreach (var line in result.Lines)
        {
            if (exceptions.Any(e => line.Text.Contains(e)))
                continue;

            switch (line.Type)
            {
                case ChangeType.Inserted:
                    sb.Append("+ ");
                    countOfChanges++;
                    break;

                case ChangeType.Deleted:
                    sb.Append("- ");
                    countOfChanges++;
                    break;

                case ChangeType.Modified: // Modified is not working with the current implementation
                    sb.Append("* ");
                    countOfChanges++;
                    break;

                case ChangeType.Imaginary:
                    sb.Append("? ");
                    break;

                case ChangeType.Unchanged:
                    sb.Append("  ");
                    break;
            }
            sb.Append(line.Text + "\n");

        }
        File.WriteAllText(comparisonFile, sb.ToString());
        return countOfChanges;
    }
@mmanela
Copy link
Owner

mmanela commented Sep 10, 2023

The pre-defined InlineDiffBuilder doesn't do sub-diffing results. The SideBySideDiffBuilder does. You can use that one to see if the results are what you expect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants