def testAncestry(self): from ast.namespace import Namespace from nine.driver import Driver driver = Driver() ns = Namespace('') driver._scanAssembly(ns, 'mscorlib') string = ns.symbols['System'].symbols['String'] object = ns.symbols['System'].symbols['Object'] assert not string.isDescendant(object) assert object.isDescendant(string), string.bases
def testGetMethods(self): 'testGetMethods: ClassDecl.getMethods' driver = Driver() ns = Namespace('') driver._scanAssembly(ns, 'bin/ClassLibrary1') class1 = ns.symbols['TestClass'].symbols['TestClass'] assert isinstance(class1, ExternalClass) names = set([func.name for func in class1.getMethods()]) expected = set(['Method', 'Method', 'StaticMethod', 'StaticMethod']) # There will be all kinds of other crud in there. None of it matters, as long as the right names are where they should be. self.failUnless(names > expected, (names, expected))
def semanticProgram(program, assemblies=[]): from ast.namespace import Namespace from ast.vartypes import Type driver = Driver() globalNs = Namespace('') for asm in assemblies: driver._scanAssembly(globalNs, asm) driver.fixPrimitives() globalScope = semantic.makeGlobalScope(globalNs.symbols) return semantic.semantic(parse(lex(program)), globalScope)
def testGetMethod(self): driver = Driver() ns = Namespace('') driver._scanAssembly(ns, 'mscorlib') console = ns.symbols['System'].symbols['Console'] writeLineStr = console.getMethod('WriteLine', (vartypes.StringType,), vartypes.VoidType) assert writeLineStr is not None nonExistent = console.getMethod('WriteLine', (vartypes.StringType,), vartypes.FloatType) assert nonExistent is None, writeLineStr toStr = console.getMethod('ToString', (), System.String) assert toStr is not None
def testScanAssembly(self): from nine.scope import Scope from ast.namespace import Namespace scope = Scope(parent=None) globalNs = Namespace('') driver = Driver() driver.addReference('bin/ClassLibrary1') driver._scanAssembly(globalNs, 'bin/ClassLibrary1') cls = globalNs.symbols['TestClass'].symbols['TestClass'] assert isinstance(cls, ExternalClass) assert cls.external self.assertEqual(cls.name, 'TestClass')
def testGetCtor(self): from ast.parameter import Parameter driver = Driver() ns = Namespace('') driver._scanAssembly(ns, 'mscorlib') string = ns.symbols['System'].symbols['String'] int32 = ns.symbols['System'].symbols['Int32'] char = ns.symbols['System'].symbols['Char'] c1args = ( Parameter((0,"<>"), 'a', char), Parameter((0,"<>"), 'b', int32) ) c2args = (Parameter((0,"<>"), 'b', int32),) c1 = string.getCtor(c1args) c2 = string.getCtor(c2args) assert c1 is not None assert c2 is None