Search in sources :

Example 1 with IntraLineDiffArgs

use of com.google.gerrit.server.patch.IntraLineDiffArgs in project gerrit by GerritCodeReview.

the class PatchListCacheIT method harmfulMutationsOfEditsAreNotPossibleForIntraLineDiffArgsAndCachedValue.

@Test
public void harmfulMutationsOfEditsAreNotPossibleForIntraLineDiffArgsAndCachedValue() throws Exception {
    String a = "First line\nSecond line\n";
    String b = "1st line\n2nd line\n";
    Text aText = new Text(a.getBytes(UTF_8));
    Text bText = new Text(b.getBytes(UTF_8));
    Edit inputEdit = new Edit(0, 2, 0, 2);
    List<Edit> inputEdits = new ArrayList<>(ImmutableList.of(inputEdit));
    IntraLineDiffKey diffKey = IntraLineDiffKey.create(ObjectId.zeroId(), ObjectId.zeroId(), Whitespace.IGNORE_NONE);
    IntraLineDiffArgs diffArgs = IntraLineDiffArgs.create(aText, bText, inputEdits, project, ObjectId.zeroId(), "file.txt");
    IntraLineDiff intraLineDiff = patchListCache.getIntraLineDiff(diffKey, diffArgs);
    Edit outputEdit = Iterables.getOnlyElement(intraLineDiff.getEdits());
    outputEdit.shift(5);
    inputEdit.shift(7);
    inputEdits.add(new Edit(43, 47, 50, 51));
    Edit originalEdit = new Edit(0, 2, 0, 2);
    assertThat(diffArgs.edits()).containsExactly(originalEdit);
    assertThat(intraLineDiff.getEdits()).containsExactly(originalEdit);
}
Also used : IntraLineDiffArgs(com.google.gerrit.server.patch.IntraLineDiffArgs) IntraLineDiffKey(com.google.gerrit.server.patch.IntraLineDiffKey) IntraLineDiff(com.google.gerrit.server.patch.IntraLineDiff) ArrayList(java.util.ArrayList) Text(com.google.gerrit.server.patch.Text) Edit(org.eclipse.jgit.diff.Edit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Aggregations

AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)1 IntraLineDiff (com.google.gerrit.server.patch.IntraLineDiff)1 IntraLineDiffArgs (com.google.gerrit.server.patch.IntraLineDiffArgs)1 IntraLineDiffKey (com.google.gerrit.server.patch.IntraLineDiffKey)1 Text (com.google.gerrit.server.patch.Text)1 ArrayList (java.util.ArrayList)1 Edit (org.eclipse.jgit.diff.Edit)1 Test (org.junit.Test)1