Ejemplo n.º 1
0
  @Test
  public void testLatestChangedRangeOfAddedTextAtEnd() {
    String oldContent = "HelloWorld";
    String newContent = "HelloWorldNEW";
    ChangedTextFile changedTextFile = new ChangedTextFile("/path", oldContent, newContent);
    ChangedRange changedRange = changedTextFile.getLatestChangedRange();

    String addedText =
        newContent.substring(changedRange.getFirstIndex(), changedRange.getExlusiveEndOfNew());
    String removedText =
        oldContent.substring(changedRange.getFirstIndex(), changedRange.getExlusiveEndOfOld());
    assertEquals("", removedText);
    assertEquals("NEW", addedText);
  }
Ejemplo n.º 2
0
  @Test
  public void testEarliestChangedRangeOfReplacedTextAtStart() {
    String oldContent = "OLDHelloWorld";
    String newContent = "NEWHelloWorld";
    ChangedTextFile changedTextFile = new ChangedTextFile("/path", oldContent, newContent);
    ChangedRange changedRange = changedTextFile.getEarliestChangedRange();

    String addedText =
        newContent.substring(changedRange.getFirstIndex(), changedRange.getExlusiveEndOfNew());
    String removedText =
        oldContent.substring(changedRange.getFirstIndex(), changedRange.getExlusiveEndOfOld());
    assertEquals("OLD", removedText);
    assertEquals("NEW", addedText);
  }
Ejemplo n.º 3
0
  @Test
  public void testLatestChangedRangeAddedTextAtTwoPossibleLocationsInMiddle() {
    String oldContent = "HelloWorld";
    String newContent = "HelloWoWorld";
    ChangedTextFile changedTextFile = new ChangedTextFile("/path", oldContent, newContent);
    ChangedRange changedRange = changedTextFile.getLatestChangedRange();

    String addedText =
        newContent.substring(changedRange.getFirstIndex(), changedRange.getExlusiveEndOfNew());
    String removedText =
        oldContent.substring(changedRange.getFirstIndex(), changedRange.getExlusiveEndOfOld());
    assertEquals("", removedText);
    assertEquals("Wo", addedText);
    assertEquals(7, changedRange.getFirstIndex());
  }