Package org.python.indexer.types

Examples of org.python.indexer.types.NType


import java.util.Set;

public class IndexerTest extends TestBase {

    public void testBuiltinModulePresent() throws Exception {
        NType mod = idx.moduleTable.lookupType("__builtin__");
        assertNotNull("missing __builtin__ module", mod);
        assertTrue("wrong type: " + mod.getClass(), mod instanceof NModuleType);
    }
View Full Code Here


        NBinding method = mtable.lookupType("MyClass").getTable().lookup("__init__");
        assertNotNull(method);
        assertEquals(NBinding.Kind.CONSTRUCTOR, method.getKind());
        assertEquals("classtype_builtins.MyClass.__init__", method.getQname());

        NType ftype = mtable.lookupType("MyClass").getTable().lookupType("__init__");
        assertTrue(ftype.isFuncType());

        NBinding c = mtable.lookup("MyClass");
        for (String special : new String[]{"im_class", "__class__", "im_self", "__self__"}) {
            NBinding attr = ftype.getTable().lookup(special);
            assertNotNull("missing binding for " + special, attr);
            assertEquals(c.getType(), attr.getType());
        }
    }
View Full Code Here

            "reassign.py",
            "app.foo = 'hello'",
            "app.foo = 2");
        assertScopeBinding("reassign.app");
        NBinding nb = assertAttributeBinding("reassign.app.foo");
        NType type = nb.getType();
        assertTrue(type.isUnionType());
        Set<NType> types = ((NUnionType)type).getTypes();
        assertEquals(2, types.size());
        assertTrue(types.contains(idx.builtins.BaseStr));
        assertTrue(types.contains(idx.builtins.BaseNum));
    }
View Full Code Here

        String src = index(
            "test.py",
            "def foo():",
            "  return (foo,)");
        assertFunctionBinding("test.foo");
        NType ftype = idx.lookupQnameType("test.foo");
        assertTrue(ftype instanceof NFuncType);
        NType rtype = ftype.asFuncType().getReturnType();
        assertTrue(rtype instanceof NTupleType);
        assertEquals(1, rtype.asTupleType().getElementTypes().size());
        assertEquals(ftype, rtype.asTupleType().getElementTypes().get(0));
        assertEquals("<FuncType=#1:_:<TupleType:[<#1>]>>", ftype.toString());
    }
View Full Code Here

        String src = index(
            "test.py",
            "x = (2,)",
            "y = [x]",
            "x = y");
        NType xtype = idx.lookupQnameType("test.x");
        assertTrue(xtype instanceof NUnionType);

        // Jump through some hoops to allow for either order in the union.
        Set<NType> types = xtype.asUnionType().getTypes();
        assertEquals(2, types.size());
        NType[] array = types.toArray(new NType[2]);
        boolean array0List = array[0] instanceof NListType;
        boolean array1List = array[1] instanceof NListType;

        assertTrue(array0List || array1List);
        int other = array0List ? 1 : 0;
        assertTrue("Expected tuple: " + array[other], array[other].isTupleType());
        assertEquals(1, array[other].asTupleType().getElementTypes().size());
        assertEquals(idx.builtins.BaseNum, array[other].asTupleType().getElementTypes().get(0));

        String s = xtype.toString();
        int index = s.indexOf("<TupleType=#");
        assertTrue(index != -1);
        int spot = index + "<TupleType=#".length();
        int num = Integer.parseInt(s.substring(spot, spot+1));
View Full Code Here

            "fret.py",
            "def foo(x): return x",
            "a = foo('a')",
            "b = foo('b')",
            "c = foo('c')");
        NType ftype = idx.lookupQnameType("fret.foo");
        assertEquals("<FuncType:_:<UnknownType:null>>", ftype.toString());
        NType ctype = idx.lookupQnameType("fret.c");
        assertEquals(ctype.follow(), ftype.asFuncType().getReturnType());
    }
View Full Code Here

        String[] names = qname.split("[.&@]");
        assertConstructed(qname, offset, names[names.length-1]);
    }

    public NType getTypeBinding(String typeQname) throws Exception {
        NType type = idx.lookupQnameType(typeQname);
        assertNotNull("No recorded type for " + typeQname, type);
        return type;
    }
View Full Code Here

    // Assert that binding for qname has exactly one type (not a union),
    // and that type has a binding with typeQname.
    public NBinding assertBindingType(String bindingQname, String typeQname) throws Exception {
        NBinding b = getBinding(bindingQname);
        NType expected = getTypeBinding(typeQname);
        assertEquals("Wrong binding type", expected, NUnknownType.follow(b.getType()));
        return b;
    }
View Full Code Here

        return b;
    }

    public NBinding assertBindingType(String bindingQname, Class type) throws Exception {
        NBinding b = getBinding(bindingQname);
        NType btype = NUnknownType.follow(b.getType());
        assertTrue("Wrong type: expected " + type + " but was " + btype,
                   type.isInstance(btype));
        return b;
    }
View Full Code Here

     * asserts that the List type's element type is an existing binding with
     * {@code eltTypeQname}.
     */
    public void assertListType(String bindingQname, String eltTypeQname) throws Exception {
        NBinding b = getBinding(bindingQname);
        NType btype = b.followType();
        assertTrue(btype.isListType());
        if (eltTypeQname != null) {
            NType eltType = getTypeBinding(eltTypeQname);
            assertEquals(eltType, NUnknownType.follow(btype.asListType().getElementType()));
        }
    }
View Full Code Here

TOP

Related Classes of org.python.indexer.types.NType

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.