Package com.aptana.shared_core.utils

Examples of com.aptana.shared_core.utils.DocCmd


    public void testNoAutoSelf3() {
        TestIndentPrefs testIndentPrefs = new TestIndentPrefs(false, 4, true);
        strategy.setIndentPrefs(testIndentPrefs);
        String doc = null;
        DocCmd docCmd = null;
        String expected = null;

        doc = "def testNotifyTwice(self):\n" +
                "   class Foo(Subject):\n" +
                "       pass\n" +
                "\n"
                +
                "   class Foo(Foo):\n" +
                "       pass\n" +
                "\n" +
                "   pool = Pool()\n" +
                "\n" +
                "   def OnAdd" +
                "";

        docCmd = new DocCmd(doc.length(), 0, "(");
        strategy.customizeDocumentCommand(new Document(doc), docCmd);
        expected = "():";
        assertEquals(expected, docCmd.text);
    }
View Full Code Here


    public void testNoAutoSelf4() {
        TestIndentPrefs testIndentPrefs = new TestIndentPrefs(false, 4, true);
        strategy.setIndentPrefs(testIndentPrefs);
        String doc = null;
        DocCmd docCmd = null;
        String expected = null;

        doc = "if True:\n" +
                "    def foo" +
                "";

        docCmd = new DocCmd(doc.length(), 0, "(");
        strategy.customizeDocumentCommand(new Document(doc), docCmd);
        expected = "():";
        assertEquals(expected, docCmd.text);
    }
View Full Code Here

     * @see PyAutoIndentStrategy
     */
    public void testAutoPar() {
        strategy.setIndentPrefs(new TestIndentPrefs(false, 4, true));
        String doc = "class c";
        DocCmd docCmd = new DocCmd(doc.length(), 0, "(");
        strategy.customizeDocumentCommand(new Document(doc), docCmd);
        String expected = "():";
        assertEquals(expected, docCmd.text);

        doc = "class c:\n" +
                "    def met";
        docCmd = new DocCmd(doc.length(), 0, "(");
        strategy.customizeDocumentCommand(new Document(doc), docCmd);
        expected = "(self):";
        assertEquals(expected, docCmd.text);

        //same as above, but with tabs
        doc = "class c:\n" +
                "\tdef met";
        docCmd = new DocCmd(doc.length(), 0, "(");
        strategy.customizeDocumentCommand(new Document(doc), docCmd);
        expected = "(self):";
        assertEquals(expected, docCmd.text);

        doc = "class c(object): #";
        docCmd = new DocCmd(doc.length(), 0, "(");
        strategy.customizeDocumentCommand(new Document(doc), docCmd);
        expected = "("; //in comment
        assertEquals(expected, docCmd.text);

        doc = "def a";
        docCmd = new DocCmd(doc.length(), 0, "(");
        strategy.customizeDocumentCommand(new Document(doc), docCmd);
        expected = "():";
        assertEquals(expected, docCmd.text);

        doc = "a";
        docCmd = new DocCmd(doc.length(), 0, "(");
        strategy.customizeDocumentCommand(new Document(doc), docCmd);
        expected = "()";
        assertEquals(expected, docCmd.text);

        doc = "a()";
        docCmd = new DocCmd(doc.length() - 1, 0, "(");
        strategy.customizeDocumentCommand(new Document(doc), docCmd);
        expected = "()";
        assertEquals(expected, docCmd.text);

        // test very simple ':' detection
        doc = "def something():";
        docCmd = new DocCmd(doc.length() - 1, 0, ":");
        strategy.customizeDocumentCommand(new Document(doc), docCmd);
        expected = "";
        assertEquals(expected, docCmd.text);
        assertEquals(15, docCmd.offset);

        // test inputting ':' when you already have a ':', like at the end of a function declaraction
        doc = "class c:\n" +
                "    def __init__(self):";
        docCmd = new DocCmd(doc.length() - 1, 0, ":");
        strategy.customizeDocumentCommand(new Document(doc), docCmd);
        expected = "";
        assertEquals(expected, docCmd.text);
        assertEquals(32, docCmd.caretOffset);

        // test inputting ':' at the end of a document
        doc = "class c:\n" +
                "    def __init__(self)";
        docCmd = new DocCmd(doc.length(), 0, ":");
        strategy.customizeDocumentCommand(new Document(doc), docCmd);
        expected = ":";
        assertEquals(expected, docCmd.text);
        assertEquals(31, docCmd.offset);

        // test same as above, but with a comment
        doc = "class c:\n" +
                "    def __init__(self): # comment";
        docCmd = new DocCmd(doc.length() - 11, 0, ":");
        strategy.customizeDocumentCommand(new Document(doc), docCmd);
        expected = "";
        assertEquals(expected, docCmd.text);
        assertEquals(32, docCmd.caretOffset);

        // test inputting ')' at the end of a document
        doc = "class c:\n" +
                "    def __init__(self)";
        docCmd = new DocCmd(doc.length(), 0, ")");
        strategy.customizeDocumentCommand(new Document(doc), docCmd);
        expected = ")";
        assertEquals(expected, docCmd.text);
        assertEquals(-1, docCmd.caretOffset);

        // test inputting ')' at the end of a document when it should replace a ')'
        doc = "class c:\n" +
                "    def __init__(self)";
        docCmd = new DocCmd(doc.length() - 1, 0, ")");
        strategy.customizeDocumentCommand(new Document(doc), docCmd);
        expected = "";
        assertEquals(expected, docCmd.text);
        assertEquals(31, docCmd.caretOffset);

        // test inputting ')' in the middle of the document
        doc = "def __init__(self):\n" +
                "   pass";
        docCmd = new DocCmd(17, 0, ")");
        strategy.customizeDocumentCommand(new Document(doc), docCmd);
        expected = "";
        assertEquals(expected, docCmd.text);
        assertEquals(18, docCmd.caretOffset);

        // check very simple braces insertion
        doc = "()";
        docCmd = new DocCmd(1, 0, ")");
        strategy.customizeDocumentCommand(new Document(doc), docCmd);
        expected = "";
        assertEquals(expected, docCmd.text);
        assertEquals(2, docCmd.caretOffset);

        // check simple braces insertion not at end of document
        doc = "() ";
        docCmd = new DocCmd(1, 0, ")");
        strategy.customizeDocumentCommand(new Document(doc), docCmd);
        expected = "";
        assertEquals(expected, docCmd.text);
        assertEquals(2, docCmd.caretOffset);

        // check insertion that should happen even being just before a ')'
        doc = "(() ";
        docCmd = new DocCmd(2, 0, ")");
        strategy.customizeDocumentCommand(new Document(doc), docCmd);
        expected = ")";
        assertEquals(expected, docCmd.text);
        assertEquals(-1, docCmd.caretOffset);

        // check same stuff for brackets
        // check simple braces insertion not at end of document
        doc = "[] ";
        docCmd = new DocCmd(1, 0, "]");
        strategy.customizeDocumentCommand(new Document(doc), docCmd);
        expected = "";
        assertEquals(expected, docCmd.text);
        assertEquals(2, docCmd.caretOffset);

        // two different kinds of braces next to each other
        doc = "([)";
        docCmd = new DocCmd(2, 0, "]");
        strategy.customizeDocumentCommand(new Document(doc), docCmd);
        expected = "]";
        assertEquals(expected, docCmd.text);
        assertEquals(-1, docCmd.caretOffset);
    }
View Full Code Here

    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);

    }
View Full Code Here

        strategy.setIndentPrefs(new TestIndentPrefs(true, 4));
        String str = "isShown() #suite()'" +
                "";
        final Document doc = new Document(str);
        int offset = doc.getLength() - ") #suite()'".length();
        DocCmd docCmd = new DocCmd(offset, 0, ")");
        strategy.customizeDocumentCommand(doc, docCmd);
        assertEquals("", docCmd.text);
        assertEquals(offset + 1, docCmd.caretOffset);

    }
View Full Code Here

    public void testParens3() {
        strategy.setIndentPrefs(new TestIndentPrefs(true, 4));
        String str = "assert_('\\\\' in txt) a()";
        final Document doc = new Document(str);
        int offset = doc.getLength() - ")".length();
        DocCmd docCmd = new DocCmd(offset, 0, ")");
        strategy.customizeDocumentCommand(doc, docCmd);
        assertEquals("", docCmd.text);
        assertEquals(offset + 1, docCmd.caretOffset);
    }
View Full Code Here

        strategy.setIndentPrefs(new TestIndentPrefs(true, 4, true));
        String strDoc = "if foo:\n" +
                "    print a\n" +
                "    else";
        int initialOffset = strDoc.length();
        DocCmd docCmd = new DocCmd(initialOffset, 0, ":");
        Document doc = new Document(strDoc);
        strategy.customizeDocumentCommand(doc, docCmd);
        String expected = ":";
        assertEquals(docCmd.offset, initialOffset - 4);
        assertEquals(expected, docCmd.text);
        assertEquals("if foo:\n" +
                "    print a\n" +
                "else", doc.get());

        //second part of test - should not dedent
        strategy.setIndentPrefs(new TestIndentPrefs(true, 4, true));
        strDoc = "if foo:\n" +
                "    if somethingElse:" +
                "        print a\n" +
                "    else";
        initialOffset = strDoc.length();
        docCmd = new DocCmd(initialOffset, 0, ":");
        doc = new Document(strDoc);
        strategy.customizeDocumentCommand(doc, docCmd);
        expected = ":";
        assertEquals(expected, docCmd.text);
        assertEquals(docCmd.offset, initialOffset);
View Full Code Here

                "    print a\n" +
                "except RuntimeError:\n" +
                "    a = 20\n" +
                "    else";
        int initialOffset = strDoc.length();
        DocCmd docCmd = new DocCmd(initialOffset, 0, ":");
        Document doc = new Document(strDoc);
        strategy.customizeDocumentCommand(doc, docCmd);
        String expected = ":";
        assertEquals(docCmd.offset, initialOffset - 4);
        assertEquals(expected, docCmd.text);
View Full Code Here

        strategy.setIndentPrefs(new TestIndentPrefs(true, 4, true));
        String strDoc = "try:\n" +
                "    print a\n" +
                "    except";
        int initialOffset = strDoc.length();
        DocCmd docCmd = new DocCmd(initialOffset, 0, ":");
        Document doc = new Document(strDoc);
        strategy.customizeDocumentCommand(doc, docCmd);
        String expected = ":";
        assertEquals(docCmd.offset, initialOffset - 4);
        assertEquals(expected, docCmd.text);
        assertEquals("try:\n" +
                "    print a\n" +
                "except", doc.get());

        //second part of test - should also dedent
        strategy.setIndentPrefs(new TestIndentPrefs(true, 4, true));
        strDoc = "try:\n" +
                "    if somethingElse:" +
                "        print a\n" +
                "    except";
        initialOffset = strDoc.length();
        docCmd = new DocCmd(initialOffset, 0, ":");
        doc = new Document(strDoc);
        strategy.customizeDocumentCommand(doc, docCmd);
        expected = ":";
        assertEquals(expected, docCmd.text);
        assertEquals(docCmd.offset, initialOffset - 4);
View Full Code Here

        strategy.setIndentPrefs(new TestIndentPrefs(true, 4, true));
        String strDoc = "if foo:\n" +
                "    print a\n" +
                "    elif";
        int initialOffset = strDoc.length();
        DocCmd docCmd = new DocCmd(initialOffset, 0, " ");
        Document doc = new Document(strDoc);
        strategy.customizeDocumentCommand(doc, docCmd);
        String expected = " ";
        assertEquals(docCmd.offset, initialOffset - 4);
        assertEquals(expected, docCmd.text);
        assertEquals("if foo:\n" +
                "    print a\n" +
                "elif", doc.get());

        //second part of test - should not dedent
        strategy.setIndentPrefs(new TestIndentPrefs(true, 4, true));
        strDoc = "if foo:\n" +
                "    if somethingElse:" +
                "        print a\n" +
                "    elif";
        initialOffset = strDoc.length();
        docCmd = new DocCmd(initialOffset, 0, " ");
        doc = new Document(strDoc);
        strategy.customizeDocumentCommand(doc, docCmd);
        expected = " ";
        assertEquals(expected, docCmd.text);
        assertEquals(docCmd.offset, initialOffset);
View Full Code Here

TOP

Related Classes of com.aptana.shared_core.utils.DocCmd

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.