Package com.aptana.interactive_console.console.ui.internal

Examples of com.aptana.interactive_console.console.ui.internal.ScriptConsoleDocumentListener


    public void testConsoleListener() throws Exception {
        final Document doc = new Document();
        final List<String> commandsHandled = new ArrayList<String>();

        ScriptConsolePrompt prompt = new ScriptConsolePrompt(">>> ", "... ");
        ScriptConsoleDocumentListener listener = new ScriptConsoleDocumentListener(
                new IScriptConsoleViewer2ForDocumentListener() {

                    public IDocument getDocument() {
                        return doc;
                    }

                    public IConsoleStyleProvider getStyleProvider() {
                        return null;
                    }

                    public void revealEndOfDocument() {
                        //do nothing
                    }

                    public void setCaretOffset(int length, boolean async) {
                        //do nothing
                    }
                },

                new ICommandHandler() {

                    public void handleCommand(String userInput,
                            ICallback<Object, InterpreterResponse> onResponseReceived,
                            ICallback<Object, Tuple<String, String>> onContentsReceived) {
                        commandsHandled.add(userInput);
                        onResponseReceived.call(new InterpreterResponse("", "", false, false));
                    }
                },

                prompt, new ScriptConsoleHistory(), new ArrayList<IConsoleLineTracker>(), "",
                new PyAutoIndentStrategy());

        PyAutoIndentStrategy strategy = (PyAutoIndentStrategy) listener.getIndentStrategy();
        strategy.setIndentPrefs(new TestIndentPrefs(true, 4));
        listener.setDocument(doc);

        doc.replace(0, 0, ">>> class A:");
        doc.replace(doc.getLength(), 0, "\n");
        //Things happen in a thread now, so, we have to wait for it to happen...
        for (int i = 0; i < 50; i++) {
            //if we get at the expected condition, break our for.
            if (com.aptana.shared_core.string.StringUtils.format(">>> class A:%s>>>     ", listener.getDelimeter()).equals(doc.get())) {
                break;
            }
            synchronized (this) {
                wait(250);
            }
        }
        assertEquals(com.aptana.shared_core.string.StringUtils.format(">>> class A:%s>>>     ", listener.getDelimeter()), doc.get());
        doc.replace(doc.getLength(), 0, "def m1");
        doc.replace(doc.getLength(), 0, "(");
        assertEquals(com.aptana.shared_core.string.StringUtils.format(">>> class A:%s>>>     def m1(self):", listener.getDelimeter()), doc.get());

        listener.clear(false);
        assertEquals(">>> ", doc.get());
        doc.replace(doc.getLength(), 0, "c()");
        assertEquals(">>> c()", doc.get());
        doc.replace(doc.getLength() - 1, 0, ")");
        assertEquals(">>> c()", doc.get());
View Full Code Here

TOP

Related Classes of com.aptana.interactive_console.console.ui.internal.ScriptConsoleDocumentListener

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.