use of org.suigeneris.jrcs.diff.delta.Chunk in project xwiki-platform by xwiki.
the class DiffTest method testSimpleLineDiff2.
@Test
public void testSimpleLineDiff2() throws XWikiException {
String text1 = "A\nB\nC";
String text2 = "A\nB B\nC";
List diffs = this.plugin.getDifferencesAsList(text1, text2);
assertEquals("There should be one difference", 1, diffs.size());
Delta delta = (Delta) diffs.get(0);
Chunk orig = delta.getOriginal();
Chunk revised = delta.getRevised();
assertEquals("Original should be", "B", orig.toString());
assertEquals("Revised should be", "B B", revised.toString());
}
use of org.suigeneris.jrcs.diff.delta.Chunk in project xwiki-platform by xwiki.
the class XWikiPatchUtils method patch.
/**
* From {@link org.suigeneris.jrcs.rcs.impl.Node#patch(List, boolean)}.
*
* @param orig - text to patch, List<String> of lines.
* @param diff - diff to patch, {@link Diff} format
* @throws InvalidFileFormatException if diff is incorrect
* @throws PatchFailedException if error in patching
*/
public static void patch(List<String> orig, String diff) throws InvalidFileFormatException, PatchFailedException {
Revision revision = new Revision();
Object[] lines = ToString.stringToArray(diff);
for (int it = 0; it < lines.length; it++) {
String cmd = lines[it].toString();
if (cmd.length() == 0) {
break;
}
java.util.StringTokenizer t = new StringTokenizer(cmd, "ad ", true);
char action;
int n;
int count;
try {
action = t.nextToken().charAt(0);
n = Integer.parseInt(t.nextToken());
// skip the space
t.nextToken();
count = Integer.parseInt(t.nextToken());
} catch (Exception e) {
throw new InvalidFileFormatException("line:" + ":" + e.getClass().getName(), e);
}
if (action == 'd') {
revision.addDelta(new DeleteDelta(new Chunk(n - 1, count)));
} else if (action == 'a') {
revision.addDelta(new AddDelta(n, new Chunk(getTextLines(lines, it + 1, it + 1 + count), 0, count, n - 1)));
it += count;
} else {
throw new InvalidFileFormatException();
}
}
revision.applyTo(orig);
}
use of org.suigeneris.jrcs.diff.delta.Chunk in project xwiki-platform by xwiki.
the class DiffTest method testSimpleLineDiff.
@Test
public void testSimpleLineDiff() throws XWikiException {
String text1 = "A";
String text2 = "A B";
List diffs = this.plugin.getDifferencesAsList(text1, text2);
assertEquals("There should be one difference", 1, diffs.size());
Delta delta = (Delta) diffs.get(0);
Chunk orig = delta.getOriginal();
Chunk revised = delta.getRevised();
assertEquals("Original should be", "A", orig.toString());
assertEquals("Revised should be", "A B", revised.toString());
}
use of org.suigeneris.jrcs.diff.delta.Chunk in project xwiki-platform by xwiki.
the class DiffTest method testSimpleWordDiff4.
@Test
public void testSimpleWordDiff4() throws XWikiException {
String text1 = "I love Paris and I like London";
String text2 = "I love London and I like Paris";
List diffs = this.plugin.getWordDifferencesAsList(text1, text2);
assertEquals("There should be two differences", 2, diffs.size());
Delta delta1 = (Delta) diffs.get(0);
Chunk orig1 = delta1.getOriginal();
Chunk revised1 = delta1.getRevised();
Delta delta2 = (Delta) diffs.get(1);
Chunk orig2 = delta2.getOriginal();
Chunk revised2 = delta2.getRevised();
assertEquals("Original 1 should be", "Paris", orig1.toString());
assertEquals("Revised 1 should be", "London", revised1.toString());
assertEquals("Original 2 should be", "London", orig2.toString());
assertEquals("Revised 2 should be", "Paris", revised2.toString());
}
Aggregations