Skip to content

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

Description

@veteda

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;
    }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions