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

EqualToLines: Use LineDiff.fullDiff() for mismatch.

parent b6f6c1e6
...@@ -18,14 +18,10 @@ ...@@ -18,14 +18,10 @@
*/ */
package net.morimekta.testing.matchers; package net.morimekta.testing.matchers;
import net.morimekta.diff.Change;
import net.morimekta.diff.DiffLines; import net.morimekta.diff.DiffLines;
import org.hamcrest.BaseMatcher; import org.hamcrest.BaseMatcher;
import org.hamcrest.Description; import org.hamcrest.Description;
import java.util.List;
/** /**
* Equality matcher that that ignores changes in line separators, and shows * Equality matcher that that ignores changes in line separators, and shows
* a line by line diff on mismatch. * a line by line diff on mismatch.
...@@ -59,29 +55,10 @@ public class EqualToLines extends BaseMatcher<String> { ...@@ -59,29 +55,10 @@ public class EqualToLines extends BaseMatcher<String> {
return; return;
} }
List<Change> changes = new DiffLines(expected, normalize(item)).getChangeList(); DiffLines diff = new DiffLines(expected, normalize(item));
description.appendText("has line-by-line diff:" + System.lineSeparator()); description.appendText("has line-by-line diff:" + System.lineSeparator())
.appendText(diff.fullDiff().replaceAll("\n", System.lineSeparator()));
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;
}
}
} }
private static String normalize(Object o) { private static String normalize(Object o) {
......
...@@ -52,16 +52,16 @@ public class EqualToLinesTest { ...@@ -52,16 +52,16 @@ public class EqualToLinesTest {
assertThat(describeMismatch(unixMatcher, diffWindows), is(equalTo( assertThat(describeMismatch(unixMatcher, diffWindows), is(equalTo(
("has line-by-line diff:\n" + ("has line-by-line diff:\n" +
"- Lorem ipsum dolor sit amet, consectetur adipiscing elit,\n" + "-Lorem ipsum dolor sit amet, consectetur adipiscing elit,\n" +
"+ Lorem ipsum dolor sit amet, kontectetur adipiscing elit,\n" + "+Lorem ipsum dolor sit amet, kontectetur adipiscing elit,\n" +
" sed do eiusmod tempor incididunt ut labore et dolore magna\n" + " sed do eiusmod tempor incididunt ut labore et dolore magna\n" +
" aliqua. Ut enim ad minim veniam, quis nostrud exercitation\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 consequat. Duis\n" +
"+ ullamco laboris nisi ut aliquip ex ea commodo kontequat. Duis\n" + "+ullamco laboris nisi ut aliquip ex ea commodo kontequat. Duis\n" +
" aute irure dolor in reprehenderit in voluptate velit esse\n" + " aute irure dolor in reprehenderit in voluptate velit esse\n" +
" cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat\n" + " cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat\n" +
" cupidatat non proident, sunt in culpa qui officia deserunt\n" + " cupidatat non proident, sunt in culpa qui officia deserunt\n" +
" mollit anim id est laborum.\n").replaceAll("\\n", System.lineSeparator())))); " mollit anim id est laborum.\n").replaceAll("\\n", System.lineSeparator()))));
} }
private String describeTo(Matcher<?> matcher) { private String describeTo(Matcher<?> matcher) {
......
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