Search in sources :

Example 51 with Edit

use of org.eclipse.jgit.diff.Edit in project gerrit by GerritCodeReview.

the class OneLineContentWithEOLTest method insertMultilineLineWithEOLInTheMiddle.

@Test
public void insertMultilineLineWithEOLInTheMiddle() throws Exception {
    FixResult fixResult = FixCalculatorVariousTest.calculateFixSingleReplacement("First line\n", 1, 5, 1, 5, "Abc\nDefgh\n");
    assertThat(fixResult).text().isEqualTo("FirstAbc\nDefgh\n line\n");
    assertThat(fixResult).edits().hasSize(1);
    Edit edit = fixResult.edits.get(0);
    assertThat(edit).isReplace(0, 1, 0, 3);
    assertThat(edit).internalEdits().onlyElement().isInsert(5, 5, 10);
}
Also used : FixResult(com.google.gerrit.server.fixes.FixCalculator.FixResult) Edit(org.eclipse.jgit.diff.Edit) Test(org.junit.Test)

Example 52 with Edit

use of org.eclipse.jgit.diff.Edit in project gerrit by GerritCodeReview.

the class OneLineContentWithEOLTest method replaceWithSingleLineWithEOLAtStart.

@Test
public void replaceWithSingleLineWithEOLAtStart() throws Exception {
    FixResult fixResult = FixCalculatorVariousTest.calculateFixSingleReplacement("First line\n", 1, 0, 1, 2, "Abc\n");
    assertThat(fixResult).text().isEqualTo("Abc\nrst line\n");
    assertThat(fixResult).edits().hasSize(1);
    Edit edit = fixResult.edits.get(0);
    assertThat(edit).isReplace(0, 1, 0, 2);
    assertThat(edit).internalEdits().onlyElement().isReplace(0, 2, 0, 4);
}
Also used : FixResult(com.google.gerrit.server.fixes.FixCalculator.FixResult) Edit(org.eclipse.jgit.diff.Edit) Test(org.junit.Test)

Example 53 with Edit

use of org.eclipse.jgit.diff.Edit in project gerrit by GerritCodeReview.

the class OneLineContentWithEOLTest method replaceMultilineLineWithEOLAtEnd.

@Test
public void replaceMultilineLineWithEOLAtEnd() throws Exception {
    FixResult fixResult = FixCalculatorVariousTest.calculateFixSingleReplacement("First line\n", 1, 8, 2, 0, "Abc\nDefgh\n");
    assertThat(fixResult).text().isEqualTo("First liAbc\nDefgh\n");
    assertThat(fixResult).edits().hasSize(1);
    Edit edit = fixResult.edits.get(0);
    assertThat(edit).isReplace(0, 1, 0, 2);
    assertThat(edit).internalEdits().onlyElement().isReplace(8, 3, 8, 10);
}
Also used : FixResult(com.google.gerrit.server.fixes.FixCalculator.FixResult) Edit(org.eclipse.jgit.diff.Edit) Test(org.junit.Test)

Example 54 with Edit

use of org.eclipse.jgit.diff.Edit in project gerrit by GerritCodeReview.

the class OneLineContentWithEOLTest method replaceMultilineLineNoEOLInTheMiddle.

@Test
public void replaceMultilineLineNoEOLInTheMiddle() throws Exception {
    FixResult fixResult = FixCalculatorVariousTest.calculateFixSingleReplacement("First line\n", 1, 3, 1, 5, "Abc\nDefgh");
    assertThat(fixResult).text().isEqualTo("FirAbc\nDefgh line\n");
    assertThat(fixResult).edits().hasSize(1);
    Edit edit = fixResult.edits.get(0);
    assertThat(edit).isReplace(0, 1, 0, 2);
    assertThat(edit).internalEdits().onlyElement().isReplace(3, 2, 3, 9);
}
Also used : FixResult(com.google.gerrit.server.fixes.FixCalculator.FixResult) Edit(org.eclipse.jgit.diff.Edit) Test(org.junit.Test)

Example 55 with Edit

use of org.eclipse.jgit.diff.Edit in project gerrit by GerritCodeReview.

the class OneLineContentWithEOLTest method replaceMultilineLineWithEOLAtStart.

@Test
public void replaceMultilineLineWithEOLAtStart() throws Exception {
    FixResult fixResult = FixCalculatorVariousTest.calculateFixSingleReplacement("First line\n", 1, 0, 1, 2, "Abc\nDefgh\n");
    assertThat(fixResult).text().isEqualTo("Abc\nDefgh\nrst line\n");
    assertThat(fixResult).edits().hasSize(1);
    Edit edit = fixResult.edits.get(0);
    assertThat(edit).isReplace(0, 1, 0, 3);
    assertThat(edit).internalEdits().onlyElement().isReplace(0, 2, 0, 10);
}
Also used : FixResult(com.google.gerrit.server.fixes.FixCalculator.FixResult) Edit(org.eclipse.jgit.diff.Edit) Test(org.junit.Test)

Aggregations

Edit (org.eclipse.jgit.diff.Edit)142 Test (org.junit.Test)117 FixResult (com.google.gerrit.server.fixes.FixCalculator.FixResult)112 ReplaceEdit (com.google.gerrit.jgit.diff.ReplaceEdit)9 ArrayList (java.util.ArrayList)5 RawText (org.eclipse.jgit.diff.RawText)5 Range (com.google.gerrit.entities.Comment.Range)4 FixReplacement (com.google.gerrit.entities.FixReplacement)4 Text (com.google.gerrit.server.patch.Text)4 EditList (org.eclipse.jgit.diff.EditList)4 PatchScript (com.google.gerrit.common.data.PatchScript)3 TaggedEdit (com.google.gerrit.server.patch.filediff.TaggedEdit)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 DiffFormatter (org.eclipse.jgit.diff.DiffFormatter)3 ReplaceEdit (org.eclipse.jgit.diff.ReplaceEdit)3 AbbreviatedObjectId (org.eclipse.jgit.lib.AbbreviatedObjectId)3 ObjectReader (org.eclipse.jgit.lib.ObjectReader)3 RevWalk (org.eclipse.jgit.revwalk.RevWalk)3 DiffPreferencesInfo (com.google.gerrit.extensions.client.DiffPreferencesInfo)2 SparseFileContent (com.google.gerrit.prettify.common.SparseFileContent)2