public void testUpdateInvalid() throws Exception {
    RangeMarker marker = createMarker("01[]23456789");

    marker.getDocument().deleteString(1, 3);
    assertFalse(marker.isValid());

    marker.getDocument().insertString(2, "xxx");

    assertEquals(2, marker.getStartOffset());
    assertEquals(2, marker.getEndOffset());
    assertFalse(marker.isValid());
  }
  public void testDeleteRightPart2() throws Exception {
    RangeMarker marker = createMarker("0123456789", 2, 5);

    marker.getDocument().deleteString(4, 5);

    assertValidMarker(marker, 2, 4);
  }
  public void testReplaceRightPartInvalid() throws Exception {
    RangeMarker marker = createMarker("0123456789", 2, 5);

    marker.getDocument().replaceString(4, 6, "xxx");

    assertValidMarker(marker, 2, 4);
  }
  public void testInsertIntoStart() throws Exception {
    RangeMarker marker = createMarker("0123456789", 2, 5);

    marker.getDocument().insertString(2, "xxx");

    assertValidMarker(marker, 5, 8);
  }
  public void testDeleteFirstChar() throws Exception {
    RangeMarker marker = createMarker("0123456789", 0, 5);

    marker.getDocument().deleteString(0, 1);

    assertValidMarker(marker, 0, 4);
  }
  public void testDeleteRangeInside() throws Exception {
    RangeMarker marker = createMarker("0123456789", 1, 7);

    marker.getDocument().deleteString(2, 5);

    assertTrue(marker.isValid());
  }
  public void testReplaceRangeToSingleChar() throws Exception {
    RangeMarker marker = createMarker("0123456789", 1, 7);

    marker.getDocument().replaceString(2, 5, " ");

    assertTrue(marker.isValid());
  }
  public void testDeletePoint() throws Exception {
    RangeMarker marker = createMarker("0123456789", 2, 2);

    marker.getDocument().deleteString(1, 3);

    assertFalse(marker.isValid());
  }
Exemplo n.º 9
0
 public static FragmentContent fromRangeMarker(RangeMarker rangeMarker, Project project) {
   Document document = rangeMarker.getDocument();
   VirtualFile file = FileDocumentManager.getInstance().getFile(document);
   FileType type = FileTypeManager.getInstance().getFileTypeByFile(file);
   return new FragmentContent(
       new DocumentContent(project, document), TextRange.create(rangeMarker), project, type);
 }
Exemplo n.º 10
0
  public void testReplaceRightIncludingFirstChar() throws Exception {
    String s = "12345\n \n12345";
    RangeMarker marker = createMarker(s, 6, 8);

    marker.getDocument().replaceString(0, s.length(), s.replaceAll(" ", ""));

    assertValidMarker(marker, 6, 7);
  }
Exemplo n.º 11
0
  public void testNested3() {
    RangeMarker marker1 = createMarker("01[23]4567890123");
    DocumentEx document = (DocumentEx) marker1.getDocument();
    RangeMarker marker2 = document.createRangeMarker(9, 11);
    RangeMarker marker3 = document.createRangeMarker(1, 12);
    marker3.dispose();

    document.deleteString(marker1.getEndOffset(), marker2.getStartOffset());
  }
Exemplo n.º 12
0
  public void testDeleteBeforeStart() throws Exception {
    RangeMarker marker = createMarker("01[234]56789");

    marker.getDocument().deleteString(0, 1);

    assertEquals(1, marker.getStartOffset());
    assertEquals(4, marker.getEndOffset());
    assertTrue(marker.isValid());
  }
Exemplo n.º 13
0
  public void testInsertIntoEnd() throws Exception {
    RangeMarker marker = createMarker("0123456789", 2, 5);

    marker.getDocument().insertString(5, "xxx");

    assertEquals(2, marker.getStartOffset());
    assertEquals(5, marker.getEndOffset());
    assertTrue(marker.isValid());
  }
Exemplo n.º 14
0
  public void testInsertIntoStartExpandToLeft() throws Exception {
    RangeMarker marker = createMarker("0123456789", 2, 5);

    marker.setGreedyToLeft(true);

    marker.getDocument().insertString(2, "xxx");

    assertEquals(2, marker.getStartOffset());
    assertEquals(8, marker.getEndOffset());
    assertTrue(marker.isValid());
  }
Exemplo n.º 15
0
  public void testLL() {
    RangeMarker marker1 = createMarker("012345678901234567", 5, 6);
    DocumentEx document = (DocumentEx) marker1.getDocument();
    document.createRangeMarker(4, 5);
    document.createRangeMarker(6, 7);
    document.createRangeMarker(0, 4);
    document.deleteString(1, 2);

    document.createRangeMarker(0, 7);
    document.createRangeMarker(0, 7);
  }
Exemplo n.º 16
0
  public void testNestedAfter() {
    RangeMarker marker1 = createMarker("0[12345678]90123");
    Document document = marker1.getDocument();
    RangeMarker marker2 = document.createRangeMarker(2, 5);
    RangeMarker marker3 = document.createRangeMarker(3, 4);
    document.insertString(10, "x");

    assertEquals(1, marker1.getStartOffset());
    assertEquals(2, marker2.getStartOffset());
    assertEquals(3, marker3.getStartOffset());
  }
Exemplo n.º 17
0
 public void testBranched() {
   RangeMarker marker1 = createMarker("01234567890123456", 0, 1);
   DocumentEx document = (DocumentEx) marker1.getDocument();
   RangeMarker marker2 = document.createRangeMarker(2, 3);
   RangeMarker marker3 = document.createRangeMarker(4, 5);
   RangeMarker marker4 = document.createRangeMarker(6, 7);
   RangeMarker marker5 = document.createRangeMarker(8, 9);
   RangeMarker marker6 = document.createRangeMarker(10, 11);
   RangeMarker marker7 = document.createRangeMarker(12, 13);
   RangeMarker marker8 = document.createRangeMarker(14, 15);
   document.deleteString(1, 2);
 }
Exemplo n.º 18
0
 protected Document createCopy() {
   final Document originalDocument = myRangeMarker.getDocument();
   String textInRange =
       originalDocument
           .getCharsSequence()
           .subSequence(myRangeMarker.getStartOffset(), myRangeMarker.getEndOffset())
           .toString();
   final Document result = EditorFactory.getInstance().createDocument(textInRange);
   result.setReadOnly(!originalDocument.isWritable());
   result.putUserData(ORIGINAL_DOCUMENT, originalDocument);
   return result;
 }
Exemplo n.º 19
0
  public void testNoNegative() throws Exception {
    RangeMarker marker =
        createMarker(
            "package safd;\n\n[import javax.swing.JPanel;]\nimport java.util.ArrayList;\n\nclass T{}");

    marker
        .getDocument()
        .replaceString(
            15,
            15 + "import javax.swing.JPanel;\nimport java.util.ArrayList;".length(),
            "import java.util.ArrayList;");

    assertEquals(15, marker.getStartOffset());
  }
Exemplo n.º 20
0
 protected Document createOriginal() {
   return myRangeMarker.getDocument();
 }
Exemplo n.º 21
0
 public void testDevourMarkerWithDeletion() {
   RangeMarker marker1 = createMarker("012345[67890123456]7");
   DocumentEx document = (DocumentEx) marker1.getDocument();
   document.deleteString(1, document.getTextLength());
 }
Exemplo n.º 22
0
 public void testReplaceWholeRange() throws Exception {
   RangeMarker marker = createMarker("0123456789", 1, 7);
   marker.getDocument().replaceString(1, 7, "abc");
   assertValidMarker(marker, 1, 4);
 }
Exemplo n.º 23
0
  public void testReplacementWithOldTextOverlap() throws Exception {
    RangeMarker marker = createMarker("0123456789", 2, 5);

    marker.getDocument().replaceString(0, 10, "0123456789");
    assertValidMarker(marker, 2, 5);
  }
Exemplo n.º 24
0
  public void testDeleteJustBeforeStart() throws Exception {
    RangeMarker marker = createMarker("0123456789", 2, 5);

    marker.getDocument().deleteString(0, 2);
    assertValidMarker(marker, 0, 3);
  }
Exemplo n.º 25
0
  public void testDeleteExactRange() throws Exception {
    RangeMarker marker = createMarker("0123456789", 2, 5);

    marker.getDocument().deleteString(2, 5);
    assertValidMarker(marker, 2, 2);
  }