jcdickinson / difflib

Easy diffs in C#
BSD 3-Clause "New" or "Revised" License
12 stars 2 forks source link

Missing diff instruction at beginning of sequences #2

Closed natewallace closed 9 years ago

natewallace commented 9 years ago

Unless I'm using your library incorrectly It looks like the Differencer.FindDifferences method is not reporting inserts at the beginning of a sequence. Most likely it's not reporting removes either but I didn't test for that.

Using the following code:

List<string> olderList = new List<string>(new string[] {
    "public  class MyException extends Exception {",
    "",
    "}"
});
List<string> newerList = new List<string>(new string[] {
    "/**",
    " * Simple exception.",
    " */",
    "public  class MyException extends Exception {",
    "",
    "}"
});
DiffLib.PatienceSequenceMatcher<string> matcher = new DiffLib.PatienceSequenceMatcher<string>();
DiffLib.Differencer<string> differencer = new DiffLib.Differencer<string>(matcher);
IEnumerable<DiffLib.DifferenceInstruction> diffs = differencer.FindDifferences(
    olderList, 
    newerList);

I'm expecting the diffs collection to have the following results: {+ (0, 0 -> 2)} {= (0 -> 2, 3 -> 5)}

However the actual results are: {= (0 -> 2, 3 -> 5)}

jcdickinson commented 9 years ago

@natewallace thanks for the bug report. Please let me know if you run into any more issues as one thing I really need is test cases.