def test_array_type(self): array_types = [ (False, False, -1), (False, False, 10), (True, False, -1), (True, True, -1), (False, True, -1), (False, True, 10), ] g = mojom_files_mojom.MojomFileGraph() t = mojom_translator.FileTranslator(g, None) for array_nullable, element_nullable, size in array_types: a = mojom_types_mojom.Type() a.array_type = mojom_types_mojom.ArrayType(nullable=array_nullable, fixed_length=size) a.array_type.element_type = mojom_types_mojom.Type( string_type=mojom_types_mojom.StringType( nullable=element_nullable)) result = t.KindFromMojom(a) self.assertTrue(module.IsArrayKind(result)) self.assertTrue(module.IsStringKind(result.kind)) self.assertEquals(array_nullable, module.IsNullableKind(result)) self.assertEquals(element_nullable, module.IsNullableKind(result.kind)) if size < 0: self.assertIsNone(result.length) else: self.assertEquals(size, result.length)
def extract_referenced_user_kinds(kind): if mojom.IsArrayKind(kind): return extract_referenced_user_kinds(kind.kind) if mojom.IsMapKind(kind): return (extract_referenced_user_kinds(kind.key_kind) + extract_referenced_user_kinds(kind.value_kind)) if mojom.IsInterfaceRequestKind(kind) or mojom.IsAssociatedKind(kind): return [kind.kind] if mojom.IsStructKind(kind): return [kind] if (mojom.IsInterfaceKind(kind) or mojom.IsEnumKind(kind) or mojom.IsUnionKind(kind)): return [kind] return []
def AddImport(element): """AddImport is a utility function that adds the import of the provided element to the used dictionary defined above. """ # Only named values or kinds could be imported. if (not isinstance(element, mojom.Kind) and not isinstance(element, mojom.NamedValue)): return if mojom.IsArrayKind(element) or mojom.IsInterfaceRequestKind(element): AddImport(element.kind) return if mojom.IsMapKind(element): AddImport(element.key_kind) AddImport(element.value_kind) return if not hasattr(element, 'imported_from') or not element.imported_from: return imported_from = element.imported_from used[imported_from['module'].path] = imported_from
def ExpectedArraySize(kind): if mojom.IsArrayKind(kind): return kind.length return None