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

📄 parseditemtest.java

📁 Python Development Environment (Python IDE plugin for Eclipse). Features editor, code completion, re
💻 JAVA
字号:
package org.python.pydev.outline;

import org.python.pydev.core.IGrammarVersionProvider;
import org.python.pydev.parser.PyParserTestBase;
import org.python.pydev.parser.jython.SimpleNode;
import org.python.pydev.parser.visitors.scope.ASTEntryWithChildren;
import org.python.pydev.parser.visitors.scope.OutlineCreatorVisitor;

public class ParsedItemTest extends PyParserTestBase {

    public void testParsedItemCreation() throws Exception {
        setDefaultVersion(IGrammarVersionProvider.GRAMMAR_PYTHON_VERSION_2_5);
        String str = "" +
        		"class Foo(object):\n" +
        		"    def m1(self):\n" +
        		"        pass\n" +
        		"        #--- comm method\n" +
        		"    #--- comm class\n" +
        		"#--- comm module\n" +
        		"";
        
        SimpleNode node = parseLegalDocStr(str);
        
        OutlineCreatorVisitor visitor = OutlineCreatorVisitor.create(node);
        ParsedItem item = new ParsedItem(visitor.getAll().toArray(new ASTEntryWithChildren[0]), null);
        
        //module level: Foo and 1 comment
        assertEquals(2, item.astChildrenEntries.length);
        assertNull(item.astChildrenEntries[1].children); //comment has no children
        
        //class level: m1 and 1 comment
        ASTEntryWithChildren classEntry = item.astChildrenEntries[0];
        assertEquals(2, classEntry.children.size()); 
        assertNull(classEntry.children.get(1).children); //comment has no children
        
        // method level: 1 comment
        ASTEntryWithChildren functionEntry = classEntry.children.get(0);
        assertEquals(1, functionEntry.children.size()); 
        
    }
    
    public void testParsedItemCreation2() throws Exception {
        setDefaultVersion(IGrammarVersionProvider.GRAMMAR_PYTHON_VERSION_2_5);
        String str = "" +
        "class Foo(object):\n" +
        "    pass\n" +
        "if __name__ == '__main__':\n" +
        "    var = 10\n" +
        "\n" +
        "";
        
        SimpleNode node = parseLegalDocStr(str);
        
        OutlineCreatorVisitor visitor = OutlineCreatorVisitor.create(node);
        ParsedItem item = new ParsedItem(visitor.getAll().toArray(new ASTEntryWithChildren[0]), null);
        
        //module level: only Foo
        assertEquals(1, item.astChildrenEntries.length);
        assertNull(item.astChildrenEntries[0].children); //no children
        
    }
}

⌨️ 快捷键说明

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