loganga / java-diff-utils

Automatically exported from code.google.com/p/java-diff-utils
0 stars 0 forks source link

Change line has wrong diff indicators #18

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

This JUnit test fails on the 2nd assert:

    public final void testGenerateDiffRowsListOfStringListOfStringChange1() {

        DiffRowGenerator generator = new DiffRowGenerator.Builder().showInlineDiffs(true).ignoreWhiteSpaces(true)
                .columnWidth(100).build();

        List<String> revised = new ArrayList<String>();
        List<String> original = new ArrayList<String>();

        original.add("aaaaa");
        revised.add("aabaa");

        List<DiffRow> result = generator.generateDiffRows(original, revised);

        assertEquals("wrong size", 1, result.size());

        assertEquals("wrong tag", DiffRow.Tag.CHANGE, result.get(0).getTag());
        assertEquals("wrong new value", "aa<span class=\"editNewInline\">b</span>aa", result.get(0).getNewLine());
        assertEquals("wrong old value", "aa<span class=\"editOldInline\">a</span>aa", result.get(0).getOldLine());
    }

What is the expected output? What do you see instead?

junit.framework.ComparisonFailure: wrong old value expected:<aa[<span 
class="editOldInline">a</span>aa]> but was:<aa[aa<span 
class="editOldInline">a</span>]>
    at junit.framework.Assert.assertEquals(Assert.java:81)

Note that the difference for the "old" line indicates the changed part is the 
last "a" and not the middle "a" where it should be.

What version of the product are you using? On what operating system?

Downloaded this file: java-diff-utils-1.2src.zip
Windows XP

Please provide any additional information below.

Original issue reported on code.google.com by LeeMeado...@gmail.com on 2 May 2011 at 2:31

Attachments:

GoogleCodeExporter commented 8 years ago
if you use "abcde" and "ab*de" it will show a single change from 'c' to '*' but 
this shows what the algorighm is doing "wrong". If it is thinking in terms of 
inserts and deletes only for "aaaaa" -> "aa*aa", there is no difference between 
the steps a, a, delete-a, insert-*, a, a and the steps a, a, insert-*, a, a, 
delete-a and it only happens when there are repeated characters (in this case 
'a' characters) after the change point. I'm guessing the delete-insert when 
together turn into a change but the delete and insert separated by two 'a' 
characters wouldn't. So ... if you decide it is a bug, the problem is in the 
way the diff algorithm weighs the cost of inserts and deletes when optimizing. 
Deletes and inserts that are next to each other can turn into a change and 
should weigh, together, the same as a single delete or insert.

Original comment by LeeMeado...@gmail.com on 4 May 2011 at 11:19