use of com.google.gerrit.entities.FixReplacement in project gerrit by GerritCodeReview.
the class FixReplacementInterpreterTest method replacementIsTranslatedToTreeModification.
@Test
public void replacementIsTranslatedToTreeModification() throws Exception {
FixReplacement fixReplacement = new FixReplacement(filePath1, new Range(1, 1, 3, 2), "Modified content");
mockFileContent(filePath1, "First line\nSecond line\nThird line\n");
CommitModification commitModification = toCommitModification(fixReplacement);
ImmutableList<TreeModification> treeModifications = commitModification.treeModifications();
assertThatList(treeModifications).onlyElement().asChangeFileContentModification().filePaths().containsExactly(filePath1);
assertThatList(treeModifications).onlyElement().asChangeFileContentModification().newContent().isEqualTo("FModified contentird line\n");
}
use of com.google.gerrit.entities.FixReplacement in project gerrit by GerritCodeReview.
the class FixCalculatorVariousTest method multipleChanges.
@Test
public void multipleChanges() throws Exception {
String str = "First line\nSecond line\nThird line\nFourth line\nFifth line\nSixth line" + "\nSeventh line\nEighth line\nNinth line\nTenth line\n";
Text content = new Text(str.getBytes(UTF_8));
FixReplacement multiLineReplace = new FixReplacement("path", new Range(1, 2, 3, 3), "AB\nC\nDEFG\nQ\n");
FixReplacement multiLineDelete = new FixReplacement("path", new Range(4, 8, 5, 8), "");
FixReplacement singleLineInsert = new FixReplacement("path", new Range(5, 10, 5, 10), "QWERTY");
FixReplacement singleLineReplace = new FixReplacement("path", new Range(7, 3, 7, 7), "XY");
FixReplacement multiLineInsert = new FixReplacement("path", new Range(8, 7, 8, 7), "KLMNO\nASDF");
FixReplacement singleLineDelete = new FixReplacement("path", new Range(10, 3, 10, 7), "");
FixResult result = FixCalculator.calculateFix(content, ImmutableList.of(multiLineReplace, multiLineDelete, singleLineInsert, singleLineReplace, multiLineInsert, singleLineDelete));
assertThat(result).text().isEqualTo("FiAB\n" + "C\n" + "DEFG\n" + "Q\n" + "rd line\n" + "Fourth lneQWERTY\n" + "Sixth line\n" + "SevXY line\n" + "Eighth KLMNO\n" + "ASDFline\n" + "Ninth line\n" + "Tenine\n");
assertThat(result).edits().hasSize(3);
assertThat(result).edits().element(0).isReplace(0, 5, 0, 6);
assertThat(result).edits().element(0).internalEdits().containsExactly(new Edit(2, 26, 2, 14), new Edit(42, 54, 30, 30), new Edit(56, 56, 32, 38));
assertThat(result).edits().element(1).isReplace(6, 2, 7, 3);
assertThat(result).edits().element(1).internalEdits().containsExactly(new Edit(3, 7, 3, 5), new Edit(20, 20, 18, 28));
assertThat(result).edits().element(2).isReplace(9, 1, 11, 1);
assertThat(result).edits().element(2).internalEdits().onlyElement().isDelete(3, 4, 3);
}
use of com.google.gerrit.entities.FixReplacement in project gerrit by GerritCodeReview.
the class FixCalculatorVariousTest method severalChangesInConsecutiveLines.
@Test
public void severalChangesInConsecutiveLines() throws Exception {
FixReplacement replace = new FixReplacement("path", new Range(2, 1, 2, 3), "ABC");
FixReplacement insert = new FixReplacement("path", new Range(3, 5, 3, 5), "DEFG");
FixReplacement delete = new FixReplacement("path", new Range(4, 7, 4, 9), "");
FixResult result = FixCalculator.calculateFix(multilineContent, ImmutableList.of(replace, insert, delete));
assertThat(result).text().isEqualTo("First line\nSABCond line\nThirdDEFG line\nFourth ne\nFifth line\n");
assertThat(result).edits().hasSize(1);
Edit edit = result.edits.get(0);
assertThat(edit).isReplace(1, 3, 1, 3);
assertThat(edit).internalEdits().hasSize(3);
assertThat(edit).internalEdits().element(0).isReplace(1, 2, 1, 3);
assertThat(edit).internalEdits().element(1).isInsert(17, 18, 4);
assertThat(edit).internalEdits().element(2).isDelete(30, 2, 35);
}
use of com.google.gerrit.entities.FixReplacement in project gerrit by GerritCodeReview.
the class FixCalculatorVariousTest method severalChangesInTheSameLineNonSorted.
@Test
public void severalChangesInTheSameLineNonSorted() throws Exception {
FixReplacement replace = new FixReplacement("path", new Range(2, 1, 2, 3), "ABC");
FixReplacement insert = new FixReplacement("path", new Range(2, 5, 2, 5), "DEFG");
FixReplacement delete = new FixReplacement("path", new Range(2, 7, 2, 9), "");
FixResult result = FixCalculator.calculateFix(multilineContent, ImmutableList.of(replace, delete, insert));
assertThat(result).text().isEqualTo("First line\nSABConDEFGd ne\nThird line\nFourth line\nFifth line\n");
assertThat(result).edits().hasSize(1);
Edit edit = result.edits.get(0);
assertThat(edit).isReplace(1, 1, 1, 1);
assertThat(edit).internalEdits().hasSize(3);
assertThat(edit).internalEdits().element(0).isReplace(1, 2, 1, 3);
assertThat(edit).internalEdits().element(1).isInsert(5, 6, 4);
assertThat(edit).internalEdits().element(2).isDelete(7, 2, 12);
}
Aggregations