use of com.google.gerrit.server.fixes.FixCalculator.FixResult 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);
}
use of com.google.gerrit.server.fixes.FixCalculator.FixResult 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);
}
use of com.google.gerrit.server.fixes.FixCalculator.FixResult in project gerrit by GerritCodeReview.
the class EmptyContentTest method insertMultilineNoEOL.
@Test
public void insertMultilineNoEOL() throws Exception {
FixResult fixResult = FixCalculatorVariousTest.calculateFixSingleReplacement("", 1, 0, 1, 0, "Abc\nDEFGH");
assertThat(fixResult).text().isEqualTo("Abc\nDEFGH");
assertThat(fixResult).edits().onlyElement();
Edit edit = fixResult.edits.get(0);
assertThat(edit).isInsert(0, 0, 2);
assertThat(edit).internalEdits().onlyElement().isInsert(0, 0, 9);
}
use of com.google.gerrit.server.fixes.FixCalculator.FixResult in project gerrit by GerritCodeReview.
the class EmptyContentTest method insertSingleLineNoEOL.
@Test
public void insertSingleLineNoEOL() throws Exception {
FixResult fixResult = FixCalculatorVariousTest.calculateFixSingleReplacement("", 1, 0, 1, 0, "Abc");
assertThat(fixResult).text().isEqualTo("Abc");
assertThat(fixResult).edits().onlyElement();
Edit edit = fixResult.edits.get(0);
assertThat(edit).isInsert(0, 0, 1);
assertThat(edit).internalEdits().onlyElement().isInsert(0, 0, 3);
}
use of com.google.gerrit.server.fixes.FixCalculator.FixResult in project gerrit by GerritCodeReview.
the class MultilineContentNoEOLTest method deleteAtStart.
@Test
public void deleteAtStart() throws Exception {
FixResult fixResult = FixCalculatorVariousTest.calculateFixSingleReplacement("First line\nSecond line\nThird line", 1, 0, 1, 4, "");
assertThat(fixResult).text().isEqualTo("t line\nSecond line\nThird line");
assertThat(fixResult).edits().hasSize(1);
Edit edit = fixResult.edits.get(0);
assertThat(edit).isReplace(0, 1, 0, 1);
assertThat(edit).internalEdits().onlyElement().isDelete(0, 4, 0);
}