How to use specializedSelfConformanceTypeName method of conformance. class

Best Mockingbird code snippet using conformance..specializedSelfConformanceTypeName

MockableType.swift

Source:MockableType.swift Github

copy

Full Screen

...216 } else if let primaryType = allSelfConformanceTypes.sorted()217 .first(where: { $0.kind == .class }) {218 self.primarySelfConformanceType = primaryType219 self.primarySelfConformanceTypeName = MockableType220 .specializedSelfConformanceTypeName(primaryType,221 specializationContexts: specializationContexts,222 moduleNames: moduleNames,223 baseRawType: baseRawType,224 rawTypeRepository: rawTypeRepository,225 typealiasRepository: typealiasRepository)226 } else {227 self.primarySelfConformanceType = nil228 self.primarySelfConformanceTypeName = nil229 }230 231 self.subclassesExternalType = subclassesExternalType || conformsToExternalType232 self.methods = methods233 self.variables = variables234 235 var methodsCount = [Method.Reduced: UInt]()236 methods.forEach({ methodsCount[Method.Reduced(from: $0), default: 0] += 1 })237 self.methodsCount = methodsCount238 239 self.genericTypes = genericTypes240 self.whereClauses = Set(whereClauses)241 242 // Parse any containing preprocessor macros.243 if let offset = baseRawType.dictionary[SwiftDocKey.offset.rawValue] as? Int64 {244 self.compilationDirectives = baseRawType.parsedFile.compilationDirectives.filter({245 $0.range.contains(offset)246 })247 } else {248 self.compilationDirectives = []249 }250 251 // Check if any of the members have `Self` constraints.252 self.hasSelfConstraint = whereClauses.contains(where: { $0.hasSelfConstraint })253 || methods.contains(where: { $0.hasSelfConstraint })254 || variables.contains(where: { $0.hasSelfConstraint })255 || genericTypes.contains(where: { $0.hasSelfConstraint })256 257 if baseRawType.parsedFile.shouldMock {258 self.sortableIdentifier = [259 self.name,260 self.genericTypes.map({ "\($0.name):\($0.constraints)" }).joined(separator: ","),261 self.whereClauses.map({ "\($0)" }).joined(separator: ",")262 ].joined(separator: "|")263 } else {264 self.sortableIdentifier = name265 }266 }267 268 private static func parseDeclaredTypes(rawTypes: [RawType],269 baseRawType: RawType,270 moduleNames: [String],271 rawTypeRepository: RawTypeRepository,272 typealiasRepository: TypealiasRepository)273 -> (methods: Set<Method>, variables: Set<Variable>) {274 var methods = Set<Method>()275 var variables = Set<Variable>()276 for rawType in rawTypes {277 guard let substructure = rawType.dictionary[SwiftDocKey.substructure.rawValue]278 as? [StructureDictionary] else { continue }279 // Cannot override declarations in extensions as they are statically defined.280 guard rawType.kind != .extension else { continue }281 for structure in substructure {282 if let method = Method(from: structure,283 rootKind: baseRawType.kind,284 rawType: rawType,285 moduleNames: moduleNames,286 rawTypeRepository: rawTypeRepository,287 typealiasRepository: typealiasRepository) {288 methods.insert(method)289 }290 if let variable = Variable(from: structure,291 rootKind: baseRawType.kind,292 rawType: rawType,293 moduleNames: moduleNames,294 rawTypeRepository: rawTypeRepository) {295 variables.insert(variable)296 }297 }298 }299 return (methods, variables)300 }301 302 // TODO: Supporting protocol `Self` conformance has bloated this function. Needs a refactor soon.303 private static func parseInheritedTypes(rawInheritedTypeNames: [String],304 forConformance: Bool,305 methods: inout Set<Method>,306 variables: inout Set<Variable>,307 genericTypes: inout [GenericType],308 whereClauses: inout [WhereClause],309 selfConstraintClauses: [WhereClause],310 mockableTypes: [String: MockableType],311 moduleNames: [String],312 genericTypeContext: [[String]],313 specializationContexts: [String: SpecializationContext],314 baseRawType: RawType,315 rawTypeRepository: RawTypeRepository,316 typealiasRepository: TypealiasRepository)317 318 -> (inheritedTypes: Set<MockableType>, // Directly inherited types319 allInheritedTypes: Set<MockableType>, // Includes ancestor inheritance320 allInheritedTypeNames: [String], // Includes ancestor inheritance and opaque type names321 subclassesExternalType: Bool) {322 323 var inheritedTypes = Set<MockableType>()324 var allInheritedTypes = Set<MockableType>()325 var allInheritedTypeNames = [String]()326 var subclassesExternalType = false327 let definesDesignatedInitializer = methods.contains(where: { $0.isDesignatedInitializer })328 329 let resolveRawType: (String) -> RawType? = { typeName in330 guard let nearestRawType = rawTypeRepository331 .nearestInheritedType(named: typeName,332 trimmedName: typeName.removingGenericTyping(),333 moduleNames: moduleNames,334 referencingModuleName: baseRawType.parsedFile.moduleName,335 containingTypeNames: baseRawType.containingTypeNames[...])?336 .findBaseRawType() else { return nil }337 338 // Map unmockable inherited types to other types.339 if baseRawType.kind == .protocol,340 let mappedType = MockableType.Constants.automaticInheritanceMap[341 nearestRawType.fullyQualifiedModuleName342 ],343 let mappedRawType = rawTypeRepository.rawType(named: mappedType.typeName,344 in: mappedType.moduleName) {345 return mappedRawType.findBaseRawType()346 }347 348 return nearestRawType349 }350 351 // Find the correct `MockableType` instances for inheritance based on type name.352 let parsedInheritedTypes = rawInheritedTypeNames.flatMap({ typeName -> [MockableType] in353 guard let nearestRawType = resolveRawType(typeName) else {354 log("Unable to resolve inherited type \(typeName.singleQuoted) for \(baseRawType.name.singleQuoted)")355 allInheritedTypeNames.append(typeName)356 return []357 }358 359 // Inherited types could be typealiased, which would hide conformance.360 guard nearestRawType.kind == .typealias else {361 guard let mockableType = mockableTypes[nearestRawType.fullyQualifiedModuleName] else {362 return []363 }364 return [mockableType]365 }366 367 // Resolve typealias to fully qualified root type name.368 let actualTypeNames = typealiasRepository369 .actualTypeNames(for: nearestRawType.fullyQualifiedModuleName,370 rawTypeRepository: rawTypeRepository,371 moduleNames: moduleNames,372 referencingModuleName: baseRawType.parsedFile.moduleName,373 containingTypeNames: baseRawType.containingTypeNames[...])374 375 // Resolve fully qualified root type name to raw type.376 return actualTypeNames.compactMap({377 guard let nearestRawType = rawTypeRepository378 .nearestInheritedType(named: $0,379 trimmedName: $0.removingGenericTyping(),380 moduleNames: moduleNames,381 referencingModuleName: baseRawType.parsedFile.moduleName,382 containingTypeNames: baseRawType.containingTypeNames[...])?383 .findBaseRawType() else { return nil }384 return mockableTypes[nearestRawType.fullyQualifiedModuleName]385 })386 })387 // Merge all inheritable members from the `MockableType` instances.388 for mockableType in parsedInheritedTypes {389 if baseRawType.kind == .class390 && mockableType.kind == .class391 && mockableType.moduleName != baseRawType.parsedFile.moduleName {392 subclassesExternalType = true393 }394 395 let shouldInheritFromType = baseRawType.kind == .protocol || mockableType.kind != .protocol396 let specializationContext = specializationContexts[mockableType.fullyQualifiedModuleName]397 398 methods = methods.union(mockableType.methods399 .filter({ method in400 let isImplicitlySynthesized = method.attributes.contains(.implicit)401 guard shouldInheritFromType || isImplicitlySynthesized else { return false }402 return method.kind.typeScope.isMockable(in: baseRawType.kind) &&403 // Mocking a subclass with designated initializers shouldn't inherit the superclass'404 // initializers.405 (baseRawType.kind == .protocol406 || isImplicitlySynthesized407 || !definesDesignatedInitializer408 || !method.isInitializer)409 })410 .map({ method in // Specialize methods from generic types.411 guard let context = specializationContext else { return method }412 return method.specialize(using: context,413 moduleNames: moduleNames,414 genericTypeContext: genericTypeContext,415 excludedGenericTypeNames: [],416 rawTypeRepository: rawTypeRepository,417 typealiasRepository: typealiasRepository)418 })419 )420 variables = variables.union(mockableType.variables421 .filter({ variable in422 guard shouldInheritFromType || variable.attributes.contains(.implicit)423 else { return false }424 return variable.kind.typeScope.isMockable(in: baseRawType.kind)425 })426 .map({ variable in // Specialize variables from generic types.427 guard let context = specializationContext else { return variable }428 return variable.specialize(using: context,429 moduleNames: moduleNames,430 genericTypeContext: genericTypeContext,431 excludedGenericTypeNames: [],432 rawTypeRepository: rawTypeRepository,433 typealiasRepository: typealiasRepository)434 })435 )436 437 // Classes must already implement generic constraints from protocols they conform to.438 guard shouldInheritFromType else { continue }439 440 inheritedTypes.insert(mockableType)441 442 // Indirect inheritance.443 if !forConformance {444 allInheritedTypes.formUnion(mockableType.inheritedTypes)445 allInheritedTypeNames.append(contentsOf: mockableType.allInheritedTypeNames)446 } else {447 allInheritedTypes.formUnion(mockableType.selfConformanceTypes)448 allInheritedTypeNames.append(contentsOf: mockableType.allSelfConformanceTypeNames)449 }450 451 let isSelfConstraintType = selfConstraintClauses.contains(where: {452 $0.constrainedTypeName == mockableType.fullyQualifiedModuleName453 || $0.genericConstraint == mockableType.fullyQualifiedModuleName454 })455 let shouldIncludeInheritedType = !forConformance ||456 forConformance && (isSelfConstraintType || mockableType.kind == .class)457 if shouldIncludeInheritedType {458 allInheritedTypes.insert(mockableType)459 allInheritedTypeNames.append(MockableType.specializedSelfConformanceTypeName(460 mockableType,461 specializationContexts: specializationContexts,462 moduleNames: moduleNames,463 baseRawType: baseRawType,464 rawTypeRepository: rawTypeRepository,465 typealiasRepository: typealiasRepository466 ))467 }468 // Only bubble-up generics for protocols from inherited protocols.469 if baseRawType.kind == .protocol && mockableType.kind == .protocol {470 let uniqueGenericTypes = Set<String>(genericTypes.map({ $0.name }))471 genericTypes.append(contentsOf: mockableType.genericTypes.filter({472 !uniqueGenericTypes.contains($0.name)473 }))474 whereClauses.append(contentsOf: mockableType.whereClauses)475 }476 }477 return (inheritedTypes, allInheritedTypes, allInheritedTypeNames, subclassesExternalType)478 }479 480 private static func specializedSelfConformanceTypeName(481 _ type: MockableType,482 specializationContexts: [String: SpecializationContext],483 moduleNames: [String],484 baseRawType: RawType,485 rawTypeRepository: RawTypeRepository,486 typealiasRepository: TypealiasRepository487 ) -> String {488 guard !type.genericTypes.isEmpty, !specializationContexts.isEmpty,489 let context = specializationContexts[type.fullyQualifiedModuleName]490 else { return type.fullyQualifiedModuleName }491 492 let specializedGenericTypes = context.typeList.map({ specialization -> String in493 let serializationContext = SerializationRequest494 .Context(moduleNames: moduleNames,...

Full Screen

Full Screen

specializedSelfConformanceTypeName

Using AI Code Generation

copy

Full Screen

1 func foo() {2 print("C.foo")3 }4}5extension C: P where T == Int {6 func foo() {7 print("C.foo where T == Int")8 }9}10extension C: P where T == String {11 func foo() {12 print("C.foo where T == String")13 }14}15let c1 = C<Int>()16let c2 = C<String>()17let c3 = C<Bool>()18 func foo() {19 print("C.foo where T == Int")20 }21}22extension C: P where T == String {23 func foo() {24 print("C.foo where T == String")25 }26}27let c1 = C<Int>()28let c2 = C<String>()29let c3 = C<Bool>()

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Mockingbird automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful