ihoglen / google-diff-match-patch

Automatically exported from code.google.com/p/google-diff-match-patch
Apache License 2.0
0 stars 0 forks source link

diff_cleanupMerge() could be improved #75

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Here are some cases I've discovered where diff_cleanupMerge() could do a better 
job.
Probably it's not the best place to put those fixes. Or maybe such situations 
will never happen upstream in diff itself. Please let me know then.

// this works already
diffs = diffList(new Diff(EQUAL, "g"), new Diff(DELETE, "gg"), new Diff(EQUAL, 
"abc"));
dmp.diff_cleanupMerge(diffs);
assertEquals("diff_cleanupMerge: Deletion move left.",
            diffList(new Diff(DELETE, "gg"), new Diff(EQUAL, "gabc")), diffs);

// but this and the other two cases - don't
diffs = diffList(new Diff(EQUAL, "gg"), new Diff(DELETE, "g"), new Diff(EQUAL, 
"abc"));
dmp.diff_cleanupMerge(diffs);
assertEquals("diff_cleanupMerge: Deletion multi-move left.",
            diffList(new Diff(DELETE, "g"), new Diff(EQUAL, "ggabc")), diffs);

diffs = diffList(new Diff(EQUAL, "gdgd"), new Diff(DELETE, "gd"), new 
Diff(EQUAL, "abc"));
dmp.diff_cleanupMerge(diffs);
assertEquals("diff_cleanupMerge: Deletion multi-move left.",
            diffList(new Diff(DELETE, "gd"), new Diff(EQUAL, "gdgdabc")), diffs);

diffs = diffList(new Diff(EQUAL, "ggg"), new Diff(DELETE, "gg"), new 
Diff(EQUAL, "abc"));
dmp.diff_cleanupMerge(diffs);
assertEquals("diff_cleanupMerge: Deletion tricky move left.",
            diffList(new Diff(DELETE, "gg"), new Diff(EQUAL, "gggabc")), diffs);

The same applies to right shifts too.

Original issue reported on code.google.com by 2sa...@gmail.com on 10 Jul 2012 at 9:43