Commit 6c00024a authored by Stein Eldar Johnsen's avatar Stein Eldar Johnsen 💬

EqualToLines: Use LineDiff.fullDiff() for mismatch.

parent b6f6c1e6
......@@ -18,14 +18,10 @@
*/
package net.morimekta.testing.matchers;
import net.morimekta.diff.Change;
import net.morimekta.diff.DiffLines;
import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import java.util.List;
/**
* Equality matcher that that ignores changes in line separators, and shows
* a line by line diff on mismatch.
......@@ -59,29 +55,10 @@ public class EqualToLines extends BaseMatcher<String> {
return;
}
List<Change> changes = new DiffLines(expected, normalize(item)).getChangeList();
description.appendText("has line-by-line diff:" + System.lineSeparator());
DiffLines diff = new DiffLines(expected, normalize(item));
for (Change change : changes) {
switch (change.operation) {
case EQUAL:
description.appendText(" ")
.appendText(change.text)
.appendText(System.lineSeparator());
break;
case DELETE:
description.appendText("- ")
.appendText(change.text)
.appendText(System.lineSeparator());
break;
case INSERT:
description.appendText("+ ")
.appendText(change.text)
.appendText(System.lineSeparator());
break;
}
}
description.appendText("has line-by-line diff:" + System.lineSeparator())
.appendText(diff.fullDiff().replaceAll("\n", System.lineSeparator()));
}
private static String normalize(Object o) {
......
......@@ -52,12 +52,12 @@ public class EqualToLinesTest {
assertThat(describeMismatch(unixMatcher, diffWindows), is(equalTo(
("has line-by-line diff:\n" +
"- Lorem ipsum dolor sit amet, consectetur adipiscing elit,\n" +
"+ Lorem ipsum dolor sit amet, kontectetur adipiscing elit,\n" +
"-Lorem ipsum dolor sit amet, consectetur adipiscing elit,\n" +
"+Lorem ipsum dolor sit amet, kontectetur adipiscing elit,\n" +
" sed do eiusmod tempor incididunt ut labore et dolore magna\n" +
" aliqua. Ut enim ad minim veniam, quis nostrud exercitation\n" +
"- ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis\n" +
"+ ullamco laboris nisi ut aliquip ex ea commodo kontequat. Duis\n" +
"-ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis\n" +
"+ullamco laboris nisi ut aliquip ex ea commodo kontequat. Duis\n" +
" aute irure dolor in reprehenderit in voluptate velit esse\n" +
" cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat\n" +
" cupidatat non proident, sunt in culpa qui officia deserunt\n" +
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment