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

Change line has wrong diff indicators #18

Open
GoogleCodeExporter opened this issue May 19, 2015 · 1 comment
Open

Change line has wrong diff indicators #18

GoogleCodeExporter opened this issue May 19, 2015 · 1 comment

Comments

@GoogleCodeExporter
Copy link

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
Copy link
Author

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

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

No branches or pull requests

1 participant