Tests - fixed failing tests

This commit is contained in:
dragonmacher 2019-05-03 13:15:05 -04:00
parent c004a11c6b
commit a4609c50f2
13 changed files with 166 additions and 367 deletions

View file

@ -208,9 +208,12 @@ class StringDiffUtils {
start += l.text.length();
}
// strip off the trailing newline that we added above
if (result.isEmpty()) {
result.add(new Line("", 0));
}
Line last = result.peekLast();
last.markAsLast();
last.markAsLast(); // this will signal to remove the trailing newline for the last line
return result;
}

View file

@ -159,6 +159,39 @@ public class StringDiffTest {
assertEquals(v2, restoredV2);
}
@Test
public void testGetLineDiffs_Empty() {
String v1 = "";
String v2 = "";
StringDiff[] diffs = StringDiffUtils.getLineDiffs(v1, v2, 0);
String restoredV2 = StringDiffUtils.applyDiffs(v1, Arrays.asList(diffs));
assertEquals(v2, restoredV2);
}
@Test
public void testGetLineDiffs_EmptyInitial() {
String v1 = "";
String v2 = "This is not empty";
StringDiff[] diffs = StringDiffUtils.getLineDiffs(v1, v2, 0);
String restoredV2 = StringDiffUtils.applyDiffs(v1, Arrays.asList(diffs));
assertEquals(v2, restoredV2);
}
@Test
public void testGetLineDiffs_EmptyReplacement() {
String v1 = "This is not empty";
String v2 = "";
StringDiff[] diffs = StringDiffUtils.getLineDiffs(v1, v2, 0);
String restoredV2 = StringDiffUtils.applyDiffs(v1, Arrays.asList(diffs));
assertEquals(v2, restoredV2);
}
@Test
public void testReplace() {
String[] a1 = new String[] { "In", "the", "beginning" };