def testInterfaceBasic(self): self.assertEqual(tree.Interface(name=tree.Identifier('abc')), self.parse('''interface abc {};''').definitions[0]) self.assertEqual( tree.Interface(name=tree.Identifier('abc'), properties=[tree.Property('prop')]), self.parse('''[prop] interface abc {};''').definitions[0])
def testPropertyRegression(self): self.assertEqual( tree.Interface( name=tree.Identifier('abc'), properties=[tree.Property('prop1'), tree.Property('prop2')]), self.parse('''[prop1,prop2] interface abc {};''').definitions[0])
def testNative(self): self.assertEqual( tree.NativeDecl(declarator=tree.Identifier('NativeType'), native_type=None, properties=[]), self.parse('''native NativeType;''').definitions[0]) self.assertEqual( tree.NativeDecl(declarator=tree.Identifier('NativeType'), native_type='something native', properties=[]), self.parse( '''native NativeType(something native);''').definitions[0]) self.assertEqual( tree.NativeDecl(declarator=tree.Identifier('NativeType'), properties=[tree.Property('prop')]), self.parse('''[prop] native NativeType;''').definitions[0])
def testDuplicateModifiers(self): self.assertEqual( tree.Interface(name=tree.Identifier('abc'), body=[ tree.OperationDef( name=tree.Identifier('test'), return_type=tree.BasicTypeNode('void'), parameters=tree.Parameters([]), raises=None, modifiers=['static'], context=None, properties=[]) ]), self.parse('''interface abc { static void test(); };''', webidl=True).definitions[0]) try: self.parse('''interface abc { static static void test(); };''', webidl=True) self.fail('Exception has not been raised') except IDLSyntaxError: self.assertTrue(True)
def testTypedefs(self): self.assertEqual( tree.TypeDef(declarators=[tree.Identifier('bar')], properties=[], type=tree.SimpleTypeReferenceNode( name=tree.Identifier('foo'), scope=tree.CurrentScopeNode())), self.parse('''typedef foo bar;''').definitions[0]) self.assertEqual( tree.TypeDef(declarators=[tree.Identifier('bar')], properties=[], type=tree.SimpleTypeReferenceNode( name=tree.Identifier('foo'), scope=tree.NamespaceReference( tree.Identifier('ns'), tree.CurrentScopeNode()))), self.parse('''typedef ns::foo bar;''').definitions[0]) self.assertEqual( tree.TypeDef(declarators=[tree.Identifier('bar')], properties=[], type=tree.SimpleTypeReferenceNode( name=tree.Identifier('foo'), scope=tree.NamespaceReference())), self.parse('''typedef ::foo bar;''').definitions[0]) self.assertEqual( tree.TypeDef(declarators=[tree.Identifier('bar')], properties=[], type=tree.SimpleTypeReferenceNode( name=tree.Identifier('foo'), scope=tree.NamespaceReference( tree.Identifier('ns'), tree.NamespaceReference()))), self.parse('''typedef ::ns::foo bar;''').definitions[0]) self.assertEqual( tree.TypeDef(declarators=[tree.Identifier('bar')], properties=[tree.Property('prop')], type=tree.SimpleTypeReferenceNode( name=tree.Identifier('foo'), scope=tree.CurrentScopeNode())), self.parse('''[prop] typedef foo bar;''').definitions[0]) self.assertEqual( tree.TypeDef(declarators=[ tree.Identifier('bar'), tree.Identifier('baz') ], properties=[], type=tree.SimpleTypeReferenceNode( name=tree.Identifier('foo'), scope=tree.CurrentScopeNode())), self.parse('''typedef foo bar, baz;''').definitions[0])