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