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

📄 pyautoindentstrategytest.java

📁 Python Development Environment (Python IDE plugin for Eclipse). Features editor, code completion, re
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
    }
    
    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); 
    }
    
    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); 
    }
    
    public void testNewLine7() {
        strategy.setIndentPrefs(new TestIndentPrefs(true, 4));
        String str = "" +
        "class C:\n" +
        "    a = 30\n" +
        "print C.a\n" +
        "\n" +
        "";
        final Document doc = new Document(str);
        DocCmd docCmd = new DocCmd(doc.getLength(), 0, "\n");
        strategy.customizeDocumentCommand(doc, docCmd);
        assertEquals("\n", docCmd.text); 
    }
    
    public void testNewLine8() {
        strategy.setIndentPrefs(new TestIndentPrefs(true, 4));
        String str = "" +
        "class C:\n" +
        "    pass\n" +
        "    a = 30\n" +
        "    " +
        "";
        final Document doc = new Document(str);
        DocCmd docCmd = new DocCmd(doc.getLength(), 0, "\n");
        strategy.customizeDocumentCommand(doc, docCmd);
        assertEquals("\n    ", docCmd.text); 
    }
    
    public void testIndent() {
    	strategy.setIndentPrefs(new TestIndentPrefs(true, 4));
    	String str = "" +
    	"while False:\n" +
    	"    if foo:" +
    	"";
    	final Document doc = new Document(str);
    	DocCmd docCmd = new DocCmd(doc.getLength()-"if foo:".length(), 0, "\n");
    	strategy.customizeDocumentCommand(doc, docCmd);
    	assertEquals("\n    ", docCmd.text); 
    }
    
    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); 
    }
    
    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); 
    }
    
    public void testNewLine9() {
        strategy.setIndentPrefs(new TestIndentPrefs(true, 4));
        String str = "" +
        "class C:\n" +
        "    try:" +
        "";
        final Document doc = new Document(str);
        DocCmd docCmd = new DocCmd(doc.getLength(), 0, "\n");
        strategy.customizeDocumentCommand(doc, docCmd);
        assertEquals("\n        ", docCmd.text); 
    }
    
    public void testNewLine4() {
    	strategy.setIndentPrefs(new TestIndentPrefs(true, 4));
    	String str = "" +
    			"def a():\n" +
    			"    print a" +
    	"";
    	final Document doc = new Document(str);
    	DocCmd docCmd = new DocCmd(doc.getLength()-"    print a".length(), 0, "\n");
    	strategy.customizeDocumentCommand(doc, docCmd);
    	String expected = "" +
    	"def a():\n" +
    	"    print a" +
    	"";
    	assertEquals(expected, doc.get()); 
    	assertEquals("\n", docCmd.text); 
    	
    }
    
    public void testNewLine5() {
    	strategy.setIndentPrefs(new TestIndentPrefs(true, 4));
    	String str = "" +
    	"def a():\n" +
    	"    " +
    	"";
    	final Document doc = new Document(str);
    	DocCmd docCmd = new DocCmd(doc.getLength()-"    ".length(), 0, "\n");
    	strategy.customizeDocumentCommand(doc, docCmd);
    	String expected = "" +
    	"def a():\n" +
    	"    " +
    	"";
    	assertEquals(expected, doc.get()); 
    	assertEquals("\n", docCmd.text); 
    }
    
    public void testNewLine() {
    	strategy.setIndentPrefs(new TestIndentPrefs(true, 4));
    	String str = "createintervention() #create " +
    	"";
    	final Document doc = new Document(str);
    	DocCmd docCmd = new DocCmd(doc.getLength(), 0, "\n");
    	strategy.customizeDocumentCommand(doc, docCmd);
    	assertEquals("\n", docCmd.text); 
    	
    }
    
    public void testNewLine2() {
    	strategy.setIndentPrefs(new TestIndentPrefs(true, 4));
    	String str = "err)" +
    	"";
    	final Document doc = new Document(str);
    	DocCmd docCmd = new DocCmd(doc.getLength(), 0, "\n");
    	strategy.customizeDocumentCommand(doc, docCmd);
    	assertEquals("\n", docCmd.text); 
    	
    }
    
    
    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
    	
    }
    
    public void testIndentingWithTab() {
    	strategy.setIndentPrefs(new TestIndentPrefs(true, 4));
    	String str = "class C:\n" +
    			     "    def m1(self):\n" +
    			     "";
    	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
    }
    
    public void testIndentingWithTab2() {
    	strategy.setIndentPrefs(new TestIndentPrefs(true, 4));
    	String str = "" +
    			"class C:\n" +
    			"    pass\n" +
    			"";
    	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
    }
    
    public void testIndentingWithTab3() {
    	strategy.setIndentPrefs(new TestIndentPrefs(true, 4));
    	String str = "" +
    	"class C:\n" +
    	"    def m1(self):            \n" +
    	"        print 1\n" +
    	"";
    	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
    }
    
    public void testWithoutSmartIndent() {
    	final TestIndentPrefs prefs = new TestIndentPrefs(true, 4);
    	prefs.smartIndentAfterPar = false;
		strategy.setIndentPrefs(prefs);
    	String str = "" +
    	"class C:\n" +
    	"    def m1(self):" +
    	"";
    	final Document doc = new Document(str);
    	DocCmd docCmd = new DocCmd(doc.getLength(), 0, "\n");
    	strategy.customizeDocumentCommand(doc, docCmd);
    	assertEquals("\n        ", docCmd.text); // a single tab should go to the correct indent
    }
    
    public void testIndentingWithTab4() {
    	strategy.setIndentPrefs(new TestIndentPrefs(true, 4));
    	String str = "" +
    	"class C:\n" +
    	"    def m1(self):            \n" +
    	"        print 'a'\n" +
    	"        " + //now, a 'regular' tab should happen
    	"";
    	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
    }
    
    public void testIndentingWithTab5() {
    	strategy.setIndentPrefs(new TestIndentPrefs(true, 4));
    	String str = "" +
    	"class C:\n" +
    	"    def m1(self):            \n" +
    	"        print 'a'\n" +
    	"       " + //now, only 1 space is missing to the correct indent
    	"";
    	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
    }
    
    public void testIndentingWithTab6() {
    	strategy.setIndentPrefs(new TestIndentPrefs(true, 4));
    	String str = "" +
    	"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
    }
    
    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
    }
    
    public void testTabs() {
        strategy.setIndentPrefs(new TestIndentPrefs(false, 4));
        DocCmd docCmd = new DocCmd(0, 0, "\t");
        strategy.customizeDocumentCommand(new Document(""), docCmd);
        assertEquals("\t", docCmd.text);
        
        docCmd = new DocCmd(0, 0, "\t\t");
        strategy.customizeDocumentCommand(new Document(""), docCmd);
        assertEquals("\t\t", docCmd.text);
        
        docCmd = new DocCmd(0, 0, "\tabc");
        strategy.customizeDocumentCommand(new Document(""), docCmd);
        assertEquals("\tabc", docCmd.text);
        
        docCmd = new DocCmd(0, 0, "\tabc\t");
        strategy.customizeDocumentCommand(new Document(""), docCmd);
        assertEquals("\tabc\t", docCmd.text);
        
        docCmd = new DocCmd(0, 0, "    abc"); //paste
        strategy.customizeDocumentCommand(new Document(""), docCmd);
        assertEquals("\tabc", docCmd.text);
    }

    public void testCommentsIndent() {
        strategy.setIndentPrefs(new TestIndentPrefs(true, 4));

        doc = "class c: #some comment";
        docCmd = new DocCmd(doc.length(), 0, "\n");
        strategy.customizeDocumentCommand(new Document(doc), docCmd);
        expected = "\n" +
                   "    ";
        assertEquals(expected, docCmd.text);
    }
    
    public void testCommentsIndent2() {
    	strategy.setIndentPrefs(new TestIndentPrefs(true, 4));
        //test not indent more
        doc = "    # comment:";
        docCmd = new DocCmd(doc.length(), 0, "\n");
        strategy.customizeDocumentCommand(new Document(doc), docCmd);
        expected = "\n" +
        "    ";
        assertEquals(expected, docCmd.text);
        
        //test indent more
        doc = "    if False:";
        docCmd = new DocCmd(doc.length(), 0, "\n");
        strategy.customizeDocumentCommand(new Document(doc), docCmd);
        expected = "\n" +
        "        ";
        assertEquals(expected, docCmd.text);
    }
    
    public void testIndentLevel3() {
    	strategy.setIndentPrefs(new TestIndentPrefs(true, 4));
    	
    	String doc = "" +
		"a = (1, \n" +
		"  2,"; //should keep this indent, and not go to the opening bracket indent.
    	DocCmd docCmd = new DocCmd(doc.length(), 0, "\n");
    	strategy.customizeDocumentCommand(new Document(doc), docCmd);
    	String expected = "\n  ";
    	assertEquals(expected, docCmd.text);
    }
    
    public void testIndentLevel() {
        strategy.setIndentPrefs(new TestIndentPrefs(true, 4));
        
        String doc = "" +
                "def m1(): #some comment\n" +
                "    print foo(a,\n" +
                "              b)";
        DocCmd docCmd = new DocCmd(doc.length(), 0, "\n");
        strategy.customizeDocumentCommand(new Document(doc), docCmd);
        String expected = "\n    ";
        assertEquals(expected, docCmd.text);
    }
    
    public void testIndentLevel2() {
        strategy.setIndentPrefs(new TestIndentPrefs(true, 4));
        
        String doc = "" +
        "def m1(): #some comment\n" +
        "    def metfoo(a,\n" +
        "               b):";
        DocCmd docCmd = new DocCmd(doc.length(), 0, "\n");
        strategy.customizeDocumentCommand(new Document(doc), docCmd);
        String expected = "\n        ";
        assertEquals(expected, docCmd.text);
    }
    
    public void testDedent() {
        strategy.setIndentPrefs(new TestIndentPrefs(true, 4));

        String doc = "def m1(): #some comment\n" +
                     "    return 10";
        DocCmd docCmd = new DocCmd(doc.length(), 0, "\n");
        strategy.customizeDocumentCommand(new Document(doc), docCmd);
        String expected = "\n";
        assertEquals(expected, docCmd.text);
        
        //test ending with
        doc = "def m1(): #some comment\n" +
              "    return";
        docCmd = new DocCmd(doc.length(), 0, "\n");
        strategy.customizeDocumentCommand(new Document(doc), docCmd);
        expected = "\n";
        assertEquals(expected, docCmd.text);
        
        //test not dedenting
        doc = "def m1(): #some comment\n" +
        "    returnIs10 = 10";
        docCmd = new DocCmd(doc.length(), 0, "\n");
        strategy.customizeDocumentCommand(new Document(doc), docCmd);
        expected = "\n"+
        "    ";
        assertEquals(expected, docCmd.text);
        
    }
    
    public void testIndentSpaces() {
        //test after class xxx:\n
        strategy.setIndentPrefs(new TestIndentPrefs(true, 4));
        String doc = "class c:";
        DocCmd docCmd = new DocCmd(doc.length(), 0, "\n");
        strategy.customizeDocumentCommand(new Document(doc), docCmd);

⌨️ 快捷键说明

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