⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pythoncompletionwithoutbuiltinstest.java

📁 Python Development Environment (Python IDE plugin for Eclipse). Features editor, code completion, re
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        PyCalltipsContextInformation contextInformation = (PyCalltipsContextInformation) prop.getContextInformation();
        assertEquals("a, b", contextInformation.getContextDisplayString());
        assertEquals("a, b", contextInformation.getInformationDisplayString());
        
        Document doc = new Document(s);
        prop.apply(doc);
        String expected = StringUtils.format(original, "a, b");    
        assertEquals(expected, doc.get());
    }
    
    public void testRegularClass() throws Exception {
        String s;
        s = "" +
        "class Fooooo:\n" +
        "    def __init__(self, a, b):pass\n\n" +
        "Fooo\n";
        ICompletionProposal[] proposals = requestCompl(s, s.length()-1, -1, new String[] {});
        assertEquals(1, proposals.length); 
        ICompletionProposal p = proposals[0];
        assertEquals("Fooooo", p.getDisplayString());
    }
    
    public void testSelfCase() throws Exception {
        String s;
        s = "" +
        "class Foo:\n" +
        "    def __init__(self, a, b):pass\n\n" +
        "Foo.__init__\n"; //we should only strip the self if we're in an instance (which is not the case)
        ICompletionProposal[] proposals = requestCompl(s, s.length()-1, -1, new String[] {});
        assertEquals(1, proposals.length); 
        ICompletionProposal p = proposals[0];
        assertEquals("__init__(self, a, b)", p.getDisplayString());
    }
    
    public void testDuplicate() throws Exception {
        String s = 
            "class Foo(object):\n" +
            "    def __init__(self):\n" +
            "        self.attribute = 1\n" +
            "        self.attribute2 = 2";
        
        ICompletionProposal[] proposals = requestCompl(s, s.length()-"ute2 = 2".length(), 1, new String[] {"attribute"});
        assertEquals(1, proposals.length); 
    }
    
    public void testDuplicate2() throws Exception {
        String s = 
            "class Bar(object):\n" +
            "    def __init__(self):\n" +
            "        foobar = 10\n" +
            "        foofoo = 20";
        //locals work because it will only get the locals that are before the cursor line
        ICompletionProposal[] proposals = requestCompl(s, s.length()-"foo = 20".length(), 1, new String[] {"foobar"});
        assertEquals(1, proposals.length); 
    }
    
    public void testNoCompletionsForContext() throws Exception {
        String s = 
            "class Foo(object):\n" +
            "    pass\n" +
            "class F(object):\n" +
            "    pass";
        //we don't want completions when we're declaring a class
        ICompletionProposal[] proposals = requestCompl(s, s.length()-"(object):\n    pass".length(), 0, new String[] {});
        assertEquals(0, proposals.length); 
    }
    
    public void testClassmethod() throws Exception {
        String s0 = 
            "class Foo:\n" +
            "    @classmethod\n" +
            "    def method1(cls, a, b):\n" +
            "        pass\n" +
            "    \n" +
            "Foo.met%s";
        
        String s = StringUtils.format(s0, "");
        ICompletionProposal[] proposals = requestCompl(s, s.length(), -1, new String[] {});
        assertEquals(1, proposals.length); 
        PyCompletionProposal p = (PyCompletionProposal) proposals[0];
        assertEquals("method1(a, b)", p.getDisplayString());
        
        
        Document document = new Document(s);
        p.apply(document);
        assertEquals(StringUtils.format(s0, "hod1(a, b)"), document.get());
    }
    
    public void testClassmethod2() throws Exception {
        String s0 = 
            "class Foo:\n" +
            "    @classmethod\n" +
            "    def method1(cls, a, b):\n" +
            "        cls.m%s";
        
        String s = StringUtils.format(s0, "");
        ICompletionProposal[] proposals = requestCompl(s, s.length(), -1, new String[] {});
        assertEquals(1, proposals.length); 
        PyCompletionProposal p = (PyCompletionProposal) proposals[0];
        assertEquals("method1(a, b)", p.getDisplayString());
        
        
        Document document = new Document(s);
        p.apply(document);
        assertEquals(StringUtils.format(s0, "ethod1(a, b)"), document.get());
    }
    
    public void testClassmethod3() throws Exception {
        String s0 = 
            "class Foo:\n" +
            "    def __init__(self):\n" +
            "        self.myvar = 10\n" +
            "\n" +
            "    def method3(self, a, b):\n" +
            "        pass\n" +
            "\n" +
            "    myvar3=10\n" +
            "    @classmethod\n" +
            "    def method2(cls, a, b):\n" +
            "        cls.myvar2 = 20\n" +
            "\n" +
            "    @classmethod\n" +
            "    def method1(cls, a, b):\n" +
            "        cls.m%s";
        
        String s = StringUtils.format(s0, "");
        ICompletionProposal[] proposals = requestCompl(s, s.length(), -1, new String[] {});
        assertEquals(5, proposals.length); 
        assertContains("method1(a, b)", proposals);
        assertContains("method2(a, b)", proposals);
        assertContains("method3(self, a, b)", proposals);
        assertContains("myvar2", proposals);
        assertContains("myvar3", proposals);
    }
    
    
    public void testClassmethod4() throws Exception {
        String s0 = 
            "from extendable.classmet.mod1 import Foo\n" +
            "Foo.Class%s";
        
        String s = StringUtils.format(s0, "");
        ICompletionProposal[] proposals = requestCompl(s, s.length(), -1, new String[] {});
        assertEquals(1, proposals.length); 
        PyCompletionProposal p = (PyCompletionProposal) proposals[0];
        assertEquals("ClassMet()", p.getDisplayString());
        
        
        Document document = new Document(s);
        p.apply(document);
        assertEquals(StringUtils.format(s0, "Met()"), document.get());
    }
    
    public void testRecursion() throws Exception {
        String s = 
            "import testrec4\n" +
            "testrec4.url_for.";
        ICompletionProposal[] proposals = requestCompl(s, s.length(), 1, new String[] {"m1(self)"});
        assertEquals(1, proposals.length); 
    }
    
    public void testGlobal() throws Exception {
        String s = 
            "class Log:\n" +
            "    def method1(self):\n" +
            "        pass\n" +
            "    \n" +
            "def main():\n" +
            "    global logger\n" +
            "    logger = Log()\n" +
            "    logger.method1()\n" +
            "    \n" +
            "def otherFunction():\n" +
            "    logger.";
        ICompletionProposal[] proposals = requestCompl(s, s.length(), 1, new String[] {"method1()"});
        assertEquals(1, proposals.length); 
    }
    
    public void testClassInNestedScope() throws Exception {
        String s = 
            "def some_function():\n" +
            "   class Starter:\n" +
            "       def m1(self):\n" +
            "           pass\n" +
            "   Starter.";
        ICompletionProposal[] proposals = requestCompl(s, s.length(), 1, new String[] {"m1(self)"});
        assertEquals(1, proposals.length); 
    }
    
    public void testClassInNestedScope2() throws Exception {
        String s = 
            "def some_function():\n" +
            "    class Starter:\n" +
            "        def m1(self):\n" +
            "            pass\n" +
            "    s = Starter()\n" +
            "    s.";
        ICompletionProposal[] proposals = requestCompl(s, s.length(), 1, new String[] {"m1()"});
        assertEquals(1, proposals.length); 
    }
    
    public void testGlobalClassInNestedScope() throws Exception {
        String s = 
            "def some_function():\n" +
            "    class Starter:\n" +
            "        def m1(self):\n" +
            "            pass\n" +
            "    global s\n" +
            "    s = Starter()\n" +
            "\n" +
            "def foo():\n" +
            "    s.";
        ICompletionProposal[] proposals = requestCompl(s, s.length(), 1, new String[] {"m1()"});
        assertEquals(1, proposals.length); 
    }
    
    public void testAssign() throws Exception {
        String s = 
            "class Foo(object):\n" +
            "    def foo(self):\n" +
            "        pass\n" +
            "class Bar(object):\n" +
            "    def bar(self):\n" +
            "        pass\n" +
            "    \n" +
            "def m1():\n" +
            "    if 1:\n" +
            "        c = Foo()\n" +
            "    elif 2:\n" +
            "        c = Bar()\n" +
            "    c.";
        requestCompl(s, s.length(), 2, new String[] {"foo()", "bar()"});
    }

    public void testAssign2() throws Exception {
        String s = 
            "class Foo(object):\n" +
            "    def foo(self):\n" +
            "        pass\n" +
            "class Bar(object):\n" +
            "    def bar(self):\n" +
            "        pass\n" +
            "    \n" +
            "class KKK:\n" +
            "    def m1(self):\n" +
            "        self.c = Foo()\n" +
            "    def m2(self):\n" +
            "        self.c = Bar()\n" +
            "    def m3(self):\n" +
            "        self.c.";
        requestCompl(s, s.length(), 2, new String[] {"foo()", "bar()"});
    }
    
    
    public void testReturn() throws Exception {
        String s = 
            "class Foo:\n" +
            "    def foo(self):\n" +
            "        pass\n" +
            "def m1():\n" +
            "    return Foo()\n" +
            "def m2():\n" +
            "    a = m1()\n" +
            "    a.";
        requestCompl(s, s.length(), 1, new String[] {"foo()"});
    }
    
    
    public void testReturn2() throws Exception {
        String s = 
            "class Foo:\n" +
            "    def method10(self):\n" +
            "        pass\n" +
            "def some_function():\n" +
            "    class Starter:\n" +
            "        def m1(self):\n" +
            "            pass\n" +
            "    if 1:\n" +
            "        return Starter()\n" +
            "    else:\n" +
            "        return Foo()\n" +
            "    \n" +
            "def foo():\n" +
            "    some = some_function()\n" +
            "    some.";
        requestCompl(s, s.length(), 2, new String[] {"m1()", "method10()"});
    }
    
    public void testReturn3() throws Exception {
        String s = 
            "class Foo:\n" +
            "    def method10(self):\n" +
            "        pass\n" +
            "def some_function():\n" +
            "    class Starter:\n" +
            "        def m1(self):\n" +
            "            pass\n" +
            "    def inner():\n" +
            "        return Starter()\n" + //ignore this one
            "    return Foo()\n" +
            "    \n" +
            "def foo():\n" +
            "    some = some_function()\n" +
            "    some.";
        requestCompl(s, s.length(), 1, new String[] {"method10()"});
    }
    
    public void testDecorateObject() throws Exception {
        String s = 
            "class Foo:\n" +
            "    def bar():pass\n"+
            "foo = Foo()\n"+
            "foo.one = 1\n"+
            "foo.two =2\n"+
            "foo.";
        
        requestCompl(s, new String[] {"one", "two", "bar()"});
    }
    
    public void testShadeClassDeclaration() throws Exception {
        String s = 
            "class Foo:\n" +
            "    def m1(self):\n" +
            "        pass\n" +
            "    \n" +
            "Foo = Foo()\n" +
            "Foo.";
        
        //don't let the name override the definition -- as only the name will remain, we won't be able to find the original
        //one, so, it will find it as an unbound call -- this may be fixed later, but as it's a corner case, let's leave
        //it like that for now.
        requestCompl(s, new String[] {"m1()"});
    }
    
    public void testRecursion1() throws Exception {
    	String s = 
    		"from testrec5.messages import foonotexistent\n" +
    		"foonotexistent.";
    	
    	requestCompl(s, new String[] {});
    }
    
}



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -