Package com.aptana.shared_core.utils

Examples of com.aptana.shared_core.utils.DocCmd


                "    except RuntimeError:\n"
                +
                "        a = 29\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);
View Full Code Here


        String strDoc = "for i in []:\n" +
                "    msg=\"success at %s\" % i\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

                "    print a\n" +
                "except:\n" +
                "    pass\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 = "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

    }

    public void testAutoImportStr2() {
        strategy.setIndentPrefs(new TestIndentPrefs(false, 4, true));
        String doc = "from ooooimport";
        DocCmd docCmd = new DocCmd(doc.length() - "import".length(), 0, " ");
        strategy.customizeDocumentCommand(new Document(doc), docCmd);
        String expected = " ";
        assertEquals(expected, docCmd.text);
    }
View Full Code Here

    }

    public void testAutoImportStr3() {
        strategy.setIndentPrefs(new TestIndentPrefs(false, 4, true));
        String doc = "from oooo importFooo";
        DocCmd docCmd = new DocCmd(doc.length() - "Fooo".length(), 0, " ");
        strategy.customizeDocumentCommand(new Document(doc), docCmd);
        String expected = " ";
        assertEquals(expected, docCmd.text);
    }
View Full Code Here

    }

    public void testAutoImportStr() {
        strategy.setIndentPrefs(new TestIndentPrefs(false, 4, true));
        String doc = "from xxx";
        DocCmd docCmd = new DocCmd(doc.length(), 0, " ");
        strategy.customizeDocumentCommand(new Document(doc), docCmd);
        String expected = " import ";
        assertEquals(expected, docCmd.text);

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

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

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

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

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

        doc = "from xxx import yyy";
        docCmd = new DocCmd(8, 0, " ");
        strategy.customizeDocumentCommand(new Document(doc), docCmd);
        expected = " ";
        assertEquals(expected, docCmd.text);

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

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

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

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

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

        doc = "from xxx #import yyy";
        docCmd = new DocCmd(8, 0, " ");
        strategy.customizeDocumentCommand(new Document(doc), docCmd);
        expected = " import ";
        assertEquals(expected, docCmd.text);

    }
View Full Code Here

    }

    public void testStringAddition() {
        strategy.setIndentPrefs(new TestIndentPrefs(true, 4, true));
        String doc = "";
        DocCmd docCmd;
        String expected;

        doc = "var";
        docCmd = new DocCmd(0, 0, "'");
        strategy.customizeDocumentCommand(new Document(doc), docCmd);
        expected = "'"; //just a single one
        assertEquals(expected, docCmd.text);

        doc = "''";
        docCmd = new DocCmd(doc.length() - 1, 0, "'");
        strategy.customizeDocumentCommand(new Document(doc), docCmd);
        expected = ""; //just walk with the cursor
        assertEquals(expected, docCmd.text);

        doc = "''";
        docCmd = new DocCmd(0, 0, "'");
        strategy.customizeDocumentCommand(new Document(doc), docCmd);
        expected = "'"; //don't walk with the cursor and add so that the document becomes '''
        assertEquals(expected, docCmd.text);

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

        doc = "'"; //already opened
        docCmd = new DocCmd(doc.length(), 0, "'");
        strategy.customizeDocumentCommand(new Document(doc), docCmd);
        expected = "'";
        assertEquals(expected, docCmd.text);

        doc = "#"; //on comment should not close
        docCmd = new DocCmd(doc.length(), 0, "'");
        strategy.customizeDocumentCommand(new Document(doc), docCmd);
        expected = "'";
        assertEquals(expected, docCmd.text);

        doc = "'ueuouo"; //already opened
        docCmd = new DocCmd(doc.length(), 0, "'");
        strategy.customizeDocumentCommand(new Document(doc), docCmd);
        expected = "'";
        assertEquals(expected, docCmd.text);

        doc = "'ueuouo' and "; //all is properly balanced, so, auto close it.
        docCmd = new DocCmd(doc.length(), 0, "'");
        strategy.customizeDocumentCommand(new Document(doc), docCmd);
        expected = "''";
        assertEquals(expected, docCmd.text);

        doc = "'ueuouo'"; //already opened
        docCmd = new DocCmd(0, doc.length(), "'");
        Document document = new Document(doc);
        strategy.customizeDocumentCommand(document, docCmd);
        assertEquals("''", docCmd.text);

        doc = "ueuo\nuo";
        docCmd = new DocCmd(0, doc.length(), "\"");
        document = new Document(doc);
        strategy.customizeDocumentCommand(document, docCmd);
        assertEquals("\"\"", docCmd.text);

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

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

    }

    public void testCloseParens() {
        strategy.setIndentPrefs(new TestIndentPrefs(false, 4, true));
        String doc = "()";
        DocCmd docCmd = new DocCmd(doc.length() - 1, 0, "(");
        strategy.customizeDocumentCommand(new Document(doc), docCmd);
        String expected = "()";
        assertEquals(expected, docCmd.text);

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

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

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

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

    }
View Full Code Here

    }

    public void testNoCloseParens() {
        strategy.setIndentPrefs(new TestIndentPrefs(false, 4, true));
        String doc = "test";
        DocCmd docCmd = new DocCmd(0, 0, "(");
        strategy.customizeDocumentCommand(new Document(doc), docCmd);
        String expected = "(";
        assertEquals(expected, docCmd.text);

        doc = "[][]";
        docCmd = new DocCmd(2, 0, "[");
        strategy.customizeDocumentCommand(new Document(doc), docCmd);
        expected = "[";
        assertEquals(expected, docCmd.text);

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

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

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

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

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

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

        doc = "[]][]";
        docCmd = new DocCmd(2, 0, "[");
        strategy.customizeDocumentCommand(new Document(doc), docCmd);
        expected = "[";
        assertEquals(expected, docCmd.text);

        doc = "\n\n)";
        docCmd = new DocCmd(0, 0, "(");
        strategy.customizeDocumentCommand(new Document(doc), docCmd);
        expected = "(";
        assertEquals(expected, docCmd.text);
    }
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.