Search in sources :

Example 6 with TextDiff

use of com.google.startupos.common.Protos.TextDiff in project startup-os by google.

the class TextDifferencerTool method run.

void run() throws IOException {
    String leftFileContents = fileUtils.readFile(leftFile.get());
    String rightFileContents = fileUtils.readFile(rightFile.get());
    String diffString = GitRepo.getTextDiff(leftFile.get(), rightFile.get());
    TextDiff textDiff = textDifferencer.getTextDiff(leftFileContents, rightFileContents, diffString);
    if (printOutput.get()) {
        System.out.println(textDiff);
    }
}
Also used : TextDiff(com.google.startupos.common.Protos.TextDiff)

Example 7 with TextDiff

use of com.google.startupos.common.Protos.TextDiff in project startup-os by google.

the class TextDifferencerTest method testMixedChangesAtTheMiddle.

@Test
public void testMixedChangesAtTheMiddle() {
    String leftContents = "With Change.";
    String rightContents = "With a Change.";
    String diff = "@@ -1 +1 @@\n-With Change.\n+With a Change.";
    TextDiff expectedTextDiff = readTextDiff("MixedChangesAtTheMiddle_diff_prototxt.txt");
    assertEquals(expectedTextDiff, differencer.getTextDiff(leftContents, rightContents, diff));
}
Also used : TextDiff(com.google.startupos.common.Protos.TextDiff) Test(org.junit.Test)

Example 8 with TextDiff

use of com.google.startupos.common.Protos.TextDiff in project startup-os by google.

the class TextDifferencerTest method testOnlyDeletions.

@Test
public void testOnlyDeletions() {
    String leftContents = "Deletion.";
    String rightContents = "";
    String diff = "@@ -1 +0,0 @@\n-Deletion.";
    TextDiff expectedTextDiff = TextDiff.newBuilder().addLeftDiffLine(DiffLine.newBuilder().setText(leftContents).setType(ChangeType.DELETE).build()).addRightDiffLine(DiffLine.newBuilder().setText(rightContents).setType(ChangeType.LINE_PLACEHOLDER).build()).setLeftFileContents(leftContents).setRightFileContents(rightContents).build();
    assertEquals(expectedTextDiff, differencer.getTextDiff(leftContents, rightContents, diff));
}
Also used : TextDiff(com.google.startupos.common.Protos.TextDiff) Test(org.junit.Test)

Example 9 with TextDiff

use of com.google.startupos.common.Protos.TextDiff in project startup-os by google.

the class TextDifferencerTest method testOnlyNoChanges.

@Test
public void testOnlyNoChanges() {
    String contents = "No Change.";
    TextDiff expectedTextDiff = TextDiff.newBuilder().setLeftFileContents(contents).setRightFileContents(contents).build();
    assertEquals(expectedTextDiff, differencer.getTextDiff(contents, contents, ""));
}
Also used : TextDiff(com.google.startupos.common.Protos.TextDiff) Test(org.junit.Test)

Example 10 with TextDiff

use of com.google.startupos.common.Protos.TextDiff in project startup-os by google.

the class TextDifferencerTest method testMixedChangesAtTheEnd.

@Test
public void testMixedChangesAtTheEnd() {
    String leftContents = "Change at end.";
    String rightContents = "Change at end!";
    String diff = "@@ -1 +1 @@\n-Change at end.\n+Change at end!";
    TextDiff expectedTextDiff = readTextDiff("MixedChangesAtTheEnd_diff_prototxt.txt");
    assertEquals(expectedTextDiff, differencer.getTextDiff(leftContents, rightContents, diff));
}
Also used : TextDiff(com.google.startupos.common.Protos.TextDiff) Test(org.junit.Test)

Aggregations

TextDiff (com.google.startupos.common.Protos.TextDiff)11 Test (org.junit.Test)9 ChangeType (com.google.startupos.common.Protos.ChangeType)1 DiffLine (com.google.startupos.common.Protos.DiffLine)1 ArrayList (java.util.ArrayList)1