Java Code Examples for org.eclipse.jface.text.Document#getLength()

The following examples show how to use org.eclipse.jface.text.Document#getLength() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PyAutoIndentStrategyTest.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
public void testIndentingWithTab7() {
    strategy.setIndentPrefs(new TestIndentPrefs(true, 4));
    String str = "" +
            "class C:\n" +
            "    def m1(self):            \n" +
            "  print 'a'" +
            "";
    String expected = "" +
            "class C:\n" +
            "    def m1(self):            \n" +
            "print 'a'" +
            "";
    final Document doc = new Document(str);
    DocCmd docCmd = new DocCmd(doc.getLength() - "  print 'a'".length(), 0, "\t");
    strategy.customizeDocumentCommand(doc, docCmd);
    assertEquals("        ", docCmd.text); // a single tab should go to the correct indent
    assertEquals(expected, doc.get()); // the spaces after the indent should be removed
}
 
Example 2
Source File: PyAutoIndentStrategyTest.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
public void testIndentAfterRet2() {
    strategy.setIndentPrefs(new TestIndentPrefs(true, 4));
    String str = "" +
            "class Foo:\n" +
            "    def m1():\n" +
            "        for a in b:\n" +
            "            if a = 20:\n"
            +
            "                print 'foo'\n" +
            "        return 30\n" +
            "    \n" +
            "";
    final Document doc = new Document(str);
    DocCmd docCmd = new DocCmd(doc.getLength(), 0, "\t");
    strategy.customizeDocumentCommand(doc, docCmd);
    assertEquals("    ", docCmd.text);
}
 
Example 3
Source File: PyAutoIndentStrategyTest.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
public void testIndentAfterRet() {
    strategy.setIndentPrefs(new TestIndentPrefs(true, 4));
    String str = "" +
            "class Foo:\n" +
            "    def m1():\n" +
            "        for a in b:\n" +
            "            if a = 20:\n"
            +
            "                print 'foo'\n" +
            "        return 30\n" +
            "    " +
            "";
    final Document doc = new Document(str);
    DocCmd docCmd = new DocCmd(doc.getLength(), 0, "\n");
    strategy.customizeDocumentCommand(doc, docCmd);
    assertEquals("\n    ", docCmd.text);
}
 
Example 4
Source File: PyBackspaceTest.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
public void testBackspace10() throws Exception {
    Document doc = new Document("a = 10\n" +
            "    ");
    PySelection ps = new PySelection(doc, 0, doc.getLength(), 0);

    backspace.perform(ps);
    assertEquals("a = 10\n", doc.get());
}
 
Example 5
Source File: PyAutoIndentStrategyTest.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
public void testTabInComment() {
    strategy.setIndentPrefs(new TestIndentPrefs(true, 4));
    String str = "#comment" +
            "";
    final Document doc = new Document(str);
    DocCmd docCmd = new DocCmd(doc.getLength(), 0, "\t");
    strategy.customizeDocumentCommand(doc, docCmd);
    assertEquals("    ", docCmd.text); // a single tab should go to the correct indent

}
 
Example 6
Source File: PyAutoIndentStrategyTest.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
public void testNewLine11() {
    strategy.setIndentPrefs(new TestIndentPrefs(true, 4));
    String str = "" +
            "def fun():\n" +
            "    if True:\n" +
            "        passif False: 'foo'" +
            "";
    final Document doc = new Document(str);
    DocCmd docCmd = new DocCmd(doc.getLength() - "if False: 'foo'".length(), 0, "\n");
    strategy.customizeDocumentCommand(doc, docCmd);
    assertEquals("\n    ", docCmd.text);

}
 
Example 7
Source File: PyAutoIndentStrategyTest.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
public void testNewLine6a() {
    strategy.setIndentPrefs(new TestIndentPrefs(true, 4));
    String str = "" +
            "def getSpilledComps( *dummy ):\n" +
            "    return [self.component4]" + //dedent here
            "";
    final Document doc = new Document(str);
    DocCmd docCmd = new DocCmd(doc.getLength(), 0, "\n");
    strategy.customizeDocumentCommand(doc, docCmd);
    assertEquals("\n", docCmd.text);
}
 
Example 8
Source File: PyBackspaceTest.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
public void testBackspace12() throws Exception {
    Document doc = new Document("a = 10\n" +
            "      ");
    PySelection ps = new PySelection(doc, 0, doc.getLength(), 0);

    backspace.perform(ps);
    assertEquals("a = 10\n    ", doc.get());
}
 
Example 9
Source File: PyPeerLinkerTest.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
public void testLiteral3() throws Exception {
    Document doc = new Document("a");
    PySelection ps = new PySelection(doc, 0, 0, doc.getLength());

    assertTrue(peerLinker.perform(ps, '\'', null));
    assertEquals("'a'", doc.get());
    assertEquals(1, peerLinker.getLinkOffset());
    assertEquals(1, peerLinker.getLinkLen());
    assertEquals(3, peerLinker.getLinkExitPos());
}
 
Example 10
Source File: PyAutoIndentStrategyTest.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
public void testParens() {
    strategy.setIndentPrefs(new TestIndentPrefs(true, 4));
    String str = "isShown() #suite()" +
            "";
    final Document doc = new Document(str);
    DocCmd docCmd = new DocCmd(doc.getLength() - ") #suite()".length(), 0, ")");
    strategy.customizeDocumentCommand(doc, docCmd);
    assertEquals("", docCmd.text);
    assertEquals(9, docCmd.caretOffset);

}
 
Example 11
Source File: PyAutoIndentStrategyTest.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
public void testMaintainIndent() {
    strategy.setIndentPrefs(new TestIndentPrefs(true, 4));
    String str = "" +
            "def moo():\n" +
            "    if not 1:\n" +
            "        print 'foo'\n" +
            "    print 'bla'" +
            "";

    final Document doc = new Document(str);
    DocCmd docCmd = new DocCmd(doc.getLength() - "print 'bla'".length(), 0, "\n");
    strategy.customizeDocumentCommand(doc, docCmd);
    assertEquals("\n    ", docCmd.text);

}
 
Example 12
Source File: PyBackspaceTest.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
public void testBackspace8() throws Exception {
    Document doc = new Document("a = 10\r");
    PySelection ps = new PySelection(doc, 0, doc.getLength(), 0);

    backspace.perform(ps);
    assertEquals("a = 10", doc.get());
}
 
Example 13
Source File: PyAutoIndentStrategyTest.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
public void testNewLineAfterOpeningParWithOtherContents() {
    strategy.setIndentPrefs(new TestIndentPrefs(true, 4));
    String str = "" +
            "def m1(  self,";
    //        |<-- should indent here in this case, and not on the parenthesis
    final Document doc = new Document(str);
    DocCmd docCmd = new DocCmd(doc.getLength(), 0, "\n");
    strategy.customizeDocumentCommand(doc, docCmd);
    assertEquals("\n         ", docCmd.text);
}
 
Example 14
Source File: PyAutoIndentStrategyTest.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
public void testNewLine6() {
    strategy.setIndentPrefs(new TestIndentPrefs(true, 4));
    String str = "" +
            "for v in w:\n" +
            "    pass\n" + //dedent on pass
            "";
    final Document doc = new Document(str);
    DocCmd docCmd = new DocCmd(doc.getLength(), 0, "\n");
    strategy.customizeDocumentCommand(doc, docCmd);
    assertEquals("\n", docCmd.text);
}
 
Example 15
Source File: PyShiftLeftTest.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
public void testShiftLeft3() throws Exception {
    Document doc = new Document("   def a(aa):\n" +
            "        pass\n" +
            "    bb\n");
    PySelection ps = new PySelection(doc, 0, 3, doc.getLength() - 2 - 3);
    new PyShiftLeft().perform(ps, new TestIndentPrefs(true, 4));

    String expected = "def a(aa):\n" +
            "     pass\n" +
            " bb\n";
    assertEquals(expected, doc.get());
}
 
Example 16
Source File: PyCommentTest.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
public void testCommentWithDifferentCodingStd() throws Exception {
    std.spacesInStartComment = 1;

    Document doc = new Document(" a\r\n" +
            "b");
    PySelection ps = new PySelection(doc, 0, 0, doc.getLength());
    assertEquals(new Tuple<Integer, Integer>(0, 9), new PyComment(std).perform(ps));

    String expected = "#  a\r\n" +
            "# b";
    assertEquals(expected, doc.get());

}
 
Example 17
Source File: PyCommentTest.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
public void testComment4() throws Exception {
    Document doc = new Document("a\r\n" +
            "b");
    PySelection ps = new PySelection(doc, 0, 0, doc.getLength());
    assertEquals(new Tuple<Integer, Integer>(0, 6), new PyComment(std).perform(ps));

    String expected = "#a\r\n" +
            "#b";
    assertEquals(expected, doc.get());

}
 
Example 18
Source File: PyBackspaceTest.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
public void testBackspace9() throws Exception {
    Document doc = new Document("a = 10\r");
    PySelection ps = new PySelection(doc, 0, doc.getLength(), 0);

    backspace.perform(ps);
    assertEquals("a = 10", doc.get());
}
 
Example 19
Source File: PyUncommentTest.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
public void testUncommentToProperIndentation() throws Exception {
    std.spacesInStartComment = 1;
    //When uncommenting, we should move the code uncommented to a proper indentation.
    Document doc = new Document("# a\n" +
            "#b");
    PySelection ps = new PySelection(doc, 0, 0, doc.getLength());
    assertEquals(new Tuple<Integer, Integer>(0, 4), new PyUncomment(std).perform(ps));

    String expected = " a\n" +
            "b";
    assertEquals(expected, doc.get());
}
 
Example 20
Source File: PartitionCodeReaderTest.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
public void testPartitionCodeReaderUnread2() throws Exception {
    PartitionCodeReader reader = new PartitionCodeReader(IDocument.DEFAULT_CONTENT_TYPE);
    Document document = new Document("abcde");
    String category = setupDocument(document);

    document.addPosition(category, new TypedPosition(1, 1, "cat1")); //skip b
    document.addPosition(category, new TypedPosition(3, 1, "cat1")); //skip d

    reader.configureForwardReader(document, 0, document.getLength());
    FastStringBuffer buf = new FastStringBuffer(document.getLength());
    readAll(reader, buf);
    reader.unread(); //EOF
    reader.unread(); //e
    reader.unread(); //c
    readAll(reader, buf);
    reader.unread(); //EOF
    reader.unread(); //e
    reader.unread(); //c
    reader.unread(); //a
    readAll(reader, buf);
    reader.unread(); //EOF
    assertEquals(-1, reader.read());
    reader.unread(); //EOF
    reader.unread(); //e
    readAll(reader, buf);
    assertEquals("aceceacee", buf.toString());
}