Search in sources :

Example 1 with Range

use of com.google.gerrit.reviewdb.client.Comment.Range in project gerrit by GerritCodeReview.

the class FixReplacementInterpreterTest method treeModificationsTargetCorrectFiles.

@Test
public void treeModificationsTargetCorrectFiles() throws Exception {
    FixReplacement fixReplacement = new FixReplacement(filePath1, new Range(1, 6, 3, 2), "Modified content");
    FixReplacement fixReplacement2 = new FixReplacement(filePath1, new Range(3, 5, 3, 5), "Second modification");
    mockFileContent(filePath1, "First line\nSecond line\nThird line\n");
    FixReplacement fixReplacement3 = new FixReplacement(filePath2, new Range(2, 0, 3, 0), "Another modified content");
    mockFileContent(filePath2, "1st line\n2nd line\n3rd line\n");
    replay(fileContentUtil);
    List<TreeModification> treeModifications = toTreeModifications(fixReplacement, fixReplacement3, fixReplacement2);
    List<TreeModification> sortedTreeModifications = getSortedCopy(treeModifications);
    assertThatList(sortedTreeModifications).element(0).asChangeFileContentModification().filePath().isEqualTo(filePath1);
    assertThatList(sortedTreeModifications).element(0).asChangeFileContentModification().newContent().startsWith("First");
    assertThatList(sortedTreeModifications).element(1).asChangeFileContentModification().filePath().isEqualTo(filePath2);
    assertThatList(sortedTreeModifications).element(1).asChangeFileContentModification().newContent().startsWith("1st");
}
Also used : TreeModification(com.google.gerrit.server.edit.tree.TreeModification) FixReplacement(com.google.gerrit.reviewdb.client.FixReplacement) Range(com.google.gerrit.reviewdb.client.Comment.Range) Test(org.junit.Test)

Example 2 with Range

use of com.google.gerrit.reviewdb.client.Comment.Range in project gerrit by GerritCodeReview.

the class FixReplacementInterpreterTest method lineSeparatorCanBeChanged.

@Test
public void lineSeparatorCanBeChanged() throws Exception {
    FixReplacement fixReplacement = new FixReplacement(filePath1, new Range(2, 11, 3, 0), "\r");
    mockFileContent(filePath1, "First line\nSecond line\nThird line\n");
    replay(fileContentUtil);
    List<TreeModification> treeModifications = toTreeModifications(fixReplacement);
    assertThatList(treeModifications).onlyElement().asChangeFileContentModification().newContent().isEqualTo("First line\nSecond line\rThird line\n");
}
Also used : TreeModification(com.google.gerrit.server.edit.tree.TreeModification) FixReplacement(com.google.gerrit.reviewdb.client.FixReplacement) Range(com.google.gerrit.reviewdb.client.Comment.Range) Test(org.junit.Test)

Example 3 with Range

use of com.google.gerrit.reviewdb.client.Comment.Range in project gerrit by GerritCodeReview.

the class FixReplacementInterpreterTest method replacementsMayTouch.

@Test
public void replacementsMayTouch() throws Exception {
    FixReplacement fixReplacement1 = new FixReplacement(filePath1, new Range(1, 6, 2, 7), "modified ");
    FixReplacement fixReplacement2 = new FixReplacement(filePath1, new Range(2, 7, 3, 5), "content");
    mockFileContent(filePath1, "First line\nSecond line\nThird line\n");
    replay(fileContentUtil);
    List<TreeModification> treeModifications = toTreeModifications(fixReplacement1, fixReplacement2);
    assertThatList(treeModifications).onlyElement().asChangeFileContentModification().newContent().isEqualTo("First modified content line\n");
}
Also used : TreeModification(com.google.gerrit.server.edit.tree.TreeModification) FixReplacement(com.google.gerrit.reviewdb.client.FixReplacement) Range(com.google.gerrit.reviewdb.client.Comment.Range) Test(org.junit.Test)

Example 4 with Range

use of com.google.gerrit.reviewdb.client.Comment.Range in project gerrit by GerritCodeReview.

the class FixReplacementInterpreterTest method replacementsMustNotReferToNotExistingOffsetOfLastLine.

@Test
public void replacementsMustNotReferToNotExistingOffsetOfLastLine() throws Exception {
    FixReplacement fixReplacement = new FixReplacement(filePath1, new Range(3, 0, 3, 11), "modified");
    mockFileContent(filePath1, "First line\nSecond line\nThird line\n");
    replay(fileContentUtil);
    expectedException.expect(ResourceConflictException.class);
    toTreeModifications(fixReplacement);
}
Also used : FixReplacement(com.google.gerrit.reviewdb.client.FixReplacement) Range(com.google.gerrit.reviewdb.client.Comment.Range) Test(org.junit.Test)

Example 5 with Range

use of com.google.gerrit.reviewdb.client.Comment.Range in project gerrit by GerritCodeReview.

the class FixReplacementInterpreterTest method replacementsDoNotNeedToBeOrderedAccordingToRange.

@Test
public void replacementsDoNotNeedToBeOrderedAccordingToRange() throws Exception {
    FixReplacement fixReplacement1 = new FixReplacement(filePath1, new Range(1, 0, 2, 0), "1st modification\n");
    FixReplacement fixReplacement2 = new FixReplacement(filePath1, new Range(3, 0, 4, 0), "2nd modification\n");
    FixReplacement fixReplacement3 = new FixReplacement(filePath1, new Range(4, 0, 5, 0), "3rd modification\n");
    mockFileContent(filePath1, "First line\nSecond line\nThird line\nFourth line\nFifth line\n");
    replay(fileContentUtil);
    List<TreeModification> treeModifications = toTreeModifications(fixReplacement2, fixReplacement1, fixReplacement3);
    assertThatList(treeModifications).onlyElement().asChangeFileContentModification().newContent().isEqualTo("1st modification\nSecond line\n2nd modification\n3rd modification\nFifth line\n");
}
Also used : TreeModification(com.google.gerrit.server.edit.tree.TreeModification) FixReplacement(com.google.gerrit.reviewdb.client.FixReplacement) Range(com.google.gerrit.reviewdb.client.Comment.Range) Test(org.junit.Test)

Aggregations

Range (com.google.gerrit.reviewdb.client.Comment.Range)15 FixReplacement (com.google.gerrit.reviewdb.client.FixReplacement)15 Test (org.junit.Test)15 TreeModification (com.google.gerrit.server.edit.tree.TreeModification)10