def _Union(module, parsed_union): """ Args: module: {mojom.Module} Module currently being constructed. parsed_union: {ast.Union} Parsed union. Returns: {mojom.Union} AST union. """ union = mojom.Union(module=module) union.mojom_name = parsed_union.mojom_name union.spec = 'x:' + module.mojom_namespace + '.' + union.mojom_name module.kinds[union.spec] = union # Stash fields parsed_union here temporarily. union.fields_data = _ElemsOfType( parsed_union.body, ast.UnionField, parsed_union.mojom_name) union.attributes = _AttributeListToDict(parsed_union.attribute_list) return union
def _Union(module, parsed_union): """ Args: module: {mojom.Module} Module currently being constructed. parsed_union: {ast.Union} Parsed union. Returns: {mojom.Union} AST union. """ union = mojom.Union(module=module) union.mojom_name = parsed_union.mojom_name union.spec = 'x:' + module.GetNamespacePrefix() + union.mojom_name module.kinds[union.spec] = union # Stash fields parsed_union here temporarily. union.fields_data = [] _ProcessElements(parsed_union.mojom_name, parsed_union.body, {ast.UnionField: union.fields_data.append}) union.attributes = _AttributeListToDict(parsed_union.attribute_list) return union
def testImportFromDataNoMissingImports(self): """Tests that unions, structs, interfaces and enums are imported.""" module = mojom.Module('test_module', 'test_namespace') imported_module = mojom.Module('import_module', 'import_namespace') #TODO(azani): Init values in module.py. #TODO(azani): Test that values are imported. imported_module.values = {} imported_data = {'module' : imported_module} struct = mojom.Struct('TestStruct', module=module) imported_module.kinds[struct.spec] = struct union = mojom.Union('TestUnion', module=module) imported_module.kinds[union.spec] = union interface = mojom.Interface('TestInterface', module=module) imported_module.kinds[interface.spec] = interface enum = mojom.Enum('TestEnum', module=module) imported_module.kinds[enum.spec] = enum data.ImportFromData(module, imported_data) # Test that the kind was imported. self.assertIn(struct.spec, module.kinds) self.assertEquals(struct.name, module.kinds[struct.spec].name) self.assertIn(union.spec, module.kinds) self.assertEquals(union.name, module.kinds[union.spec].name) self.assertIn(interface.spec, module.kinds) self.assertEquals(interface.name, module.kinds[interface.spec].name) self.assertIn(enum.spec, module.kinds) self.assertEquals(enum.name, module.kinds[enum.spec].name) # Test that the imported kind is a copy and not the original. self.assertIsNot(struct, module.kinds[struct.spec]) self.assertIsNot(union, module.kinds[union.spec]) self.assertIsNot(interface, module.kinds[interface.spec]) self.assertIsNot(enum, module.kinds[enum.spec])