Search in sources :

Example 1 with Range

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

the class FixCalculatorVariousTest method severalChangesInNonConsecutiveLines.

@Test
public void severalChangesInNonConsecutiveLines() throws Exception {
    FixReplacement replace = new FixReplacement("path", new Range(1, 1, 1, 3), "ABC");
    FixReplacement insert = new FixReplacement("path", new Range(3, 5, 3, 5), "DEFG");
    FixReplacement delete = new FixReplacement("path", new Range(5, 9, 6, 0), "");
    FixResult result = FixCalculator.calculateFix(multilineContent, ImmutableList.of(replace, insert, delete));
    assertThat(result).text().isEqualTo("FABCst line\nSecond line\nThirdDEFG line\nFourth line\nFifth lin");
    assertThat(result).edits().hasSize(3);
    assertThat(result).edits().element(0).isReplace(0, 1, 0, 1);
    assertThat(result).edits().element(0).internalEdits().onlyElement().isReplace(1, 2, 1, 3);
    assertThat(result).edits().element(1).isReplace(2, 1, 2, 1);
    assertThat(result).edits().element(1).internalEdits().onlyElement().isInsert(5, 5, 4);
    assertThat(result).edits().element(2).isReplace(4, 1, 4, 1);
    assertThat(result).edits().element(2).internalEdits().onlyElement().isDelete(9, 2, 9);
}
Also used : FixResult(com.google.gerrit.server.fixes.FixCalculator.FixResult) FixReplacement(com.google.gerrit.entities.FixReplacement) Range(com.google.gerrit.entities.Comment.Range) Test(org.junit.Test)

Example 2 with Range

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

the class FixCalculatorVariousTest method changesMayTouch.

@Test
public void changesMayTouch() throws Exception {
    FixReplacement firstReplace = new FixReplacement("path", new Range(1, 6, 2, 7), "modified ");
    FixReplacement consecutiveReplace = new FixReplacement("path", new Range(2, 7, 3, 5), "content");
    FixResult result = FixCalculator.calculateFix(multilineContent, ImmutableList.of(firstReplace, consecutiveReplace));
    assertThat(result).text().isEqualTo("First modified content line\nFourth line\nFifth line\n");
    assertThat(result).edits().hasSize(1);
    Edit edit = result.edits.get(0);
    assertThat(edit).isReplace(0, 3, 0, 1);
    // The current code creates two inline edits even though only one would be necessary. It
    // shouldn't make a visual difference to the user and hence we can ignore this.
    assertThat(edit).internalEdits().hasSize(2);
    assertThat(edit).internalEdits().element(0).isReplace(6, 12, 6, 9);
    assertThat(edit).internalEdits().element(1).isReplace(18, 10, 15, 7);
}
Also used : FixResult(com.google.gerrit.server.fixes.FixCalculator.FixResult) Edit(org.eclipse.jgit.diff.Edit) FixReplacement(com.google.gerrit.entities.FixReplacement) Range(com.google.gerrit.entities.Comment.Range) Test(org.junit.Test)

Example 3 with Range

use of com.google.gerrit.entities.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");
    CommitModification commitModification = toCommitModification(fixReplacement, fixReplacement3, fixReplacement2);
    List<TreeModification> sortedTreeModifications = getSortedCopy(commitModification.treeModifications());
    assertThatList(sortedTreeModifications).element(0).asChangeFileContentModification().filePaths().containsExactly(filePath1);
    assertThatList(sortedTreeModifications).element(0).asChangeFileContentModification().newContent().startsWith("First");
    assertThatList(sortedTreeModifications).element(1).asChangeFileContentModification().filePaths().containsExactly(filePath2);
    assertThatList(sortedTreeModifications).element(1).asChangeFileContentModification().newContent().startsWith("1st");
}
Also used : CommitModification(com.google.gerrit.server.edit.CommitModification) TreeModification(com.google.gerrit.server.edit.tree.TreeModification) FixReplacement(com.google.gerrit.entities.FixReplacement) Range(com.google.gerrit.entities.Comment.Range) Test(org.junit.Test)

Example 4 with Range

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

the class FixReplacementInterpreter method shiftRangesBy.

private static FixReplacement shiftRangesBy(FixReplacement fixReplacement, int shiftedAmount) {
    Range adjustedRange = new Range(fixReplacement.range);
    adjustedRange.startLine += shiftedAmount;
    adjustedRange.endLine += shiftedAmount;
    return new FixReplacement(fixReplacement.path, adjustedRange, fixReplacement.replacement);
}
Also used : Range(com.google.gerrit.entities.Comment.Range) FixReplacement(com.google.gerrit.entities.FixReplacement)

Example 5 with Range

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

the class FixReplacementInterpreterTest method replacementsCanModifySeveralFilesInAnyOrder.

@Test
public void replacementsCanModifySeveralFilesInAnyOrder() throws Exception {
    FixReplacement fixReplacement1 = new FixReplacement(filePath1, new Range(1, 1, 3, 2), "Modified content");
    mockFileContent(filePath1, "First line\nSecond line\nThird line\n");
    FixReplacement fixReplacement2 = new FixReplacement(filePath2, new Range(2, 0, 3, 0), "First modification\n");
    FixReplacement fixReplacement3 = new FixReplacement(filePath2, new Range(3, 0, 4, 0), "Second modification\n");
    mockFileContent(filePath2, "1st line\n2nd line\n3rd line\n");
    CommitModification commitModification = toCommitModification(fixReplacement3, fixReplacement1, fixReplacement2);
    List<TreeModification> sortedTreeModifications = getSortedCopy(commitModification.treeModifications());
    assertThatList(sortedTreeModifications).element(0).asChangeFileContentModification().newContent().isEqualTo("FModified contentird line\n");
    assertThatList(sortedTreeModifications).element(1).asChangeFileContentModification().newContent().isEqualTo("1st line\nFirst modification\nSecond modification\n");
}
Also used : CommitModification(com.google.gerrit.server.edit.CommitModification) TreeModification(com.google.gerrit.server.edit.tree.TreeModification) FixReplacement(com.google.gerrit.entities.FixReplacement) Range(com.google.gerrit.entities.Comment.Range) Test(org.junit.Test)

Aggregations

Range (com.google.gerrit.entities.Comment.Range)9 FixReplacement (com.google.gerrit.entities.FixReplacement)9 Test (org.junit.Test)8 FixResult (com.google.gerrit.server.fixes.FixCalculator.FixResult)5 Edit (org.eclipse.jgit.diff.Edit)4 CommitModification (com.google.gerrit.server.edit.CommitModification)3 TreeModification (com.google.gerrit.server.edit.tree.TreeModification)3 Text (com.google.gerrit.server.patch.Text)1