diff --git a/Package.swift b/Package.swift index 938b1e91..ea705f24 100644 --- a/Package.swift +++ b/Package.swift @@ -1,10 +1,11 @@ -// swift-tools-version:5.7 +// swift-tools-version:5.10 +import CompilerPluginSupport import PackageDescription let package = Package( name: "Mockolo", platforms: [ - .macOS(.v12), + .macOS(.v13), ], products: [ .executable(name: "mockolo", targets: ["Mockolo"]), @@ -21,7 +22,8 @@ let package = Package( dependencies: [ "MockoloFramework", .product(name: "ArgumentParser", package: "swift-argument-parser"), - ]), + ] + ), .target( name: "MockoloFramework", dependencies: [ @@ -30,12 +32,21 @@ let package = Package( .product(name: "Algorithms", package: "swift-algorithms"), ] ), + .macro( + name: "MockoloTestSupportMacros", + dependencies: [ + .product(name: "SwiftCompilerPlugin", package: "swift-syntax"), + .product(name: "SwiftDiagnostics", package: "swift-syntax"), + .product(name: "SwiftSyntaxMacros", package: "swift-syntax"), + ] + ), .testTarget( name: "MockoloTests", dependencies: [ "MockoloFramework", + "MockoloTestSupportMacros", ], path: "Tests" - ) + ), ] ) diff --git a/README.md b/README.md index 1143198c..5af8dbb7 100644 --- a/README.md +++ b/README.md @@ -21,9 +21,9 @@ This project may contain unstable APIs which may not be ready for general use. S ## System Requirements -* Swift 5.7 or later -* Xcode 14.2 or later -* macOS 12.0 or later and Linux +* Swift 5.10 or later +* Xcode 15.3 or later +* macOS 13.0 or later and Linux * Support is included for the Swift Package Manager @@ -424,11 +424,6 @@ This will generate: public class FooMock: FooProtocol { ... } ``` -## Used libraries - -[SwiftSyntax](https://github.com/apple/swift-syntax) | - - ## How to contribute to Mockolo See [CONTRIBUTING](CONTRIBUTING.md) for more info. diff --git a/Sources/Mockolo/Executor.swift b/Sources/Mockolo/Executor.swift index 189cfe5e..581469dc 100644 --- a/Sources/Mockolo/Executor.swift +++ b/Sources/Mockolo/Executor.swift @@ -214,10 +214,8 @@ struct Executor: ParsableCommand { excludeImports: excludeImports, to: outputFilePath, loggingLevel: loggingLevel, - concurrencyLimit: concurrencyLimit, - onCompletion: { _ in - log("Done. Exiting program.", level: .info) - }) + concurrencyLimit: concurrencyLimit) + log("Done. Exiting program.", level: .info) } catch { fatalError("Generation error: \(error)") } diff --git a/Sources/MockoloFramework/Operations/Generator.swift b/Sources/MockoloFramework/Operations/Generator.swift index 02af6d45..3da3fe41 100644 --- a/Sources/MockoloFramework/Operations/Generator.swift +++ b/Sources/MockoloFramework/Operations/Generator.swift @@ -23,6 +23,7 @@ enum InputError: Error { } /// Performs end to end mock generation flow +@discardableResult public func generate(sourceDirs: [String], sourceFiles: [String], parser: SourceParser, @@ -43,8 +44,7 @@ public func generate(sourceDirs: [String], excludeImports: [String], to outputFilePath: String, loggingLevel: Int, - concurrencyLimit: Int?, - onCompletion: @escaping (String) -> ()) throws { + concurrencyLimit: Int?) throws -> String { guard sourceDirs.count > 0 || sourceFiles.count > 0 else { log("Source files or directories do not exist", level: .error) throw InputError.sourceFilesError @@ -184,5 +184,5 @@ public func generate(sourceDirs: [String], log("TOTAL", t5-t0, level: .verbose) log("#Protocols = \(protocolMap.count), #Annotated protocols = \(annotatedProtocolMap.count), #Parent mock classes = \(parentMocks.count), #Final mock classes = \(candidates.count), File LoC = \(count)", level: .verbose) - onCompletion(result) + return result } diff --git a/Sources/MockoloTestSupportMacros/Fixture.swift b/Sources/MockoloTestSupportMacros/Fixture.swift new file mode 100644 index 00000000..9795c787 --- /dev/null +++ b/Sources/MockoloTestSupportMacros/Fixture.swift @@ -0,0 +1,49 @@ +import SwiftBasicFormat +import SwiftSyntax +import SwiftSyntaxMacros + +struct Fixture: MemberMacro { + static func expansion( + of node: AttributeSyntax, + providingMembersOf declaration: some DeclGroupSyntax, + conformingTo protocols: [TypeSyntax], + in context: some MacroExpansionContext + ) throws -> [DeclSyntax] { + let baseItems = declaration.memberBlock.members.filter { (item: MemberBlockItemSyntax) in + if let decl = item.decl.asProtocol(WithAttributesSyntax.self) { + let isFixtureAnnotated = decl.attributes.contains { (attr: AttributeListSyntax.Element) in + return attr.trimmedDescription == "@Fixture" + } + return !isFixtureAnnotated + } + return true + } + + let indent = BasicFormat.inferIndentation(of: declaration) ?? .spaces(4) + let sourceContent = baseItems.trimmedDescription(matching: \.isNewline) + + let varDecl = VariableDeclSyntax( + modifiers: [.init(name: .keyword(.static))], + .let, + name: "_source", + initializer: .init( + value: StringLiteralExprSyntax( + multilineContent: sourceContent, + endIndent: Trivia(pieces: node.leadingTrivia.filter(\.isSpaceOrTab)) + indent + ) + ) + ) + + return [DeclSyntax(varDecl)] + } +} + +extension StringLiteralExprSyntax { + fileprivate init(multilineContent: String, endIndent: Trivia) { + self = StringLiteralExprSyntax( + openingQuote: .multilineStringQuoteToken(), + segments: [.stringSegment(.init(content: .stringSegment(multilineContent)))], + closingQuote: .multilineStringQuoteToken(leadingTrivia: endIndent) + ) + } +} diff --git a/Sources/MockoloTestSupportMacros/MacroMain.swift b/Sources/MockoloTestSupportMacros/MacroMain.swift new file mode 100644 index 00000000..4ebb78cc --- /dev/null +++ b/Sources/MockoloTestSupportMacros/MacroMain.swift @@ -0,0 +1,8 @@ +import SwiftCompilerPlugin +import SwiftSyntaxMacros + +@main struct MacroMain: CompilerPlugin { + let providingMacros: [any Macro.Type] = [ + Fixture.self, + ] +} diff --git a/Tests/MockoloTestCase.swift b/Tests/MockoloTestCase.swift index 2edc9676..985af784 100644 --- a/Tests/MockoloTestCase.swift +++ b/Tests/MockoloTestCase.swift @@ -132,13 +132,14 @@ class MockoloTestCase: XCTestCase { excludeImports: [], to: dstFilePath, loggingLevel: 3, - concurrencyLimit: concurrencyLimit, - onCompletion: { ret in - let output = (try? String(contentsOf: URL(fileURLWithPath: self.defaultDstFilePath), encoding: .utf8)) ?? "" - let outputContents = output.components(separatedBy: .newlines).filter { !$0.isEmpty && !$0.allSatisfy(\.isWhitespace) } - let fixtureContents = dstContent.components(separatedBy: .newlines).filter { !$0.isEmpty && !$0.allSatisfy(\.isWhitespace) } - XCTAssert(outputContents.contains(subArray: fixtureContents), "output:\n" + output) - }) + concurrencyLimit: concurrencyLimit) + let output = (try? String(contentsOf: URL(fileURLWithPath: self.defaultDstFilePath), encoding: .utf8)) ?? "" + let outputContents = output.components(separatedBy: .newlines).filter { !$0.isEmpty && !$0.allSatisfy(\.isWhitespace) } + let fixtureContents = dstContent.components(separatedBy: .newlines).filter { !$0.isEmpty && !$0.allSatisfy(\.isWhitespace) } + if fixtureContents.isEmpty { + throw XCTSkip("empty fixture") + } + XCTAssert(outputContents.contains(subArray: fixtureContents), "output:\n" + output) } } diff --git a/Tests/TestActor/ActorTests.swift b/Tests/TestActor/ActorTests.swift index 2f195c84..3fb98818 100644 --- a/Tests/TestActor/ActorTests.swift +++ b/Tests/TestActor/ActorTests.swift @@ -1,22 +1,22 @@ final class ActorTests: MockoloTestCase { func testActorProtocol() { - verify(srcContent: actorProtocol, - dstContent: actorProtocolMock) + verify(srcContent: actorProtocol._source, + dstContent: actorProtocol.expected._source) } func testParentProtocolInheritsActor() { - verify(srcContent: parentProtocolInheritsActor, - dstContent: parentProtocolInheritsActorMock) + verify(srcContent: parentProtocolInheritsActor._source, + dstContent: parentProtocolInheritsActor.expected._source) } func testGlobalActorProtocol() { - verify(srcContent: globalActorProtocol, - dstContent: globalActorProtocolMock) + verify(srcContent: globalActorProtocol._source, + dstContent: globalActorProtocol.expected._source) } func testAttributeAboveAnnotationComment() { - verify(srcContent: attributeAboveAnnotationComment, - dstContent: attributeAboveAnnotationCommentMock, + verify(srcContent: attributeAboveAnnotationComment._source, + dstContent: attributeAboveAnnotationComment.expected._source, declType: .all) } } diff --git a/Tests/TestActor/FixtureActor.swift b/Tests/TestActor/FixtureActor.swift index 9e829710..45373500 100644 --- a/Tests/TestActor/FixtureActor.swift +++ b/Tests/TestActor/FixtureActor.swift @@ -1,63 +1,94 @@ -import MockoloFramework +@Fixture enum actorProtocol { + /// @mockable + protocol Foo: Actor { + func foo(arg: String) async -> Result + var bar: Int { get } + } -let actorProtocol = """ -/// \(String.mockAnnotation) -protocol Foo: Actor { - func foo(arg: String) async -> Result - var bar: Int { get } -} -""" - -let actorProtocolMock = """ -actor FooMock: Foo { - init() { } - init(bar: Int = 0) { - self.bar = bar - } - private(set) var fooCallCount = 0 - var fooHandler: ((String) async -> Result)? - func foo(arg: String) async -> Result { - fooCallCount += 1 - if let fooHandler = fooHandler { - return await fooHandler(arg) + @Fixture enum expected { + actor FooMock: Foo { + init() { } + init(bar: Int = 0) { + self.bar = bar + } + private(set) var fooCallCount = 0 + var fooHandler: ((String) async -> Result)? + func foo(arg: String) async -> Result { + fooCallCount += 1 + if let fooHandler = fooHandler { + return await fooHandler(arg) + } + fatalError("fooHandler returns can't have a default value thus its handler must be set") + } + + var bar: Int = 0 } - fatalError("fooHandler returns can't have a default value thus its handler must be set") } - - var bar: Int = 0 } -""" +@Fixture enum parentProtocolInheritsActor { + protocol Bar: Actor { + var bar: Int { get } + } + + /// @mockable + protocol Foo: Bar { + func baz(arg: String) async -> Int + } + + @Fixture enum expected { + actor FooMock: Foo { + init() { } + init(bar: Int = 0) { + self.bar = bar + } -let parentProtocolInheritsActor = """ -protocol Bar: Actor { - var bar: Int { get } -} -/// \(String.mockAnnotation) -protocol Foo: Bar { - func baz(arg: String) async -> Int + var bar: Int = 0 + + private(set) var bazCallCount = 0 + var bazHandler: ((String) async -> Int)? + func baz(arg: String) async -> Int { + bazCallCount += 1 + if let bazHandler = bazHandler { + return await bazHandler(arg) + } + return 0 + } + } + } } -""" -let parentProtocolInheritsActorMock = """ -actor FooMock: Foo { - init() { } - init(bar: Int = 0) { - self.bar = bar +@Fixture enum attributeAboveAnnotationComment { + @MainActor + /// @mockable + protocol P0 { } + @MainActor + /// @mockable + @available(iOS 18.0, *) protocol P1 { + } - var bar: Int = 0 + @MainActor + /// @mockable + public class C0 { + init() {} + } + + @Fixture enum expected { + class P0Mock: P0 { + init() { } + } + + class P1Mock: P1 { + init() { } + } - private(set) var bazCallCount = 0 - var bazHandler: ((String) async -> Int)? - func baz(arg: String) async -> Int { - bazCallCount += 1 - if let bazHandler = bazHandler { - return await bazHandler(arg) + public class C0Mock: C0 { + override init() { + super.init() + } } - return 0 } } -""" diff --git a/Tests/TestActor/FixtureGlobalActor.swift b/Tests/TestActor/FixtureGlobalActor.swift index fccebf1d..bbf47081 100644 --- a/Tests/TestActor/FixtureGlobalActor.swift +++ b/Tests/TestActor/FixtureGlobalActor.swift @@ -1,75 +1,41 @@ -import MockoloFramework - -let globalActorProtocol = """ -/// \(String.mockAnnotation) -@MainActor protocol RootController: AnyObject { - var viewController: UIViewController { get } -} - -/// \(String.mockAnnotation) -protocol RootBuildable { - func build() -> RootController -} -""" - -let globalActorProtocolMock = """ -class RootControllerMock: RootController { - init() { } - init(viewController: UIViewController) { - self._viewController = viewController +@Fixture enum globalActorProtocol { + /// @mockable + @MainActor protocol RootController: AnyObject { + var viewController: UIViewController { get } } - private var _viewController: UIViewController! - var viewController: UIViewController { - get { return _viewController } - set { _viewController = newValue } + /// @mockable + protocol RootBuildable { + func build() -> RootController } -} -class RootBuildableMock: RootBuildable { - init() { } - - - private(set) var buildCallCount = 0 - var buildHandler: (() -> RootController)? - func build() -> RootController { - buildCallCount += 1 - if let buildHandler = buildHandler { - return buildHandler() + @Fixture enum expected { + class RootControllerMock: RootController { + init() { } + init(viewController: UIViewController) { + self._viewController = viewController + } + + private var _viewController: UIViewController! + var viewController: UIViewController { + get { return _viewController } + set { _viewController = newValue } + } } - fatalError("buildHandler returns can't have a default value thus its handler must be set") - } -} -""" + class RootBuildableMock: RootBuildable { + init() { } -let attributeAboveAnnotationComment = """ -@MainActor -/// \(String.mockAnnotation) -protocol P0 { -} -@MainActor -/// \(String.mockAnnotation) -@available(iOS 18.0, *) protocol P1 { -} - -@MainActor -/// \(String.mockAnnotation) -public class C0 { -} -""" - -let attributeAboveAnnotationCommentMock = """ -class P0Mock: P0 { - init() { } -} - -class P1Mock: P1 { - init() { } -} - -public class C0Mock: C0 { - public init() { } + private(set) var buildCallCount = 0 + var buildHandler: (() -> RootController)? + func build() -> RootController { + buildCallCount += 1 + if let buildHandler = buildHandler { + return buildHandler() + } + fatalError("buildHandler returns can't have a default value thus its handler must be set") + } + } + } } -""" diff --git a/Tests/TestArgumentsHistory/ArgumentsHistoryTests.swift b/Tests/TestArgumentsHistory/ArgumentsHistoryTests.swift index a8ec5459..bccd480f 100644 --- a/Tests/TestArgumentsHistory/ArgumentsHistoryTests.swift +++ b/Tests/TestArgumentsHistory/ArgumentsHistoryTests.swift @@ -1,70 +1,69 @@ import Foundation -class ArgumentsHistoryTests: MockoloTestCase { - +class ArgumentsHistoryTests: MockoloTestCase { func testArgumentsHistoryWithAnnotationAllFuncCases() { - verify(srcContent: argumentsHistoryWithAnnotation, - dstContent: argumentsHistoryWithAnnotationAllFuncCaseMock, + verify(srcContent: argumentsHistoryWithAnnotation._source, + dstContent: argumentsHistoryWithAnnotation.expected._source, enableFuncArgsHistory: true) } func testArgumentsHistoryWithAnnotationNotAllFuncCases() { - verify(srcContent: argumentsHistoryWithAnnotation, - dstContent: argumentsHistoryWithAnnotationNotAllFuncCaseMock, + verify(srcContent: argumentsHistoryWithAnnotationNotAllFuncCase._source, + dstContent: argumentsHistoryWithAnnotationNotAllFuncCase.expected._source, enableFuncArgsHistory: false) } func testArgumentsHistorySimpleCase() { - verify(srcContent: argumentsHistorySimpleCase, - dstContent: argumentsHistorySimpleCaseMock, + verify(srcContent: argumentsHistorySimpleCase._source, + dstContent: argumentsHistorySimpleCase.expected._source, enableFuncArgsHistory: true) } func testArgumentsHistoryTupleCase() { - verify(srcContent: argumentsHistoryTupleCase, - dstContent: argumentsHistoryTupleCaseMock, + verify(srcContent: argumentsHistoryTupleCase._source, + dstContent: argumentsHistoryTupleCase.expected._source, enableFuncArgsHistory: true) } func testArgumentsHistoryOverloadedCase() { - verify(srcContent: argumentsHistoryOverloadedCase, - dstContent: argumentsHistoryOverloadedCaseMock, + verify(srcContent: argumentsHistoryOverloadedCase._source, + dstContent: argumentsHistoryOverloadedCase.expected._source, enableFuncArgsHistory: true) } func testArgumentsHistoryGenericsCase() { - verify(srcContent: argumentsHistoryGenericsCase, - dstContent: argumentsHistoryGenericsCaseMock, + verify(srcContent: argumentsHistoryGenericsCase._source, + dstContent: argumentsHistoryGenericsCase.expected._source, enableFuncArgsHistory: true) } func testArgumentsHistoryInoutCase() { - verify(srcContent: argumentsHistoryInoutCase, - dstContent: argumentsHistoryInoutCaseMock, + verify(srcContent: argumentsHistoryInoutCase._source, + dstContent: argumentsHistoryInoutCase.expected._source, enableFuncArgsHistory: true) } func testArgumentsHistoryHandlerCase() { - verify(srcContent: argumentsHistoryHandlerCase, - dstContent: argumentsHistoryHandlerCaseMock, + verify(srcContent: argumentsHistoryHandlerCase._source, + dstContent: argumentsHistoryHandlerCase.expected._source, enableFuncArgsHistory: true) } func testArgumentsHistoryEscapingTypealiasHandlerCase() { - verify(srcContent: argumentsHistoryEscapingTypealiasHandlerCase, - dstContent: argumentsHistoryEscapingTypealiasHandlerCaseMock, + verify(srcContent: argumentsHistoryEscapingTypealiasHandlerCase._source, + dstContent: argumentsHistoryEscapingTypealiasHandlerCase.expected._source, enableFuncArgsHistory: true) } func testArgumentsHistoryAutoclosureCase() { - verify(srcContent: argumentsHistoryAutoclosureCase, - dstContent: argumentsHistoryAutoclosureCaseMock, + verify(srcContent: argumentsHistoryAutoclosureCase._source, + dstContent: argumentsHistoryAutoclosureCase.expected._source, enableFuncArgsHistory: true) } func testArgumentsHistoryStaticCase() { - verify(srcContent: argumentsHistoryStaticCase, - dstContent: argumentsHistoryStaticCaseMock, + verify(srcContent: argumentsHistoryStaticCase._source, + dstContent: argumentsHistoryStaticCase.expected._source, enableFuncArgsHistory: true) } } diff --git a/Tests/TestArgumentsHistory/FixtureArgumentsHistory.swift b/Tests/TestArgumentsHistory/FixtureArgumentsHistory.swift index 0a32db58..8eca04e3 100644 --- a/Tests/TestArgumentsHistory/FixtureArgumentsHistory.swift +++ b/Tests/TestArgumentsHistory/FixtureArgumentsHistory.swift @@ -1,475 +1,479 @@ -import MockoloFramework - -let argumentsHistoryWithAnnotation = """ -/// \(String.mockAnnotation)(history: fooFunc = true; bazFunc = true) -protocol Foo { - func fooFunc(val: Int) - func barFunc(for: [Int]) - func bazFunc(arg: String, default: Float) -} -""" - -let argumentsHistoryWithAnnotationAllFuncCaseMock = """ -class FooMock: Foo { - init() { } - - - private(set) var fooFuncCallCount = 0 - var fooFuncArgValues = [Int]() - var fooFuncHandler: ((Int) -> ())? - func fooFunc(val: Int) { - fooFuncCallCount += 1 - fooFuncArgValues.append(val) - if let fooFuncHandler = fooFuncHandler { - fooFuncHandler(val) - } - +@Fixture enum argumentsHistoryWithAnnotation { + /// @mockable(history: fooFunc = true; bazFunc = true) + protocol Foo { + func fooFunc(val: Int) + func barFunc(for: [Int]) + func bazFunc(arg: String, default: Float) } - private(set) var barFuncCallCount = 0 - var barFuncArgValues = [[Int]]() - var barFuncHandler: (([Int]) -> ())? - func barFunc(for: [Int]) { - barFuncCallCount += 1 - barFuncArgValues.append(`for`) - if let barFuncHandler = barFuncHandler { - barFuncHandler(`for`) + @Fixture enum expected { + class FooMock: Foo { + init() { } + + + private(set) var fooFuncCallCount = 0 + var fooFuncArgValues = [Int]() + var fooFuncHandler: ((Int) -> ())? + func fooFunc(val: Int) { + fooFuncCallCount += 1 + fooFuncArgValues.append(val) + if let fooFuncHandler = fooFuncHandler { + fooFuncHandler(val) + } + } + + private(set) var barFuncCallCount = 0 + var barFuncArgValues = [[Int]]() + var barFuncHandler: (([Int]) -> ())? + func barFunc(for: [Int]) { + barFuncCallCount += 1 + barFuncArgValues.append(`for`) + if let barFuncHandler = barFuncHandler { + barFuncHandler(`for`) + } + } + + private(set) var bazFuncCallCount = 0 + var bazFuncArgValues = [(String, Float)]() + var bazFuncHandler: ((String, Float) -> ())? + func bazFunc(arg: String, default: Float) { + bazFuncCallCount += 1 + bazFuncArgValues.append((arg, `default`)) + if let bazFuncHandler = bazFuncHandler { + bazFuncHandler(arg, `default`) + } + } } - - } - - private(set) var bazFuncCallCount = 0 - var bazFuncArgValues = [(String, Float)]() - var bazFuncHandler: ((String, Float) -> ())? - func bazFunc(arg: String, default: Float) { - bazFuncCallCount += 1 - bazFuncArgValues.append((arg, `default`)) - if let bazFuncHandler = bazFuncHandler { - bazFuncHandler(arg, `default`) - } - } } -""" - -let argumentsHistoryWithAnnotationNotAllFuncCaseMock = """ -class FooMock: Foo { - init() { } - - - private(set) var fooFuncCallCount = 0 - var fooFuncArgValues = [Int]() - var fooFuncHandler: ((Int) -> ())? - func fooFunc(val: Int) { - fooFuncCallCount += 1 - fooFuncArgValues.append(val) - if let fooFuncHandler = fooFuncHandler { - fooFuncHandler(val) - } - +@Fixture enum argumentsHistoryWithAnnotationNotAllFuncCase { + /// @mockable(history: fooFunc = true; bazFunc = true) + protocol Foo { + func fooFunc(val: Int) + func barFunc(for: [Int]) + func bazFunc(arg: String, default: Float) } - private(set) var barFuncCallCount = 0 - var barFuncHandler: (([Int]) -> ())? - func barFunc(for: [Int]) { - barFuncCallCount += 1 - if let barFuncHandler = barFuncHandler { - barFuncHandler(`for`) + @Fixture enum expected { + class FooMock: Foo { + init() { } + + + private(set) var fooFuncCallCount = 0 + var fooFuncArgValues = [Int]() + var fooFuncHandler: ((Int) -> ())? + func fooFunc(val: Int) { + fooFuncCallCount += 1 + fooFuncArgValues.append(val) + if let fooFuncHandler = fooFuncHandler { + fooFuncHandler(val) + } + + } + + private(set) var barFuncCallCount = 0 + var barFuncHandler: (([Int]) -> ())? + func barFunc(for: [Int]) { + barFuncCallCount += 1 + if let barFuncHandler = barFuncHandler { + barFuncHandler(`for`) + } + + } + + private(set) var bazFuncCallCount = 0 + var bazFuncArgValues = [(String, Float)]() + var bazFuncHandler: ((String, Float) -> ())? + func bazFunc(arg: String, default: Float) { + bazFuncCallCount += 1 + bazFuncArgValues.append((arg, `default`)) + if let bazFuncHandler = bazFuncHandler { + bazFuncHandler(arg, `default`) + } + + } } - } - - private(set) var bazFuncCallCount = 0 - var bazFuncArgValues = [(String, Float)]() - var bazFuncHandler: ((String, Float) -> ())? - func bazFunc(arg: String, default: Float) { - bazFuncCallCount += 1 - bazFuncArgValues.append((arg, `default`)) - if let bazFuncHandler = bazFuncHandler { - bazFuncHandler(arg, `default`) - } - - } -} - -""" - -let argumentsHistorySimpleCase = """ -/// \(String.mockAnnotation) -protocol Foo { - func fooFunc() - func barFunc(val: Int) - func bazFunc(_ val: Int) - func quxFunc(val: Int) -> String - func quuxFunc(val1: String, val2: Float) } -""" - -let argumentsHistorySimpleCaseMock = """ -class FooMock: Foo { - init() { } - - private(set) var fooFuncCallCount = 0 - var fooFuncHandler: (() -> ())? - func fooFunc() { - fooFuncCallCount += 1 - - if let fooFuncHandler = fooFuncHandler { - fooFuncHandler() - } - } - - private(set) var barFuncCallCount = 0 - var barFuncArgValues = [Int]() - var barFuncHandler: ((Int) -> ())? - func barFunc(val: Int) { - barFuncCallCount += 1 - barFuncArgValues.append(val) - - if let barFuncHandler = barFuncHandler { - barFuncHandler(val) - } - } - private(set) var bazFuncCallCount = 0 - var bazFuncArgValues = [Int]() - var bazFuncHandler: ((Int) -> ())? - func bazFunc(_ val: Int) { - bazFuncCallCount += 1 - bazFuncArgValues.append(val) - - if let bazFuncHandler = bazFuncHandler { - bazFuncHandler(val) - } +@Fixture enum argumentsHistorySimpleCase { + /// @mockable + protocol Foo { + func fooFunc() + func barFunc(val: Int) + func bazFunc(_ val: Int) + func quxFunc(val: Int) -> String + func quuxFunc(val1: String, val2: Float) } - private(set) var quxFuncCallCount = 0 - var quxFuncArgValues = [Int]() - var quxFuncHandler: ((Int) -> String)? - func quxFunc(val: Int) -> String { - quxFuncCallCount += 1 - quxFuncArgValues.append(val) - - if let quxFuncHandler = quxFuncHandler { - return quxFuncHandler(val) - } - return "" - } - - private(set) var quuxFuncCallCount = 0 - var quuxFuncArgValues = [(String, Float)]() - var quuxFuncHandler: ((String, Float) -> ())? - func quuxFunc(val1: String, val2: Float) { - quuxFuncCallCount += 1 - quuxFuncArgValues.append((val1, val2)) - - if let quuxFuncHandler = quuxFuncHandler { - quuxFuncHandler(val1, val2) + @Fixture enum expected { + class FooMock: Foo { + init() { } + + private(set) var fooFuncCallCount = 0 + var fooFuncHandler: (() -> ())? + func fooFunc() { + fooFuncCallCount += 1 + + if let fooFuncHandler = fooFuncHandler { + fooFuncHandler() + } + } + + private(set) var barFuncCallCount = 0 + var barFuncArgValues = [Int]() + var barFuncHandler: ((Int) -> ())? + func barFunc(val: Int) { + barFuncCallCount += 1 + barFuncArgValues.append(val) + + if let barFuncHandler = barFuncHandler { + barFuncHandler(val) + } + } + + private(set) var bazFuncCallCount = 0 + var bazFuncArgValues = [Int]() + var bazFuncHandler: ((Int) -> ())? + func bazFunc(_ val: Int) { + bazFuncCallCount += 1 + bazFuncArgValues.append(val) + + if let bazFuncHandler = bazFuncHandler { + bazFuncHandler(val) + } + } + + private(set) var quxFuncCallCount = 0 + var quxFuncArgValues = [Int]() + var quxFuncHandler: ((Int) -> String)? + func quxFunc(val: Int) -> String { + quxFuncCallCount += 1 + quxFuncArgValues.append(val) + + if let quxFuncHandler = quxFuncHandler { + return quxFuncHandler(val) + } + return "" + } + + private(set) var quuxFuncCallCount = 0 + var quuxFuncArgValues = [(String, Float)]() + var quuxFuncHandler: ((String, Float) -> ())? + func quuxFunc(val1: String, val2: Float) { + quuxFuncCallCount += 1 + quuxFuncArgValues.append((val1, val2)) + + if let quuxFuncHandler = quuxFuncHandler { + quuxFuncHandler(val1, val2) + } + } } } } -""" -let argumentsHistoryTupleCase = """ -/// \(String.mockAnnotation)(history: fooFunc = true) -protocol Foo { - func fooFunc(val: (Int, String)) - func barFunc(val1: (bar1: Int, String), val2: (bar3: Int, bar4: String)) -} +let argumentsHistorySimpleCaseMock = """ """ -let argumentsHistoryTupleCaseMock = """ -class FooMock: Foo { - init() { } - - private(set) var fooFuncCallCount = 0 - var fooFuncArgValues = [(Int, String)]() - var fooFuncHandler: (((Int, String)) -> ())? - func fooFunc(val: (Int, String)) { - fooFuncCallCount += 1 - fooFuncArgValues.append(val) - - if let fooFuncHandler = fooFuncHandler { - fooFuncHandler(val) - } +@Fixture enum argumentsHistoryTupleCase { + /// @mockable(history: fooFunc = true) + protocol Foo { + func fooFunc(val: (Int, String)) + func barFunc(val1: (bar1: Int, String), val2: (bar3: Int, bar4: String)) } - private(set) var barFuncCallCount = 0 - var barFuncArgValues = [((bar1: Int, String), (bar3: Int, bar4: String))]() - var barFuncHandler: (((bar1: Int, String), (bar3: Int, bar4: String)) -> ())? - func barFunc(val1: (bar1: Int, String), val2: (bar3: Int, bar4: String)) { - barFuncCallCount += 1 - barFuncArgValues.append((val1, val2)) - - if let barFuncHandler = barFuncHandler { - barFuncHandler(val1, val2) + @Fixture enum expected { + class FooMock: Foo { + init() { } + + private(set) var fooFuncCallCount = 0 + var fooFuncArgValues = [(Int, String)]() + var fooFuncHandler: (((Int, String)) -> ())? + func fooFunc(val: (Int, String)) { + fooFuncCallCount += 1 + fooFuncArgValues.append(val) + + if let fooFuncHandler = fooFuncHandler { + fooFuncHandler(val) + } + } + + private(set) var barFuncCallCount = 0 + var barFuncArgValues = [((bar1: Int, String), (bar3: Int, bar4: String))]() + var barFuncHandler: (((bar1: Int, String), (bar3: Int, bar4: String)) -> ())? + func barFunc(val1: (bar1: Int, String), val2: (bar3: Int, bar4: String)) { + barFuncCallCount += 1 + barFuncArgValues.append((val1, val2)) + + if let barFuncHandler = barFuncHandler { + barFuncHandler(val1, val2) + } + } } } } -""" - -let argumentsHistoryOverloadedCase = """ -/// \(String.mockAnnotation) -protocol Foo { - func fooFunc() - func fooFunc(val1: Int) - func fooFunc(val1: String) - func fooFunc(val2: Int) -} -""" -let argumentsHistoryOverloadedCaseMock = """ -class FooMock: Foo { - init() { } - - private(set) var fooFuncCallCount = 0 - var fooFuncHandler: (() -> ())? - func fooFunc() { - fooFuncCallCount += 1 - - if let fooFuncHandler = fooFuncHandler { - fooFuncHandler() - } +@Fixture enum argumentsHistoryOverloadedCase { + /// @mockable + protocol Foo { + func fooFunc() + func fooFunc(val1: Int) + func fooFunc(val1: String) + func fooFunc(val2: Int) } - private(set) var fooFuncVal1CallCount = 0 - var fooFuncVal1ArgValues = [Int]() - var fooFuncVal1Handler: ((Int) -> ())? - func fooFunc(val1: Int) { - fooFuncVal1CallCount += 1 - fooFuncVal1ArgValues.append(val1) - - if let fooFuncVal1Handler = fooFuncVal1Handler { - fooFuncVal1Handler(val1) + @Fixture enum expected { + class FooMock: Foo { + init() { } + + private(set) var fooFuncCallCount = 0 + var fooFuncHandler: (() -> ())? + func fooFunc() { + fooFuncCallCount += 1 + + if let fooFuncHandler = fooFuncHandler { + fooFuncHandler() + } + } + + private(set) var fooFuncVal1CallCount = 0 + var fooFuncVal1ArgValues = [Int]() + var fooFuncVal1Handler: ((Int) -> ())? + func fooFunc(val1: Int) { + fooFuncVal1CallCount += 1 + fooFuncVal1ArgValues.append(val1) + + if let fooFuncVal1Handler = fooFuncVal1Handler { + fooFuncVal1Handler(val1) + } + + } + + private(set) var fooFuncVal1StringCallCount = 0 + var fooFuncVal1StringArgValues = [String]() + var fooFuncVal1StringHandler: ((String) -> ())? + func fooFunc(val1: String) { + fooFuncVal1StringCallCount += 1 + fooFuncVal1StringArgValues.append(val1) + + if let fooFuncVal1StringHandler = fooFuncVal1StringHandler { + fooFuncVal1StringHandler(val1) + } + } + + private(set) var fooFuncVal2CallCount = 0 + var fooFuncVal2ArgValues = [Int]() + var fooFuncVal2Handler: ((Int) -> ())? + func fooFunc(val2: Int) { + fooFuncVal2CallCount += 1 + fooFuncVal2ArgValues.append(val2) + + if let fooFuncVal2Handler = fooFuncVal2Handler { + fooFuncVal2Handler(val2) + } + } } - } +} - private(set) var fooFuncVal1StringCallCount = 0 - var fooFuncVal1StringArgValues = [String]() - var fooFuncVal1StringHandler: ((String) -> ())? - func fooFunc(val1: String) { - fooFuncVal1StringCallCount += 1 - fooFuncVal1StringArgValues.append(val1) - - if let fooFuncVal1StringHandler = fooFuncVal1StringHandler { - fooFuncVal1StringHandler(val1) - } +@Fixture enum argumentsHistoryGenericsCase { + /// @mockable + protocol Foo { + func fooFunc(val1: T, val2: T?) + func barFunc(val: T) -> U } - private(set) var fooFuncVal2CallCount = 0 - var fooFuncVal2ArgValues = [Int]() - var fooFuncVal2Handler: ((Int) -> ())? - func fooFunc(val2: Int) { - fooFuncVal2CallCount += 1 - fooFuncVal2ArgValues.append(val2) - - if let fooFuncVal2Handler = fooFuncVal2Handler { - fooFuncVal2Handler(val2) + @Fixture enum expected { + class FooMock: Foo { + init() { } + + private(set) var fooFuncCallCount = 0 + var fooFuncArgValues = [(Any, Any?)]() + var fooFuncHandler: ((Any, Any?) -> ())? + func fooFunc(val1: T, val2: T?) { + fooFuncCallCount += 1 + fooFuncArgValues.append((val1, val2)) + + if let fooFuncHandler = fooFuncHandler { + fooFuncHandler(val1, val2) + } + } + + private(set) var barFuncCallCount = 0 + var barFuncArgValues = [Any]() + var barFuncHandler: ((Any) -> Any)? + func barFunc(val: T) -> U { + barFuncCallCount += 1 + barFuncArgValues.append(val) + + if let barFuncHandler = barFuncHandler { + return barFuncHandler(val) as! U + } + fatalError("barFuncHandler returns can't have a default value thus its handler must be set") + } } } } -""" - -let argumentsHistoryGenericsCase = """ -/// \(String.mockAnnotation) -protocol Foo { - func fooFunc(val1: T, val2: T?) - func barFunc(val: T) -> U -} -""" - -let argumentsHistoryGenericsCaseMock = """ -class FooMock: Foo { - init() { } - - private(set) var fooFuncCallCount = 0 - var fooFuncArgValues = [(Any, Any?)]() - var fooFuncHandler: ((Any, Any?) -> ())? - func fooFunc(val1: T, val2: T?) { - fooFuncCallCount += 1 - fooFuncArgValues.append((val1, val2)) - if let fooFuncHandler = fooFuncHandler { - fooFuncHandler(val1, val2) - } +@Fixture enum argumentsHistoryInoutCase { + /// @mockable + protocol Foo { + func fooFunc(val: inout Int) + func barFunc(into val: inout Int) } - private(set) var barFuncCallCount = 0 - var barFuncArgValues = [Any]() - var barFuncHandler: ((Any) -> Any)? - func barFunc(val: T) -> U { - barFuncCallCount += 1 - barFuncArgValues.append(val) - - if let barFuncHandler = barFuncHandler { - return barFuncHandler(val) as! U + @Fixture enum expected { + class FooMock: Foo { + init() { } + + + private(set) var fooFuncCallCount = 0 + var fooFuncArgValues = [Int]() + var fooFuncHandler: ((inout Int) -> ())? + func fooFunc(val: inout Int) { + fooFuncCallCount += 1 + fooFuncArgValues.append(val) + if let fooFuncHandler = fooFuncHandler { + fooFuncHandler(&val) + } + + } + + private(set) var barFuncCallCount = 0 + var barFuncArgValues = [Int]() + var barFuncHandler: ((inout Int) -> ())? + func barFunc(into val: inout Int) { + barFuncCallCount += 1 + barFuncArgValues.append(val) + if let barFuncHandler = barFuncHandler { + barFuncHandler(&val) + } + + } } - fatalError("barFuncHandler returns can't have a default value thus its handler must be set") } } -""" - -let argumentsHistoryInoutCase = """ -/// \(String.mockAnnotation) -protocol Foo { - func fooFunc(val: inout Int) - func barFunc(into val: inout Int) -} -""" - -let argumentsHistoryInoutCaseMock = """ -class FooMock: Foo { - init() { } - - private(set) var fooFuncCallCount = 0 - var fooFuncArgValues = [Int]() - var fooFuncHandler: ((inout Int) -> ())? - func fooFunc(val: inout Int) { - fooFuncCallCount += 1 - fooFuncArgValues.append(val) - if let fooFuncHandler = fooFuncHandler { - fooFuncHandler(&val) - } - +@Fixture enum argumentsHistoryHandlerCase { + /// @mockable + protocol Foo { + func fooFunc(handler: () -> Int) + func barFunc(val: Int, handler: (String) -> Void) } - private(set) var barFuncCallCount = 0 - var barFuncArgValues = [Int]() - var barFuncHandler: ((inout Int) -> ())? - func barFunc(into val: inout Int) { - barFuncCallCount += 1 - barFuncArgValues.append(val) - if let barFuncHandler = barFuncHandler { - barFuncHandler(&val) + @Fixture enum expected { + class FooMock: Foo { + init() { } + + private(set) var fooFuncCallCount = 0 + var fooFuncHandler: ((() -> Int) -> ())? + func fooFunc(handler: () -> Int) { + fooFuncCallCount += 1 + + if let fooFuncHandler = fooFuncHandler { + fooFuncHandler(handler) + } + } + + private(set) var barFuncCallCount = 0 + var barFuncArgValues = [Int]() + var barFuncHandler: ((Int, (String) -> Void) -> ())? + func barFunc(val: Int, handler: (String) -> Void) { + barFuncCallCount += 1 + barFuncArgValues.append(val) + + if let barFuncHandler = barFuncHandler { + barFuncHandler(val, handler) + } + } } - } } -""" - -let argumentsHistoryHandlerCase = """ -/// \(String.mockAnnotation) -protocol Foo { - func fooFunc(handler: () -> Int) - func barFunc(val: Int, handler: (String) -> Void) -} -""" -let argumentsHistoryHandlerCaseMock = """ -class FooMock: Foo { - init() { } +@Fixture enum argumentsHistoryEscapingTypealiasHandlerCase { + typealias FooHandler = () -> Int + typealias BarHandler = (String) -> Void - private(set) var fooFuncCallCount = 0 - var fooFuncHandler: ((() -> Int) -> ())? - func fooFunc(handler: () -> Int) { - fooFuncCallCount += 1 - - if let fooFuncHandler = fooFuncHandler { - fooFuncHandler(handler) - } + /// @mockable + protocol Foo { + func fooFunc(handler: @escaping FooHandler) + func barFunc(val: Int, handler: @escaping BarHandler) } - private(set) var barFuncCallCount = 0 - var barFuncArgValues = [Int]() - var barFuncHandler: ((Int, (String) -> Void) -> ())? - func barFunc(val: Int, handler: (String) -> Void) { - barFuncCallCount += 1 - barFuncArgValues.append(val) - - if let barFuncHandler = barFuncHandler { - barFuncHandler(val, handler) + @Fixture enum expected { + class FooMock: Foo { + init() { } + + private(set) var fooFuncCallCount = 0 + var fooFuncHandler: ((@escaping FooHandler) -> ())? + func fooFunc(handler: @escaping FooHandler) { + fooFuncCallCount += 1 + + if let fooFuncHandler = fooFuncHandler { + fooFuncHandler(handler) + } + } + + private(set) var barFuncCallCount = 0 + var barFuncArgValues = [Int]() + var barFuncHandler: ((Int, @escaping BarHandler) -> ())? + func barFunc(val: Int, handler: @escaping BarHandler) { + barFuncCallCount += 1 + barFuncArgValues.append(val) + + if let barFuncHandler = barFuncHandler { + barFuncHandler(val, handler) + } + } } } } -""" -let argumentsHistoryEscapingTypealiasHandlerCase = """ -typealias FooHandler = () -> Int -typealias BarHandler = (String) -> Void - -/// \(String.mockAnnotation) -protocol Foo { - func fooFunc(handler: @escaping FooHandler) - func barFunc(val: Int, handler: @escaping BarHandler) -} -""" - -let argumentsHistoryEscapingTypealiasHandlerCaseMock = """ -class FooMock: Foo { - init() { } - - private(set) var fooFuncCallCount = 0 - var fooFuncHandler: ((@escaping FooHandler) -> ())? - func fooFunc(handler: @escaping FooHandler) { - fooFuncCallCount += 1 - - if let fooFuncHandler = fooFuncHandler { - fooFuncHandler(handler) - } +@Fixture enum argumentsHistoryAutoclosureCase { + /// @mockable + protocol Foo { + func fooFunc(handler: @autoclosure () -> Int) } - private(set) var barFuncCallCount = 0 - var barFuncArgValues = [Int]() - var barFuncHandler: ((Int, @escaping BarHandler) -> ())? - func barFunc(val: Int, handler: @escaping BarHandler) { - barFuncCallCount += 1 - barFuncArgValues.append(val) - - if let barFuncHandler = barFuncHandler { - barFuncHandler(val, handler) - } - } -} -""" + @Fixture enum expected { + class FooMock: Foo { + init() { } -let argumentsHistoryAutoclosureCase = """ -/// \(String.mockAnnotation) -protocol Foo { - func fooFunc(handler: @autoclosure () -> Int) -} -""" + private(set) var fooFuncCallCount = 0 + var fooFuncHandler: ((@autoclosure () -> Int) -> ())? + func fooFunc(handler: @autoclosure () -> Int) { + fooFuncCallCount += 1 -let argumentsHistoryAutoclosureCaseMock = """ -class FooMock: Foo { - init() { } - - private(set) var fooFuncCallCount = 0 - var fooFuncHandler: ((@autoclosure () -> Int) -> ())? - func fooFunc(handler: @autoclosure () -> Int) { - fooFuncCallCount += 1 - - if let fooFuncHandler = fooFuncHandler { - fooFuncHandler(handler()) + if let fooFuncHandler = fooFuncHandler { + fooFuncHandler(handler()) + } + } } } } -""" - -let argumentsHistoryStaticCase = """ -/// \(String.mockAnnotation) -protocol Foo { - static func fooFunc(val: Int) -} -""" - -let argumentsHistoryStaticCaseMock = """ -class FooMock: Foo { - init() { } - - static private(set) var fooFuncCallCount = 0 - static var fooFuncArgValues = [Int]() - static var fooFuncHandler: ((Int) -> ())? - static func fooFunc(val: Int) { - fooFuncCallCount += 1 - fooFuncArgValues.append(val) +@Fixture enum argumentsHistoryStaticCase { + /// @mockable + protocol Foo { + static func fooFunc(val: Int) + } - if let fooFuncHandler = fooFuncHandler { - fooFuncHandler(val) + @Fixture enum expected { + class FooMock: Foo { + init() { } + + static private(set) var fooFuncCallCount = 0 + static var fooFuncArgValues = [Int]() + static var fooFuncHandler: ((Int) -> ())? + static func fooFunc(val: Int) { + fooFuncCallCount += 1 + fooFuncArgValues.append(val) + + if let fooFuncHandler = fooFuncHandler { + fooFuncHandler(val) + } + } } } } -""" diff --git a/Tests/TestClassMocking/FixtureMockableClass.swift b/Tests/TestClassMocking/FixtureMockableClass.swift index a146c71a..4f03bc28 100644 --- a/Tests/TestClassMocking/FixtureMockableClass.swift +++ b/Tests/TestClassMocking/FixtureMockableClass.swift @@ -2,7 +2,7 @@ import MockoloFramework let klass = """ -/// \(String.mockAnnotation) +/// @mockable public class Low: Mid { var name: String = "k2" diff --git a/Tests/TestClassMocking/FixtureMockableClassInit.swift b/Tests/TestClassMocking/FixtureMockableClassInit.swift index 13158a24..32a1f692 100644 --- a/Tests/TestClassMocking/FixtureMockableClassInit.swift +++ b/Tests/TestClassMocking/FixtureMockableClassInit.swift @@ -2,7 +2,7 @@ import MockoloFramework let klassInit = """ -/// \(String.mockAnnotation) +/// @mockable public class Low: Mid { var name: String = "" public required init(arg: String) { diff --git a/Tests/TestCombine/FixtureCombine.swift b/Tests/TestCombine/FixtureCombine.swift index d0368a4c..d5bce6a5 100644 --- a/Tests/TestCombine/FixtureCombine.swift +++ b/Tests/TestCombine/FixtureCombine.swift @@ -1,7 +1,7 @@ import MockoloFramework let combineProtocol = """ -/// \(String.mockAnnotation)(combine: dictionaryPublisher = CurrentValueSubject; myPublisher = PassthroughSubject; noDefaultSubjectValue = CurrentValueSubject) +/// @mockable(combine: dictionaryPublisher = CurrentValueSubject; myPublisher = PassthroughSubject; noDefaultSubjectValue = CurrentValueSubject) public protocol Foo: AnyObject { var myPublisher: AnyPublisher { get } var dictionaryPublisher: AnyPublisher, Never> { get } @@ -25,7 +25,7 @@ public class FooMock: Foo { """ let combinePublishedProtocol = """ -/// \(String.mockAnnotation)(combine: myStringPublisher = @Published myString; myIntPublisher = @Published myInt; myCustomTypePublisher = @Published myCustomType; myNonOptionalPublisher = @CustomPropertyWrapper myNonOptional) +/// @mockable(combine: myStringPublisher = @Published myString; myIntPublisher = @Published myInt; myCustomTypePublisher = @Published myCustomType; myNonOptionalPublisher = @CustomPropertyWrapper myNonOptional) public protocol FooPublished { var myString: String { get set } var myStringPublisher: AnyPublisher { get } @@ -67,7 +67,7 @@ public class FooPublishedMock: FooPublished { """ let combineNullableProtocol = """ -/// \(String.mockAnnotation)(combine: myStringPublisher = @Published myString; myIntPublisher = @Published myInt; myCustomTypePublisher = @Published myCustomType; myNonOptionalPublisher = @Published myNonOptional) +/// @mockable(combine: myStringPublisher = @Published myString; myIntPublisher = @Published myInt; myCustomTypePublisher = @Published myCustomType; myNonOptionalPublisher = @Published myNonOptional) public protocol FooNullable { var myString: String? { get set } var myStringPublisher: AnyPublisher { get } @@ -115,18 +115,18 @@ public class FooNullableMock: FooNullable { let combineMultiParents = """ -/// \(String.mockAnnotation) +/// @mockable public protocol BaseProtocolA { var myStringInBase: String { get set } } -/// \(String.mockAnnotation)(combine: myIntPublisher = @Published myInt) +/// @mockable(combine: myIntPublisher = @Published myInt) public protocol BaseProtocolB { var myIntPublisher: AnyPublisher { get } var myOtherPublisher: AnyPublisher { get } } -/// \(String.mockAnnotation)(combine: myStringPublisher = @Published myStringInBase) +/// @mockable(combine: myStringPublisher = @Published myStringInBase) public protocol Child: BaseProtocolA, BaseProtocolB { var myStringPublisher: AnyPublisher { get } var myInt: Int { get set } @@ -181,7 +181,7 @@ public class ChildMock: Child { """ let combineMockContentProtocol = """ -/// \(String.mockAnnotation)(combine: myStringPublisher = @Published myStringInBase) +/// @mockable(combine: myStringPublisher = @Published myStringInBase) public protocol Child: BaseProtocolA { var myStringPublisher: AnyPublisher { get } } diff --git a/Tests/TestDocComments/FixtureDocComment.swift b/Tests/TestDocComments/FixtureDocComment.swift index 6bcdd127..89d82e24 100644 --- a/Tests/TestDocComments/FixtureDocComment.swift +++ b/Tests/TestDocComments/FixtureDocComment.swift @@ -13,7 +13,7 @@ import Foundation * and types that conform to this protocol * and also contains the mock annotation * in this comment. - * \(String.mockAnnotation) + * @mockable */ public protocol DocProtocol: Doc { func foo(arg: Bool, tag: Int) @@ -36,7 +36,7 @@ import Foundation * and also contains the mock annotation * in this comment. */ -/// \(String.mockAnnotation) +/// @mockable public protocol DocProtocol { func foo(arg: Bool, tag: Int) func bar(name: String, more: Float) diff --git a/Tests/TestEmojis/FixtureEmojis.swift b/Tests/TestEmojis/FixtureEmojis.swift index abae51ca..8a528593 100644 --- a/Tests/TestEmojis/FixtureEmojis.swift +++ b/Tests/TestEmojis/FixtureEmojis.swift @@ -2,7 +2,7 @@ import MockoloFramework let emojiVars = """ -/// \(String.mockAnnotation) +/// @mockable protocol EmojiVars: EmojiParent { @available(iOS 10.0, *) var 😂: Emoji { get set } @@ -101,7 +101,7 @@ class EmojiVarsMock: EmojiVars { let familyEmoji = """ -/// \(String.mockAnnotation) +/// @mockable protocol Family: FamilyEmoji { var 안녕하세요: String { get set } } @@ -159,7 +159,7 @@ class FamilyMock: Family { let krJp = """ -/// \(String.mockAnnotation) +/// @mockable protocol Hello: Hi { var 天気: String { get set } } diff --git a/Tests/TestExistentialAny/FixtureExistentialAny.swift b/Tests/TestExistentialAny/FixtureExistentialAny.swift index e8bc7378..420114ec 100644 --- a/Tests/TestExistentialAny/FixtureExistentialAny.swift +++ b/Tests/TestExistentialAny/FixtureExistentialAny.swift @@ -1,5 +1,5 @@ let existentialAny = """ -/// \(String.mockAnnotation) +/// @mockable protocol ExistentialAny { var foo: P { get } var bar: any R { get } @@ -95,11 +95,11 @@ class ExistentialAnyMock: ExistentialAny { """ let existentialAnyDefaultTypeMap = """ -/// \(String.mockAnnotation) +/// @mockable protocol SomeProtocol { } -/// \(String.mockAnnotation) +/// @mockable protocol UseSomeProtocol { func foo() -> any SomeProtocol } diff --git a/Tests/TestFuncs/TestBasicFuncs/FixtureNonSimpleFuncs.swift b/Tests/TestFuncs/TestBasicFuncs/FixtureNonSimpleFuncs.swift index e352aa64..166ed32b 100644 --- a/Tests/TestFuncs/TestBasicFuncs/FixtureNonSimpleFuncs.swift +++ b/Tests/TestFuncs/TestBasicFuncs/FixtureNonSimpleFuncs.swift @@ -1,546 +1,501 @@ import MockoloFramework -let inoutParams = """ -/// \(String.mockAnnotation) -public protocol Foo { - func hash(into hasher: inout Hasher) - func bar(lhs: inout String, rhs: inout Int) -} -""" - -let inoutParamsMock = """ - - - -public class FooMock: Foo { - public init() { } - - - public private(set) var hashCallCount = 0 - public var hashHandler: ((inout Hasher) -> ())? - public func hash(into hasher: inout Hasher) { - hashCallCount += 1 - if let hashHandler = hashHandler { - hashHandler(&hasher) - } - - } - - public private(set) var barCallCount = 0 - public var barHandler: ((inout String, inout Int) -> ())? - public func bar(lhs: inout String, rhs: inout Int) { - barCallCount += 1 - if let barHandler = barHandler { - barHandler(&lhs, &rhs) - } - - } -} - -""" - -let subscripts = """ - -/// \(String.mockAnnotation) -protocol SubscriptProtocol { - associatedtype T - associatedtype Value - - static subscript(key: Int) -> AnyObject? { get set } - subscript(_ key: Int) -> AnyObject { get set } - subscript(key: Int) -> AnyObject? { get set } - subscript(index: String) -> CGImage? { get set } - subscript(memoizeKey: Int) -> CGRect? { get set } - subscript(position: Int) -> Any { get set } - subscript(index: String.Index) -> Double { get set } - subscript(safe index: String.Index) -> Double? { get set } - subscript(range: Range) -> String { get set } - subscript(path: String) -> ((Double) -> Float)? { get set } - subscript(dynamicMember keyPath: ReferenceWritableKeyPath) -> T { get set } - subscript(dynamicMember keyPath: ReferenceWritableKeyPath) -> T { get set } - subscript(dynamicMember keyPath: WritableKeyPath) -> Value { get set } - subscript(_ parameter: T) -> T { get set } - subscript(keyPath: ReferenceWritableKeyPath) -> Array { get set } - subscript(keyPath: ReferenceWritableKeyPath, on schedulerType: T) -> Array { get set } -} - -/// \(String.mockAnnotation) -public protocol KeyValueSubscripting { - associatedtype Key - associatedtype Value - - /// Accesses the value associated with the given key for reading and writing. - subscript(key: Key) -> Value? { get set } - - /// Accesses the value with the given key. If the receiver doesn’t contain the given key, accesses the provided default value as if the key and default value existed in the receiver. - subscript(key: Key, default defaultValue: @autoclosure () -> Value) -> Value { get set } -} -""" - - -let subscriptsMocks = """ -class SubscriptProtocolMock: SubscriptProtocol { - init() { } - - typealias T = Any - typealias Value = Any - - static private(set) var subscriptCallCount = 0 - static var subscriptHandler: ((Int) -> AnyObject?)? - static subscript(key: Int) -> AnyObject? { - get { - subscriptCallCount += 1 - if let subscriptHandler = subscriptHandler { - return subscriptHandler(key) - } - return nil - } - set { } - } - - private(set) var subscriptKeyCallCount = 0 - var subscriptKeyHandler: ((Int) -> AnyObject)? - subscript(_ key: Int) -> AnyObject { - get { - subscriptKeyCallCount += 1 - if let subscriptKeyHandler = subscriptKeyHandler { - return subscriptKeyHandler(key) - } - fatalError("subscriptKeyHandler returns can't have a default value thus its handler must be set") - } - set { } - } - - private(set) var subscriptKeyIntCallCount = 0 - var subscriptKeyIntHandler: ((Int) -> AnyObject?)? - subscript(key: Int) -> AnyObject? { - get { - subscriptKeyIntCallCount += 1 - if let subscriptKeyIntHandler = subscriptKeyIntHandler { - return subscriptKeyIntHandler(key) - } - return nil - } - set { } - } - - private(set) var subscriptIndexCallCount = 0 - var subscriptIndexHandler: ((String) -> CGImage?)? - subscript(index: String) -> CGImage? { - get { - subscriptIndexCallCount += 1 - if let subscriptIndexHandler = subscriptIndexHandler { - return subscriptIndexHandler(index) - } - return nil - } - set { } +@Fixture enum inoutParams { + /// @mockable + public protocol Foo { + func hash(into hasher: inout Hasher) + func bar(lhs: inout String, rhs: inout Int) } - private(set) var subscriptMemoizeKeyCallCount = 0 - var subscriptMemoizeKeyHandler: ((Int) -> CGRect?)? - subscript(memoizeKey: Int) -> CGRect? { - get { - subscriptMemoizeKeyCallCount += 1 - if let subscriptMemoizeKeyHandler = subscriptMemoizeKeyHandler { - return subscriptMemoizeKeyHandler(memoizeKey) - } - return nil - } - set { } - } + @Fixture enum expected { + public class FooMock: Foo { + public init() { } - private(set) var subscriptPositionCallCount = 0 - var subscriptPositionHandler: ((Int) -> Any)? - subscript(position: Int) -> Any { - get { - subscriptPositionCallCount += 1 - if let subscriptPositionHandler = subscriptPositionHandler { - return subscriptPositionHandler(position) - } - fatalError("subscriptPositionHandler returns can't have a default value thus its handler must be set") - } - set { } - } - private(set) var subscriptIndexStringIndexCallCount = 0 - var subscriptIndexStringIndexHandler: ((String.Index) -> Double)? - subscript(index: String.Index) -> Double { - get { - subscriptIndexStringIndexCallCount += 1 - if let subscriptIndexStringIndexHandler = subscriptIndexStringIndexHandler { - return subscriptIndexStringIndexHandler(index) - } - return 0.0 - } - set { } - } + public private(set) var hashCallCount = 0 + public var hashHandler: ((inout Hasher) -> ())? + public func hash(into hasher: inout Hasher) { + hashCallCount += 1 + if let hashHandler = hashHandler { + hashHandler(&hasher) + } - private(set) var subscriptSafeCallCount = 0 - var subscriptSafeHandler: ((String.Index) -> Double?)? - subscript(safe index: String.Index) -> Double? { - get { - subscriptSafeCallCount += 1 - if let subscriptSafeHandler = subscriptSafeHandler { - return subscriptSafeHandler(index) - } - return nil - } - set { } - } + } - private(set) var subscriptRangeCallCount = 0 - var subscriptRangeHandler: ((Range) -> String)? - subscript(range: Range) -> String { - get { - subscriptRangeCallCount += 1 - if let subscriptRangeHandler = subscriptRangeHandler { - return subscriptRangeHandler(range) - } - return "" - } - set { } - } + public private(set) var barCallCount = 0 + public var barHandler: ((inout String, inout Int) -> ())? + public func bar(lhs: inout String, rhs: inout Int) { + barCallCount += 1 + if let barHandler = barHandler { + barHandler(&lhs, &rhs) + } - private(set) var subscriptPathCallCount = 0 - var subscriptPathHandler: ((String) -> ((Double) -> Float)?)? - subscript(path: String) -> ((Double) -> Float)? { - get { - subscriptPathCallCount += 1 - if let subscriptPathHandler = subscriptPathHandler { - return subscriptPathHandler(path) - } - return nil + } } - set { } } +} - private(set) var subscriptDynamicMemberCallCount = 0 - var subscriptDynamicMemberHandler: ((Any) -> Any)? - subscript(dynamicMember keyPath: ReferenceWritableKeyPath) -> T { - get { - subscriptDynamicMemberCallCount += 1 - if let subscriptDynamicMemberHandler = subscriptDynamicMemberHandler { - return subscriptDynamicMemberHandler(keyPath) as! T - } - fatalError("subscriptDynamicMemberHandler returns can't have a default value thus its handler must be set") - } - set { } +@Fixture enum subscripts { + /// @mockable + protocol SubscriptProtocol { + associatedtype T + associatedtype Value + + static subscript(key: Int) -> AnyObject? { get set } + subscript(_ key: Int) -> AnyObject { get set } + subscript(key: Int) -> AnyObject? { get set } + subscript(index: String) -> CGImage? { get set } + subscript(memoizeKey: Int) -> CGRect? { get set } + subscript(position: Int) -> Any { get set } + subscript(index: String.Index) -> Double { get set } + subscript(safe index: String.Index) -> Double? { get set } + subscript(range: Range) -> String { get set } + subscript(path: String) -> ((Double) -> Float)? { get set } + subscript(dynamicMember keyPath: ReferenceWritableKeyPath) -> T { get set } + subscript(dynamicMember keyPath: ReferenceWritableKeyPath) -> T { get set } + subscript(dynamicMember keyPath: WritableKeyPath) -> Value { get set } + subscript(_ parameter: T) -> T { get set } + subscript(keyPath: ReferenceWritableKeyPath) -> Array { get set } + subscript(keyPath: ReferenceWritableKeyPath, on schedulerType: T) -> Array { get set } } - private(set) var subscriptDynamicMemberTCallCount = 0 - var subscriptDynamicMemberTHandler: ((Any) -> Any)? - subscript(dynamicMember keyPath: ReferenceWritableKeyPath) -> T { - get { - subscriptDynamicMemberTCallCount += 1 - if let subscriptDynamicMemberTHandler = subscriptDynamicMemberTHandler { - return subscriptDynamicMemberTHandler(keyPath) as! T - } - fatalError("subscriptDynamicMemberTHandler returns can't have a default value thus its handler must be set") - } - set { } - } + /// @mockable + public protocol KeyValueSubscripting { + associatedtype Key + associatedtype Value - private(set) var subscriptDynamicMemberTWritableKeyPathTValueCallCount = 0 - var subscriptDynamicMemberTWritableKeyPathTValueHandler: ((Any) -> Value)? - subscript(dynamicMember keyPath: WritableKeyPath) -> Value { - get { - subscriptDynamicMemberTWritableKeyPathTValueCallCount += 1 - if let subscriptDynamicMemberTWritableKeyPathTValueHandler = subscriptDynamicMemberTWritableKeyPathTValueHandler { - return subscriptDynamicMemberTWritableKeyPathTValueHandler(keyPath) - } - fatalError("subscriptDynamicMemberTWritableKeyPathTValueHandler returns can't have a default value thus its handler must be set") - } - set { } - } + /// Accesses the value associated with the given key for reading and writing. + subscript(key: Key) -> Value? { get set } - private(set) var subscriptParameterCallCount = 0 - var subscriptParameterHandler: ((Any) -> Any)? - subscript(_ parameter: T) -> T { - get { - subscriptParameterCallCount += 1 - if let subscriptParameterHandler = subscriptParameterHandler { - return subscriptParameterHandler(parameter) as! T - } - fatalError("subscriptParameterHandler returns can't have a default value thus its handler must be set") - } - set { } + /// Accesses the value with the given key. If the receiver doesn’t contain the given key, accesses the provided default value as if the key and default value existed in the receiver. + subscript(key: Key, default defaultValue: @autoclosure () -> Value) -> Value { get set } } - private(set) var subscriptKeyPathCallCount = 0 - var subscriptKeyPathHandler: ((Any) -> Any)? - subscript(keyPath: ReferenceWritableKeyPath) -> Array { - get { - subscriptKeyPathCallCount += 1 - if let subscriptKeyPathHandler = subscriptKeyPathHandler { - return subscriptKeyPathHandler(keyPath) as! Array + @Fixture enum expected { + class SubscriptProtocolMock: SubscriptProtocol { + init() { } + + typealias T = Any + typealias Value = Any + + static private(set) var subscriptCallCount = 0 + static var subscriptHandler: ((Int) -> AnyObject?)? + static subscript(key: Int) -> AnyObject? { + get { + subscriptCallCount += 1 + if let subscriptHandler = subscriptHandler { + return subscriptHandler(key) + } + return nil + } + set { } + } + + private(set) var subscriptKeyCallCount = 0 + var subscriptKeyHandler: ((Int) -> AnyObject)? + subscript(_ key: Int) -> AnyObject { + get { + subscriptKeyCallCount += 1 + if let subscriptKeyHandler = subscriptKeyHandler { + return subscriptKeyHandler(key) + } + fatalError("subscriptKeyHandler returns can't have a default value thus its handler must be set") + } + set { } + } + + private(set) var subscriptKeyIntCallCount = 0 + var subscriptKeyIntHandler: ((Int) -> AnyObject?)? + subscript(key: Int) -> AnyObject? { + get { + subscriptKeyIntCallCount += 1 + if let subscriptKeyIntHandler = subscriptKeyIntHandler { + return subscriptKeyIntHandler(key) + } + return nil + } + set { } + } + + private(set) var subscriptIndexCallCount = 0 + var subscriptIndexHandler: ((String) -> CGImage?)? + subscript(index: String) -> CGImage? { + get { + subscriptIndexCallCount += 1 + if let subscriptIndexHandler = subscriptIndexHandler { + return subscriptIndexHandler(index) + } + return nil + } + set { } + } + + private(set) var subscriptMemoizeKeyCallCount = 0 + var subscriptMemoizeKeyHandler: ((Int) -> CGRect?)? + subscript(memoizeKey: Int) -> CGRect? { + get { + subscriptMemoizeKeyCallCount += 1 + if let subscriptMemoizeKeyHandler = subscriptMemoizeKeyHandler { + return subscriptMemoizeKeyHandler(memoizeKey) + } + return nil + } + set { } + } + + private(set) var subscriptPositionCallCount = 0 + var subscriptPositionHandler: ((Int) -> Any)? + subscript(position: Int) -> Any { + get { + subscriptPositionCallCount += 1 + if let subscriptPositionHandler = subscriptPositionHandler { + return subscriptPositionHandler(position) + } + fatalError("subscriptPositionHandler returns can't have a default value thus its handler must be set") + } + set { } + } + + private(set) var subscriptIndexStringIndexCallCount = 0 + var subscriptIndexStringIndexHandler: ((String.Index) -> Double)? + subscript(index: String.Index) -> Double { + get { + subscriptIndexStringIndexCallCount += 1 + if let subscriptIndexStringIndexHandler = subscriptIndexStringIndexHandler { + return subscriptIndexStringIndexHandler(index) + } + return 0.0 + } + set { } + } + + private(set) var subscriptSafeCallCount = 0 + var subscriptSafeHandler: ((String.Index) -> Double?)? + subscript(safe index: String.Index) -> Double? { + get { + subscriptSafeCallCount += 1 + if let subscriptSafeHandler = subscriptSafeHandler { + return subscriptSafeHandler(index) + } + return nil + } + set { } + } + + private(set) var subscriptRangeCallCount = 0 + var subscriptRangeHandler: ((Range) -> String)? + subscript(range: Range) -> String { + get { + subscriptRangeCallCount += 1 + if let subscriptRangeHandler = subscriptRangeHandler { + return subscriptRangeHandler(range) + } + return "" + } + set { } + } + + private(set) var subscriptPathCallCount = 0 + var subscriptPathHandler: ((String) -> ((Double) -> Float)?)? + subscript(path: String) -> ((Double) -> Float)? { + get { + subscriptPathCallCount += 1 + if let subscriptPathHandler = subscriptPathHandler { + return subscriptPathHandler(path) + } + return nil + } + set { } + } + + private(set) var subscriptDynamicMemberCallCount = 0 + var subscriptDynamicMemberHandler: ((Any) -> Any)? + subscript(dynamicMember keyPath: ReferenceWritableKeyPath) -> T { + get { + subscriptDynamicMemberCallCount += 1 + if let subscriptDynamicMemberHandler = subscriptDynamicMemberHandler { + return subscriptDynamicMemberHandler(keyPath) as! T + } + fatalError("subscriptDynamicMemberHandler returns can't have a default value thus its handler must be set") + } + set { } + } + + private(set) var subscriptDynamicMemberTCallCount = 0 + var subscriptDynamicMemberTHandler: ((Any) -> Any)? + subscript(dynamicMember keyPath: ReferenceWritableKeyPath) -> T { + get { + subscriptDynamicMemberTCallCount += 1 + if let subscriptDynamicMemberTHandler = subscriptDynamicMemberTHandler { + return subscriptDynamicMemberTHandler(keyPath) as! T + } + fatalError("subscriptDynamicMemberTHandler returns can't have a default value thus its handler must be set") + } + set { } + } + + private(set) var subscriptDynamicMemberTWritableKeyPathTValueCallCount = 0 + var subscriptDynamicMemberTWritableKeyPathTValueHandler: ((Any) -> Value)? + subscript(dynamicMember keyPath: WritableKeyPath) -> Value { + get { + subscriptDynamicMemberTWritableKeyPathTValueCallCount += 1 + if let subscriptDynamicMemberTWritableKeyPathTValueHandler = subscriptDynamicMemberTWritableKeyPathTValueHandler { + return subscriptDynamicMemberTWritableKeyPathTValueHandler(keyPath) + } + fatalError("subscriptDynamicMemberTWritableKeyPathTValueHandler returns can't have a default value thus its handler must be set") + } + set { } + } + + private(set) var subscriptParameterCallCount = 0 + var subscriptParameterHandler: ((Any) -> Any)? + subscript(_ parameter: T) -> T { + get { + subscriptParameterCallCount += 1 + if let subscriptParameterHandler = subscriptParameterHandler { + return subscriptParameterHandler(parameter) as! T + } + fatalError("subscriptParameterHandler returns can't have a default value thus its handler must be set") + } + set { } + } + + private(set) var subscriptKeyPathCallCount = 0 + var subscriptKeyPathHandler: ((Any) -> Any)? + subscript(keyPath: ReferenceWritableKeyPath) -> Array { + get { + subscriptKeyPathCallCount += 1 + if let subscriptKeyPathHandler = subscriptKeyPathHandler { + return subscriptKeyPathHandler(keyPath) as! Array + } + return Array() + } + set { } + } + + private(set) var subscriptKeyPathOnCallCount = 0 + var subscriptKeyPathOnHandler: ((Any, T) -> Any)? + subscript(keyPath: ReferenceWritableKeyPath, on schedulerType: T) -> Array { + get { + subscriptKeyPathOnCallCount += 1 + if let subscriptKeyPathOnHandler = subscriptKeyPathOnHandler { + return subscriptKeyPathOnHandler(keyPath, schedulerType) as! Array + } + return Array() + } + set { } + } + } + + public class KeyValueSubscriptingMock: KeyValueSubscripting { + public init() { } + + public typealias Key = Any + public typealias Value = Any + + public private(set) var subscriptCallCount = 0 + public var subscriptHandler: ((Key) -> Value?)? + public subscript(key: Key) -> Value? { + get { + subscriptCallCount += 1 + if let subscriptHandler = subscriptHandler { + return subscriptHandler(key) + } + return nil + } + set { } + } + + public private(set) var subscriptKeyCallCount = 0 + public var subscriptKeyHandler: ((Key, @autoclosure () -> Value) -> Value)? + public subscript(key: Key, default defaultValue: @autoclosure () -> Value) -> Value { + get { + subscriptKeyCallCount += 1 + if let subscriptKeyHandler = subscriptKeyHandler { + return subscriptKeyHandler(key, defaultValue()) + } + fatalError("subscriptKeyHandler returns can't have a default value thus its handler must be set") + } + set { } + } } - return Array() - } - set { } - } - - private(set) var subscriptKeyPathOnCallCount = 0 - var subscriptKeyPathOnHandler: ((Any, T) -> Any)? - subscript(keyPath: ReferenceWritableKeyPath, on schedulerType: T) -> Array { - get { - subscriptKeyPathOnCallCount += 1 - if let subscriptKeyPathOnHandler = subscriptKeyPathOnHandler { - return subscriptKeyPathOnHandler(keyPath, schedulerType) as! Array - } - return Array() - } - set { } } } -public class KeyValueSubscriptingMock: KeyValueSubscripting { - public init() { } - - public typealias Key = Any - public typealias Value = Any - - public private(set) var subscriptCallCount = 0 - public var subscriptHandler: ((Key) -> Value?)? - public subscript(key: Key) -> Value? { - get { - subscriptCallCount += 1 - if let subscriptHandler = subscriptHandler { - return subscriptHandler(key) - } - return nil - } - set { } +@Fixture enum variadicFunc { + /// @mockable + protocol NonSimpleFuncs { + func bar(_ arg: String, x: Int..., y: [Double]) -> Float? } - public private(set) var subscriptKeyCallCount = 0 - public var subscriptKeyHandler: ((Key, @autoclosure () -> Value) -> Value)? - public subscript(key: Key, default defaultValue: @autoclosure () -> Value) -> Value { - get { - subscriptKeyCallCount += 1 - if let subscriptKeyHandler = subscriptKeyHandler { - return subscriptKeyHandler(key, defaultValue()) - } - fatalError("subscriptKeyHandler returns can't have a default value thus its handler must be set") - } - set { } + @Fixture enum expected { +// class NonSimpleFuncsMock: NonSimpleFuncs { +// init() { } +// +// +// private(set) var barCallCount = 0 +// var barHandler: ((String, Int..., [Double]) -> Float?)? +// func bar(_ arg: String, x: Int..., y: [Double]) -> Float? { +// barCallCount += 1 +// if let barHandler = barHandler { +// return barHandler(arg, x, y) +// } +// return nil +// } +// } } } -""" - - -let variadicFunc = """ -import Foundation -/// \(String.mockAnnotation) -protocol NonSimpleFuncs { - func bar(_ arg: String, x: Int..., y: [Double]) -> Float? -} -""" - -let variadicFuncMock = -""" - -import Foundation - - -class NonSimpleFuncsMock: NonSimpleFuncs { - init() { } - - - private(set) var barCallCount = 0 - var barHandler: ((String, Int..., [Double]) -> Float?)? - func bar(_ arg: String, x: Int..., y: [Double]) -> Float? { - barCallCount += 1 - if let barHandler = barHandler { - return barHandler(arg, x, y) - } - return nil +@Fixture enum autoclosureArgFunc { + /// @mockable + protocol NonSimpleFuncs { + func pass(handler: @autoclosure () -> Int) throws -> T } -} - -""" - - -let autoclosureArgFunc = """ -import Foundation - -/// \(String.mockAnnotation) -protocol NonSimpleFuncs { -func pass(handler: @autoclosure () -> Int) throws -> T -} -""" - -let autoclosureArgFuncMock = """ - -import Foundation - -class NonSimpleFuncsMock: NonSimpleFuncs { - init() { } + @Fixture enum expected { + class NonSimpleFuncsMock: NonSimpleFuncs { + init() { } - private(set) var passCallCount = 0 - var passHandler: ((@autoclosure () -> Int) throws -> Any)? - func pass(handler: @autoclosure () -> Int) throws -> T { - passCallCount += 1 - if let passHandler = passHandler { - return try passHandler(handler()) as! T + private(set) var passCallCount = 0 + var passHandler: ((@autoclosure () -> Int) throws -> Any)? + func pass(handler: @autoclosure () -> Int) throws -> T { + passCallCount += 1 + if let passHandler = passHandler { + return try passHandler(handler()) as! T + } + fatalError("passHandler returns can't have a default value thus its handler must be set") + } } - fatalError("passHandler returns can't have a default value thus its handler must be set") } } -""" - - -let closureArgFunc = """ -import Foundation - -/// \(String.mockAnnotation) -protocol NonSimpleFuncs { -func cat(named arg: String, tags: [String: String]?, closure: () throws -> T) rethrows -> T -func more(named arg: String, tags: [String: String]?, closure: (T) throws -> ()) rethrows -> T -} -""" - - -let closureArgFuncMock = """ - -import Foundation - - -class NonSimpleFuncsMock: NonSimpleFuncs { - init() { } - - - private(set) var catCallCount = 0 - var catHandler: ((String, [String: String]?, () throws -> Any) throws -> Any)? - func cat(named arg: String, tags: [String: String]?, closure: () throws -> T) rethrows -> T { - catCallCount += 1 - if let catHandler = catHandler { - return try catHandler(arg, tags, closure) as! T - } - fatalError("catHandler returns can't have a default value thus its handler must be set") +@Fixture enum closureArgFunc { + /// @mockable + protocol NonSimpleFuncs { + func cat(named arg: String, tags: [String: String]?, closure: () throws -> T) rethrows -> T + func more(named arg: String, tags: [String: String]?, closure: (T) throws -> ()) rethrows -> T } - private(set) var moreCallCount = 0 - var moreHandler: ((String, [String: String]?, (Any) throws -> ()) throws -> Any)? - func more(named arg: String, tags: [String: String]?, closure: (T) throws -> ()) rethrows -> T { - moreCallCount += 1 - if let moreHandler = moreHandler { - return try moreHandler(arg, tags, closure) as! T - } - fatalError("moreHandler returns can't have a default value thus its handler must be set") + @Fixture enum expected { +// class NonSimpleFuncsMock: NonSimpleFuncs { +// init() { } +// +// +// private(set) var catCallCount = 0 +// var catHandler: ((String, [String: String]?, () throws -> Any) throws -> Any)? +// func cat(named arg: String, tags: [String: String]?, closure: () throws -> T) rethrows -> T { +// catCallCount += 1 +// if let catHandler = catHandler { +// return try catHandler(arg, tags, closure) as! T +// } +// fatalError("catHandler returns can't have a default value thus its handler must be set") +// } +// +// private(set) var moreCallCount = 0 +// var moreHandler: ((String, [String: String]?, (Any) throws -> ()) throws -> Any)? +// func more(named arg: String, tags: [String: String]?, closure: (T) throws -> ()) rethrows -> T { +// moreCallCount += 1 +// if let moreHandler = moreHandler { +// return try moreHandler(arg, tags, closure) as! T +// } +// fatalError("moreHandler returns can't have a default value thus its handler must be set") +// } +// } } } -""" - -let forArgClosureFunc = """ -import Foundation - -/// \(String.mockAnnotation) -protocol NonSimpleFuncs { -func max(for: Int) -> (() -> Void)? -func maxDo(do: Int) -> (() -> Void)? -func maxIn(in: Int) -> (() -> Void)? -func maxSwitch(for switch: Int) -> (() -> Void)? -func maxExtension(extension: Int) -> (() -> Void)? -} -""" - -let forArgClosureFuncMock = """ - -import Foundation - - -class NonSimpleFuncsMock: NonSimpleFuncs { - init() { } - - - private(set) var maxCallCount = 0 - var maxHandler: ((Int) -> (() -> Void)?)? - func max(for: Int) -> (() -> Void)? { - maxCallCount += 1 - if let maxHandler = maxHandler { - return maxHandler(`for`) - } - return nil +@Fixture enum forArgClosureFunc { + /// @mockable + protocol NonSimpleFuncs { + func max(for: Int) -> (() -> Void)? + func maxDo(do: Int) -> (() -> Void)? + func maxIn(in: Int) -> (() -> Void)? + func maxSwitch(for switch: Int) -> (() -> Void)? + func maxExtension(extension: Int) -> (() -> Void)? } - private(set) var maxDoCallCount = 0 - var maxDoHandler: ((Int) -> (() -> Void)?)? - func maxDo(do: Int) -> (() -> Void)? { - maxDoCallCount += 1 - if let maxDoHandler = maxDoHandler { - return maxDoHandler(`do`) + @Fixture enum expected { + class NonSimpleFuncsMock: NonSimpleFuncs { + init() { } + + + private(set) var maxCallCount = 0 + var maxHandler: ((Int) -> (() -> Void)?)? + func max(for: Int) -> (() -> Void)? { + maxCallCount += 1 + if let maxHandler = maxHandler { + return maxHandler(`for`) + } + return nil + } + + private(set) var maxDoCallCount = 0 + var maxDoHandler: ((Int) -> (() -> Void)?)? + func maxDo(do: Int) -> (() -> Void)? { + maxDoCallCount += 1 + if let maxDoHandler = maxDoHandler { + return maxDoHandler(`do`) + } + return nil + } + + private(set) var maxInCallCount = 0 + var maxInHandler: ((Int) -> (() -> Void)?)? + func maxIn(in: Int) -> (() -> Void)? { + maxInCallCount += 1 + if let maxInHandler = maxInHandler { + return maxInHandler(`in`) + } + return nil + } + + private(set) var maxSwitchCallCount = 0 + var maxSwitchHandler: ((Int) -> (() -> Void)?)? + func maxSwitch(for switch: Int) -> (() -> Void)? { + maxSwitchCallCount += 1 + if let maxSwitchHandler = maxSwitchHandler { + return maxSwitchHandler(`switch`) + } + return nil + } + + private(set) var maxExtensionCallCount = 0 + var maxExtensionHandler: ((Int) -> (() -> Void)?)? + func maxExtension(extension: Int) -> (() -> Void)? { + maxExtensionCallCount += 1 + if let maxExtensionHandler = maxExtensionHandler { + return maxExtensionHandler(`extension`) + } + return nil + } } - return nil } - - private(set) var maxInCallCount = 0 - var maxInHandler: ((Int) -> (() -> Void)?)? - func maxIn(in: Int) -> (() -> Void)? { - maxInCallCount += 1 - if let maxInHandler = maxInHandler { - return maxInHandler(`in`) - } - return nil - } - - private(set) var maxSwitchCallCount = 0 - var maxSwitchHandler: ((Int) -> (() -> Void)?)? - func maxSwitch(for switch: Int) -> (() -> Void)? { - maxSwitchCallCount += 1 - if let maxSwitchHandler = maxSwitchHandler { - return maxSwitchHandler(`switch`) - } - return nil - } - - private(set) var maxExtensionCallCount = 0 - var maxExtensionHandler: ((Int) -> (() -> Void)?)? - func maxExtension(extension: Int) -> (() -> Void)? { - maxExtensionCallCount += 1 - if let maxExtensionHandler = maxExtensionHandler { - return maxExtensionHandler(`extension`) - } - return nil - } - } -""" - -let returnSelfFunc = """ -import Foundation - -/// \(String.mockAnnotation) -protocol NonSimpleFuncs { -@discardableResult -func returnSelf() -> Self -} -""" - -let returnSelfFuncMock = """ - -import Foundation - - -class NonSimpleFuncsMock: NonSimpleFuncs { - init() { } +@Fixture enum returnSelfFunc { + /// @mockable + protocol NonSimpleFuncs { + @discardableResult + func returnSelf() -> Self + } - private(set) var returnSelfCallCount = 0 - var returnSelfHandler: (() -> NonSimpleFuncsMock)? - func returnSelf() -> Self { - returnSelfCallCount += 1 - if let returnSelfHandler = returnSelfHandler { - return returnSelfHandler() as! Self + @Fixture enum expected { + class NonSimpleFuncsMock: NonSimpleFuncs { + init() { } + + + private(set) var returnSelfCallCount = 0 + var returnSelfHandler: (() -> NonSimpleFuncsMock)? + func returnSelf() -> Self { + returnSelfCallCount += 1 + if let returnSelfHandler = returnSelfHandler { + return returnSelfHandler() as! Self + } + fatalError("returnSelfHandler returns can't have a default value thus its handler must be set") + } } - fatalError("returnSelfHandler returns can't have a default value thus its handler must be set") } } -""" diff --git a/Tests/TestFuncs/TestBasicFuncs/FixtureSimpleFuncs.swift b/Tests/TestFuncs/TestBasicFuncs/FixtureSimpleFuncs.swift index 495ebf7a..e312c7b5 100644 --- a/Tests/TestFuncs/TestBasicFuncs/FixtureSimpleFuncs.swift +++ b/Tests/TestFuncs/TestBasicFuncs/FixtureSimpleFuncs.swift @@ -1,70 +1,57 @@ import MockoloFramework -let simpleFuncs = """ -import Foundation - -/// \(String.mockAnnotation) -public protocol SimpleFunc { - func update(arg: Int) -> String -} -""" - -let simpleFuncsMock = """ - -import Foundation +@Fixture enum simpleFuncs { + /// @mockable + public protocol SimpleFunc { + func update(arg: Int) -> String + } -public class SimpleFuncMock: SimpleFunc { - public init() { } + @Fixture enum expected { + public class SimpleFuncMock: SimpleFunc { + public init() { } - public private(set) var updateCallCount = 0 - public var updateHandler: ((Int) -> String)? - public func update(arg: Int) -> String { - updateCallCount += 1 - if let updateHandler = updateHandler { - return updateHandler(arg) + public private(set) var updateCallCount = 0 + public var updateHandler: ((Int) -> String)? + public func update(arg: Int) -> String { + updateCallCount += 1 + if let updateHandler = updateHandler { + return updateHandler(arg) + } + return "" + } } - return "" } -} - -""" - -let simpleFuncsAllowCallCountMock = """ + @Fixture enum allowCallCountExpected { + public class SimpleFuncMock: SimpleFunc { + public init() { } -import Foundation -public class SimpleFuncMock: SimpleFunc { - public init() { } - - - public var updateCallCount = 0 - public var updateHandler: ((Int) -> String)? - public func update(arg: Int) -> String { - updateCallCount += 1 - if let updateHandler = updateHandler { - return updateHandler(arg) + public var updateCallCount = 0 + public var updateHandler: ((Int) -> String)? + public func update(arg: Int) -> String { + updateCallCount += 1 + if let updateHandler = updateHandler { + return updateHandler(arg) + } + return "" + } } - return "" } -} - -""" -let simpleMockFuncMock = """ + @Fixture enum mockFuncExpected { + public class SimpleFuncMock: SimpleFunc { + public init() { } -import Foundation -public class SimpleFuncMock: SimpleFunc { - public init() { } - - - public private(set) var updateCallCount = 0 - public var updateHandler: ((Int) -> String)? - public func update(arg: Int) -> String { - mockFunc(&updateCallCount)("update", updateHandler?(arg), .val("")) + public private(set) var updateCallCount = 0 + public var updateHandler: ((Int) -> String)? + public func update(arg: Int) -> String { + mockFunc(&updateCallCount)("update", updateHandler?(arg), .val("")) + } + } } } -""" + diff --git a/Tests/TestFuncs/TestBasicFuncs/FuncBasicTests.swift b/Tests/TestFuncs/TestBasicFuncs/FuncBasicTests.swift index 94af2201..d3ef57bc 100644 --- a/Tests/TestFuncs/TestBasicFuncs/FuncBasicTests.swift +++ b/Tests/TestFuncs/TestBasicFuncs/FuncBasicTests.swift @@ -1,56 +1,53 @@ -import Foundation - class BasicFuncTests: MockoloTestCase { - func testInoutParams() { - verify(srcContent: inoutParams, - dstContent: inoutParamsMock) + verify(srcContent: inoutParams._source, + dstContent: inoutParams.expected._source) } func testSubscripts() { - verify(srcContent: subscripts, - dstContent: subscriptsMocks) + verify(srcContent: subscripts._source, + dstContent: subscripts.expected._source) } func testVariadicFuncs() { - verify(srcContent: variadicFunc, - dstContent: variadicFuncMock) + verify(srcContent: variadicFunc._source, + dstContent: variadicFunc.expected._source) } func testAutoclosureArgFuncs() { - verify(srcContent: autoclosureArgFunc, - dstContent: autoclosureArgFuncMock) + verify(srcContent: autoclosureArgFunc._source, + dstContent: autoclosureArgFunc.expected._source) } func testClosureArgFuncs() { - verify(srcContent: closureArgFunc, - dstContent: closureArgFuncMock) + verify(srcContent: closureArgFunc._source, + dstContent: closureArgFunc.expected._source) } func testForArgFuncs() { - verify(srcContent: forArgClosureFunc, - dstContent: forArgClosureFuncMock) + verify(srcContent: forArgClosureFunc._source, + dstContent: forArgClosureFunc.expected._source) } func testReturnSelfFunc() { - verify(srcContent: returnSelfFunc, - dstContent: returnSelfFuncMock) + verify(srcContent: returnSelfFunc._source, + dstContent: returnSelfFunc.expected._source) } func testSimpleFuncs() { - verify(srcContent: simpleFuncs, - dstContent: simpleFuncsMock) + verify(srcContent: simpleFuncs._source, + dstContent: simpleFuncs.expected._source) } func testSimpleFuncsAllowCallCount() { - verify(srcContent: simpleFuncs, - dstContent: simpleFuncsAllowCallCountMock, + verify(srcContent: simpleFuncs._source, + dstContent: simpleFuncs.allowCallCountExpected._source, allowSetCallCount: true) } func testMockFuncs() { - verify(srcContent: simpleFuncs, - dstContent: simpleMockFuncMock, + verify(srcContent: simpleFuncs._source, + dstContent: simpleFuncs.mockFuncExpected._source, useTemplateFunc: true) } } diff --git a/Tests/TestFuncs/TestFuncAsync/FixtureFuncAsync.swift b/Tests/TestFuncs/TestFuncAsync/FixtureFuncAsync.swift index b29efa9c..7ebafd01 100644 --- a/Tests/TestFuncs/TestFuncAsync/FixtureFuncAsync.swift +++ b/Tests/TestFuncs/TestFuncAsync/FixtureFuncAsync.swift @@ -1,7 +1,7 @@ import MockoloFramework let funcAsync = """ -/// \(String.mockAnnotation) +/// @mockable protocol FuncAsync { init() async func f1(arg: Int) async -> String @@ -71,7 +71,7 @@ class FuncAsyncMock: FuncAsync { """ let funcAsyncThrows = """ -/// \(String.mockAnnotation) +/// @mockable protocol FuncAsyncThrows { init() async throws func f1(arg: Int) async throws -> String diff --git a/Tests/TestFuncs/TestFuncThrow/FixtureFuncThrow.swift b/Tests/TestFuncs/TestFuncThrow/FixtureFuncThrow.swift index ea33fcba..763dfd95 100644 --- a/Tests/TestFuncs/TestFuncThrow/FixtureFuncThrow.swift +++ b/Tests/TestFuncs/TestFuncThrow/FixtureFuncThrow.swift @@ -4,7 +4,7 @@ import MockoloFramework let funcThrow = """ import Foundation -/// \(String.mockAnnotation) +/// @mockable protocol FuncThrow { func f1(arg: Int) throws -> String func f2(arg: Int) throws diff --git a/Tests/TestFuncs/TestGenericFuncs/FixtureGenericFunc.swift b/Tests/TestFuncs/TestGenericFuncs/FixtureGenericFunc.swift index 44913992..9b453ea6 100644 --- a/Tests/TestFuncs/TestGenericFuncs/FixtureGenericFunc.swift +++ b/Tests/TestFuncs/TestGenericFuncs/FixtureGenericFunc.swift @@ -1,7 +1,7 @@ import MockoloFramework let genericOptionalType = """ -/// \(String.mockAnnotation) +/// @mockable public protocol GenericProtocol { func nonOptional() -> T func optional() -> T? @@ -42,7 +42,7 @@ public class GenericProtocolMock: GenericProtocol { let genericFunc = """ import Foundation -/// \(String.mockAnnotation) +/// @mockable protocol GenericFunc { func containsGeneric(arg1: T, arg2: @escaping (U) -> ()) -> ((T) -> (U)) func sendEvents(events: [SomeEvent], value: T, once: Bool, closure: @escaping (T) -> ()) @@ -230,7 +230,7 @@ class NetworkingMock: Networking { """ let funcDuplicateSignatureDifferentWhereClause = """ -/// \(String.mockAnnotation) +/// @mockable protocol Storing { func connect(adapter: T) where T: Adapter func connect(adapter: T) where T: KeyedAdapter @@ -283,7 +283,7 @@ class StoringMock: Storing { """ let funcDuplicateSignatureDifferentWhereClauseEquality = """ -/// \(String.mockAnnotation) +/// @mockable protocol Storing { func connect(adapter: T) where T: Adapter, T.Element == S.Element func connect(adapter: T) where T: KeyedAdapter, T.Element == S.Element diff --git a/Tests/TestFuncs/TestOpaqueTypeFuncs/FixtureOpaqueTypeFunc.swift b/Tests/TestFuncs/TestOpaqueTypeFuncs/FixtureOpaqueTypeFunc.swift index e866d808..133c2c9e 100644 --- a/Tests/TestFuncs/TestOpaqueTypeFuncs/FixtureOpaqueTypeFunc.swift +++ b/Tests/TestFuncs/TestOpaqueTypeFuncs/FixtureOpaqueTypeFunc.swift @@ -1,7 +1,7 @@ import MockoloFramework let someParameterOptionalType = """ -/// \(String.mockAnnotation) +/// @mockable public protocol OpaqueTypeProtocol { func nonOptional(_ type: some Error) -> Int func optional(_ type: (some Error)?) @@ -40,7 +40,7 @@ public class OpaqueTypeProtocolMock: OpaqueTypeProtocol { """ let someMultiParameterOptionalType = """ -/// \(String.mockAnnotation) +/// @mockable public protocol OpaqueTypeWithMultiTypeProtocol { func nonOptional(_ type: some Error) -> Int func optional(_ type: ((some (Error & Foo)))?) @@ -91,7 +91,7 @@ public class OpaqueTypeWithMultiTypeProtocolMock: OpaqueTypeWithMultiTypeProtoco """ let closureReturningSomeType = """ -/// \(String.mockAnnotation) +/// @mockable protocol ProtocolReturningOpaqueTypeInClosureProtocol { func register(router: @autoclosure @escaping () -> (some MyAwesomeType)) } diff --git a/Tests/TestInit/FixtureInit.swift b/Tests/TestInit/FixtureInit.swift index ab86fba7..aca4a2be 100644 --- a/Tests/TestInit/FixtureInit.swift +++ b/Tests/TestInit/FixtureInit.swift @@ -1,7 +1,7 @@ import MockoloFramework let keywordParams = """ -/// \(String.mockAnnotation) +/// @mockable protocol KeywordProtocol { init(in: Int) } @@ -13,7 +13,7 @@ class KClass { } } -/// \(String.mockAnnotation) +/// @mockable class KeywordClass: KClass { override init(in: Int) { super.init(in: `in`) @@ -39,7 +39,7 @@ class KeywordProtocolMock: KeywordProtocol { // MARK - protocol containing init let protocolWithBlankInit = """ -/// \(String.mockAnnotation) +/// @mockable public protocol BlankInit { init() } @@ -53,7 +53,7 @@ public class BlankInitMock: BlankInit { """ let protocolWithInit = """ -/// \(String.mockAnnotation) +/// @mockable public protocol HasInit: HasInitParent { init(arg: String) } @@ -142,7 +142,7 @@ public class HasInitMock: HasInit { let simpleInit = """ import Foundation -/// \(String.mockAnnotation) +/// @mockable public protocol Current: Parent { var title: String { get set } } @@ -212,7 +212,7 @@ let nonSimpleInitVars = """ public typealias ForcastCheckBlock = () -> ForcastUpdateConfig? -/// \(String.mockAnnotation) +/// @mockable @objc public protocol ForcastUpdating { @objc init(checkBlock: @escaping ForcastCheckBlock, dataStream: DataStream) @objc func enabled() -> Bool @@ -265,7 +265,7 @@ public class ForcastUpdatingMock: ForcastUpdating { """ let initWithSameParamNameButDifferentType = """ -/// \(String.mockAnnotation) +/// @mockable protocol MyProtocol { init(param: Any) init(param: String) @@ -290,7 +290,7 @@ class MyProtocolMock: MyProtocol { """ let multipleInitsWithSameParamName = """ -/// \(String.mockAnnotation) +/// @mockable protocol MyProtocol { init(param: String, anotherParam: Int) init(param: String, anotherParam: String) @@ -316,7 +316,7 @@ class MyProtocolMock: MyProtocol { """ let throwableInit = """ -/// \(String.mockAnnotation) +/// @mockable protocol MyProtocol { init(param: String) throws } @@ -336,7 +336,7 @@ class MyProtocolMock: MyProtocol { """ let typedThrowableInit = """ -/// \(String.mockAnnotation) +/// @mockable protocol MyProtocol { init(param: String) throws(SomeError) } diff --git a/Tests/TestMacros/FixtureMacro.swift b/Tests/TestMacros/FixtureMacro.swift index ec1bb0f8..45f490a1 100644 --- a/Tests/TestMacros/FixtureMacro.swift +++ b/Tests/TestMacros/FixtureMacro.swift @@ -11,7 +11,7 @@ import W import V -/// \(String.mockAnnotation) +/// @mockable public protocol SomeProtocol: Parent { func run() } @@ -140,7 +140,7 @@ import Z import C -/// \(String.mockAnnotation) +/// @mockable public protocol SomeProtocol: Parent { func run() } @@ -192,7 +192,7 @@ import Y import C -/// \(String.mockAnnotation) +/// @mockable public protocol SomeProtocol: Parent { func run() } @@ -229,7 +229,7 @@ public class SomeProtocolMock: SomeProtocol { let macroInFunc = """ -/// \(String.mockAnnotation) +/// @mockable protocol PresentableListener: class { func run() #if DEBUG @@ -272,7 +272,7 @@ class PresentableListenerMock: PresentableListener { """ let macroInFuncWithOverload = """ -/// \(String.mockAnnotation) +/// @mockable protocol PresentableListener: AnyObject { #if DEBUG func run(value: Int) diff --git a/Tests/TestModifiersTypes/FixtureModifiersTypes.swift b/Tests/TestModifiersTypes/FixtureModifiersTypes.swift index d4215bcc..6cd30f4f 100644 --- a/Tests/TestModifiersTypes/FixtureModifiersTypes.swift +++ b/Tests/TestModifiersTypes/FixtureModifiersTypes.swift @@ -1,7 +1,7 @@ import MockoloFramework let modifiersTypesWithWeakAnnotation = """ -/// \(String.mockAnnotation)(modifiers: listener = weak) +/// @mockable(modifiers: listener = weak) protocol Foo { var listener: AnyObject? { get } func barFunc(val: [Int]) @@ -43,7 +43,7 @@ class FooMock: Foo { """ let modifiersTypesWithDynamicAnnotation = """ -/// \(String.mockAnnotation)(modifiers: listener = dynamic) +/// @mockable(modifiers: listener = dynamic) protocol Foo { var listener: AnyObject? { get } func barFunc(val: [Int]) @@ -86,7 +86,7 @@ class FooMock: Foo { """ let modifiersTypesWithDynamicFuncAnnotation = """ -/// \(String.mockAnnotation)(modifiers: barFunc = dynamic) +/// @mockable(modifiers: barFunc = dynamic) protocol Foo { var listener: AnyObject? { get } func barFunc(val: [Int]) diff --git a/Tests/TestNamespaces/FixtureModuleOverrides.swift b/Tests/TestNamespaces/FixtureModuleOverrides.swift index 7642f6cf..c982a202 100644 --- a/Tests/TestNamespaces/FixtureModuleOverrides.swift +++ b/Tests/TestNamespaces/FixtureModuleOverrides.swift @@ -2,7 +2,7 @@ import MockoloFramework let moduleOverride = """ -/// \(String.mockAnnotation)(module: prefix = Foo) +/// @mockable(module: prefix = Foo) protocol TaskRouting: BaseRouting { var bar: String { get } func baz() -> Double diff --git a/Tests/TestNamespaces/FixtureNestedProtocol.swift b/Tests/TestNamespaces/FixtureNestedProtocol.swift index 56b3dadb..fe55af08 100644 --- a/Tests/TestNamespaces/FixtureNestedProtocol.swift +++ b/Tests/TestNamespaces/FixtureNestedProtocol.swift @@ -2,7 +2,7 @@ import MockoloFramework let nestedProtocol = """ @MainActor final class FooView: UIView { - /// \(String.mockAnnotation) + /// @mockable @MainActor protocol Delegate: AnyObject { func onTapButton(_ button: UIButton) } @@ -12,7 +12,7 @@ let nestedProtocol = """ extension AAA { actor BBB { - /// \(String.mockAnnotation) + /// @mockable protocol CCC { } } @@ -49,7 +49,7 @@ extension AAA.BBB { let nestedProtocolInGeneric = """ actor Foo { - /// \(String.mockAnnotation) + /// @mockable protocol NG1 { func requirement() -> Int } @@ -57,14 +57,14 @@ actor Foo { enum Bar { struct Baz { - /// \(String.mockAnnotation) + /// @mockable protocol NG2 { func requirement() -> Int } } } -/// \(String.mockAnnotation) +/// @mockable protocol OK { associatedtype T func requirement() -> T diff --git a/Tests/TestOutputChange/OutputChangeTests.swift b/Tests/TestOutputChange/OutputChangeTests.swift index 1a78aaf5..3d4d6a35 100644 --- a/Tests/TestOutputChange/OutputChangeTests.swift +++ b/Tests/TestOutputChange/OutputChangeTests.swift @@ -3,15 +3,15 @@ import XCTest class OutputChangeTests: MockoloTestCase { func testFileWriteBehavior() throws { - verify(srcContent: simpleFuncs, - dstContent: simpleFuncsMock) + verify(srcContent: simpleFuncs._source, + dstContent: simpleFuncs.expected._source) let expectedAttributes = try FileManager.default.attributesOfItem(atPath: defaultDstFilePath) let expectedCreationDate = expectedAttributes[.creationDate] as? Date let expectedModificationDate = expectedAttributes[.modificationDate] as? Date - verify(srcContent: simpleFuncs, - dstContent: simpleFuncsMock) + verify(srcContent: simpleFuncs._source, + dstContent: simpleFuncs.expected._source) let attributes = try FileManager.default.attributesOfItem(atPath: defaultDstFilePath) let creationDate = attributes[.creationDate] as? Date diff --git a/Tests/TestOverloads/FixtureDuplicates1.swift b/Tests/TestOverloads/FixtureDuplicates1.swift index 5dbdcd4e..92f13b2d 100644 --- a/Tests/TestOverloads/FixtureDuplicates1.swift +++ b/Tests/TestOverloads/FixtureDuplicates1.swift @@ -4,7 +4,7 @@ import MockoloFramework let overload3 = """ import UIKit -/// \(String.mockAnnotation) +/// @mockable protocol Foo { func display() func display(x: Int) diff --git a/Tests/TestOverloads/FixtureDuplicates2.swift b/Tests/TestOverloads/FixtureDuplicates2.swift index f04e8254..dc534be6 100644 --- a/Tests/TestOverloads/FixtureDuplicates2.swift +++ b/Tests/TestOverloads/FixtureDuplicates2.swift @@ -1,14 +1,14 @@ import MockoloFramework let o = """ -/// \(String.mockAnnotation) +/// @mockable protocol Foo { func update(arg: Int) -> (String) -> Observable } """ let overload4 = """ -/// \(String.mockAnnotation) +/// @mockable protocol Foo { func update(arg: Int, some: Float) func update(arg: Int, some: Float) -> Int diff --git a/Tests/TestOverloads/FixtureDuplicates3.swift b/Tests/TestOverloads/FixtureDuplicates3.swift index 378bfdcd..23a1d3a7 100644 --- a/Tests/TestOverloads/FixtureDuplicates3.swift +++ b/Tests/TestOverloads/FixtureDuplicates3.swift @@ -1,7 +1,7 @@ import MockoloFramework let overload5 = """ -/// \(String.mockAnnotation) +/// @mockable protocol Foo { func collectionView(_ collectionView: UICollectionView, reuseIdentifierForItemAt index: Int) -> String? diff --git a/Tests/TestOverloads/FixtureDuplicates4.swift b/Tests/TestOverloads/FixtureDuplicates4.swift index 6b3386cb..8674a620 100644 --- a/Tests/TestOverloads/FixtureDuplicates4.swift +++ b/Tests/TestOverloads/FixtureDuplicates4.swift @@ -2,7 +2,7 @@ import MockoloFramework let overload6 = """ -/// \(String.mockAnnotation) +/// @mockable protocol SomeVC { func popViewController(viewController: UIViewController) func popViewController() @@ -60,7 +60,7 @@ public protocol Bar5 { func customize(text: String?, textColor: UIColor?, loadId: String?) } -/// \(String.mockAnnotation) +/// @mockable public protocol Foo: Bar2, Bar3, Bar4, Bar5 { } """ @@ -109,12 +109,12 @@ public class FooMock: Foo { let sameNameVarFunc = """ -/// \(String.mockAnnotation) +/// @mockable public protocol Bar: AnyObject { var talk: Int { get } } -/// \(String.mockAnnotation) +/// @mockable public protocol Foo: Bar { func talk(_ dismiss: Bool) } diff --git a/Tests/TestOverloads/FixtureDuplicates5.swift b/Tests/TestOverloads/FixtureDuplicates5.swift index dc40b918..7fbf1991 100644 --- a/Tests/TestOverloads/FixtureDuplicates5.swift +++ b/Tests/TestOverloads/FixtureDuplicates5.swift @@ -2,7 +2,7 @@ import MockoloFramework let simpleDuplicates = """ -/// \(String.mockAnnotation) +/// @mockable public protocol SimpleDuplicate { func remove(_ arg: Int) func remove(_ arg: String) diff --git a/Tests/TestOverloads/FixtureDuplicatesInheritance1.swift b/Tests/TestOverloads/FixtureDuplicatesInheritance1.swift index f0e77c29..367cedc7 100644 --- a/Tests/TestOverloads/FixtureDuplicatesInheritance1.swift +++ b/Tests/TestOverloads/FixtureDuplicatesInheritance1.swift @@ -3,14 +3,14 @@ import MockoloFramework let overload8 = """ import Foundation -/// \(String.mockAnnotation) +/// @mockable public protocol Parent: AnyObject { @discardableResult func updateState(_ state: Int) -> (result: Double?, status: Bool) } -/// \(String.mockAnnotation) +/// @mockable public protocol Child: Parent { @discardableResult func updateState(_ state: Int, style: SomeStyle) -> (result: Double?, status: Bool) diff --git a/Tests/TestOverloads/FixtureDuplicatesInheritance2.swift b/Tests/TestOverloads/FixtureDuplicatesInheritance2.swift index 3c1cb51b..b8cbdb69 100644 --- a/Tests/TestOverloads/FixtureDuplicatesInheritance2.swift +++ b/Tests/TestOverloads/FixtureDuplicatesInheritance2.swift @@ -1,12 +1,12 @@ import MockoloFramework let overload9 = """ -/// \(String.mockAnnotation) +/// @mockable protocol Foo { func update(arg: Int) } -/// \(String.mockAnnotation) +/// @mockable protocol Bar: Foo { func update(arg: Int) } diff --git a/Tests/TestOverloads/FixtureDuplicatesInheritance3.swift b/Tests/TestOverloads/FixtureDuplicatesInheritance3.swift index 6d6c25b8..91146046 100644 --- a/Tests/TestOverloads/FixtureDuplicatesInheritance3.swift +++ b/Tests/TestOverloads/FixtureDuplicatesInheritance3.swift @@ -1,17 +1,17 @@ import MockoloFramework let overload10 = """ -/// \(String.mockAnnotation) +/// @mockable protocol Foo { func update(arg: Int) } -/// \(String.mockAnnotation) +/// @mockable protocol Bar { func update(arg: Int) } -/// \(String.mockAnnotation) +/// @mockable protocol Baz: Foo, Bar { } """ diff --git a/Tests/TestOverloads/FixtureDuplicatesInheritance4.swift b/Tests/TestOverloads/FixtureDuplicatesInheritance4.swift index fda9fe63..47cca602 100644 --- a/Tests/TestOverloads/FixtureDuplicatesInheritance4.swift +++ b/Tests/TestOverloads/FixtureDuplicatesInheritance4.swift @@ -2,17 +2,17 @@ import MockoloFramework let duplicateSigInheritance4 = """ -/// \(String.mockAnnotation) +/// @mockable protocol Foo { func update(arg: Int) } -/// \(String.mockAnnotation) +/// @mockable protocol Bar: Foo { func update(arg: Int) } -/// \(String.mockAnnotation) +/// @mockable protocol Baz: Foo, Bar { } """ diff --git a/Tests/TestOverloads/FixtureDuplicatesInheritance5.swift b/Tests/TestOverloads/FixtureDuplicatesInheritance5.swift index e1bcb20b..c50077bf 100644 --- a/Tests/TestOverloads/FixtureDuplicatesInheritance5.swift +++ b/Tests/TestOverloads/FixtureDuplicatesInheritance5.swift @@ -1,20 +1,20 @@ import MockoloFramework let overload11 = """ -/// \(String.mockAnnotation) +/// @mockable protocol Foo { func update(arg: Int) func update(arg: Float) func display(param: String) } -/// \(String.mockAnnotation) +/// @mockable protocol Bar: Foo { func update(arg: Float) func display(param: Double) } -/// \(String.mockAnnotation) +/// @mockable protocol Baz: Foo, Bar { func display(param: Double) func display(param: Int) diff --git a/Tests/TestOverloads/FixtureFuncOverload1.swift b/Tests/TestOverloads/FixtureFuncOverload1.swift index 86731b96..13a13088 100644 --- a/Tests/TestOverloads/FixtureFuncOverload1.swift +++ b/Tests/TestOverloads/FixtureFuncOverload1.swift @@ -3,7 +3,7 @@ import MockoloFramework let overload1 = """ import AVFoundation -/// \(String.mockAnnotation) +/// @mockable protocol P1: P0 { } """ diff --git a/Tests/TestOverloads/FixtureFuncOverload2.swift b/Tests/TestOverloads/FixtureFuncOverload2.swift index 730ecb75..52817a16 100644 --- a/Tests/TestOverloads/FixtureFuncOverload2.swift +++ b/Tests/TestOverloads/FixtureFuncOverload2.swift @@ -2,7 +2,7 @@ import MockoloFramework let overload2 = """ -/// \(String.mockAnnotation) +/// @mockable public protocol Foo: Bar { func tell(status: Int, msg: String) -> Double } diff --git a/Tests/TestOverloads/FixtureInheritance.swift b/Tests/TestOverloads/FixtureInheritance.swift index 926e7e33..e28e6697 100644 --- a/Tests/TestOverloads/FixtureInheritance.swift +++ b/Tests/TestOverloads/FixtureInheritance.swift @@ -2,13 +2,13 @@ import MockoloFramework // MARK: Simple inheritance let simpleInheritance = """ -/// \(String.mockAnnotation) +/// @mockable public protocol SimpleChild: SimpleParent { var name: String { get set } func foo() } -/// \(String.mockAnnotation) +/// @mockable public protocol SimpleParent: AnyObject { var number: Int { get set } func bar(arg: Double) -> Float? @@ -87,7 +87,7 @@ protocol SecondSwiftProtocol { func doSomethingElse() -> Bool } -/// \(String.mockAnnotation) +/// @mockable protocol TestProtocol: FirstSwiftProtocol & SecondSwiftProtocol { func doSomethingSpecial() } diff --git a/Tests/TestOverrides/FixtureMockNames.swift b/Tests/TestOverrides/FixtureMockNames.swift index 32cb7cec..49af58cd 100644 --- a/Tests/TestOverrides/FixtureMockNames.swift +++ b/Tests/TestOverrides/FixtureMockNames.swift @@ -2,7 +2,7 @@ import Foundation let nameOverride = """ -/// \(String.mockAnnotation)(override: name = FooMock) +/// @mockable(override: name = FooMock) protocol FooProtocol { func display() } diff --git a/Tests/TestPATs/FixturePAT.swift b/Tests/TestPATs/FixturePAT.swift index 930c7d03..cb39f757 100644 --- a/Tests/TestPATs/FixturePAT.swift +++ b/Tests/TestPATs/FixturePAT.swift @@ -1,22 +1,22 @@ import MockoloFramework let patNameCollision = """ -/// \(String.mockAnnotation) +/// @mockable protocol Foo { associatedtype T } -/// \(String.mockAnnotation) +/// @mockable protocol Bar { associatedtype T: String } -/// \(String.mockAnnotation)(typealias: T = Hashable & Codable) +/// @mockable(typealias: T = Hashable & Codable) protocol Cat { associatedtype T } -/// \(String.mockAnnotation) +/// @mockable protocol Baz: Foo, Bar, Cat { } """ @@ -46,7 +46,7 @@ class BazMock: Baz { let simplePat = """ -/// \(String.mockAnnotation)(typealias: T = String) +/// @mockable(typealias: T = String) public protocol FooBar: Foo { associatedtype T } @@ -70,7 +70,7 @@ public class FooBarMock: FooBar { let patOverride = """ -/// \(String.mockAnnotation)(typealias: T = Any; U = Bar; R = (String, Int); S = AnyObject) +/// @mockable(typealias: T = Any; U = Bar; R = (String, Int); S = AnyObject) protocol Foo { associatedtype T associatedtype U: Collection where U.Element == T @@ -103,7 +103,7 @@ class FooMock: Foo { """ let protocolWithTypealias = """ -/// \(String.mockAnnotation) +/// @mockable public protocol SomeType { typealias Key = String var key: Key { get } @@ -128,7 +128,7 @@ public class SomeTypeMock: SomeType { """ let patDefaultType = """ -/// \(String.mockAnnotation) +/// @mockable protocol Foo { associatedtype T associatedtype U: Collection where U.Element == T @@ -145,7 +145,7 @@ class FooMock: Foo { """ let patPartialOverride = """ -/// \(String.mockAnnotation)(typealias: U = AnyObject) +/// @mockable(typealias: U = AnyObject) protocol Foo { associatedtype T associatedtype U: Collection where U.Element == T diff --git a/Tests/TestRx/FixtureRxVars.swift b/Tests/TestRx/FixtureRxVars.swift index 9d28d217..f636ebcf 100644 --- a/Tests/TestRx/FixtureRxVars.swift +++ b/Tests/TestRx/FixtureRxVars.swift @@ -2,7 +2,7 @@ import MockoloFramework let rxSubjects = """ -/// \(String.mockAnnotation) +/// @mockable public protocol Foo: AnyObject { var someBehavior: BehaviorSubject { get } var someReply: ReplaySubject { get } @@ -50,7 +50,7 @@ public class FooMock: Foo { """ let rx = """ -/// \(String.mockAnnotation)(rx: attachedRouter = BehaviorSubject) +/// @mockable(rx: attachedRouter = BehaviorSubject) protocol TaskRouting: BaseRouting { var attachedRouter: Observable { get } func routeToFoo() -> Observable<()> @@ -86,7 +86,7 @@ class TaskRoutingMock: TaskRouting { let rxObservables = """ -/// \(String.mockAnnotation)(rx: nameStream = BehaviorSubject; integerStream = ReplaySubject) +/// @mockable(rx: nameStream = BehaviorSubject; integerStream = ReplaySubject) protocol RxVar { var isEnabled: Observable { get } var nameStream: Observable<[EMobilitySearchVehicle]> { get } @@ -131,12 +131,12 @@ class RxVarMock: RxVar { let rxVarInherited = """ -/// \(String.mockAnnotation)(rx: all = BehaviorSubject) +/// @mockable(rx: all = BehaviorSubject) public protocol X { var myKey: Observable { get } } -/// \(String.mockAnnotation) +/// @mockable public protocol Y: X { func update(with key: SomeKey) } @@ -189,7 +189,7 @@ public class YMock: Y { let rxMultiParents = """ -/// \(String.mockAnnotation) +/// @mockable public protocol TasksStream: BaseTasksStream { func update(tasks: Tasks) } @@ -198,31 +198,31 @@ public protocol BaseTasksStream: BaseTaskScopeListStream, WorkTaskScopeListStrea var tasks: Observable { get } } -/// \(String.mockAnnotation)(rx: all = ReplaySubject) +/// @mockable(rx: all = ReplaySubject) public protocol BaseTaskScopeListStream: AnyObject { var taskScopes: Observable<[TaskScope]> { get } } -/// \(String.mockAnnotation)(rx: all = ReplaySubject) +/// @mockable(rx: all = ReplaySubject) public protocol WorkTaskScopeListStream: AnyObject { var workTaskScopes: Observable<[TaskScope]> { get } } -/// \(String.mockAnnotation) +/// @mockable public protocol OnlineStream: AnyObject { var online: Observable { get } } -/// \(String.mockAnnotation) +/// @mockable public protocol StateStream: AnyObject { var state: Observable { get } } -/// \(String.mockAnnotation)(rx: all = BehaviorSubject) +/// @mockable(rx: all = BehaviorSubject) public protocol WorkStateStream: AnyObject { var isOnJob: Observable { get } } -/// \(String.mockAnnotation)(rx: all = BehaviorSubject) +/// @mockable(rx: all = BehaviorSubject) public protocol CompletionTasksStream: AnyObject { var completionTasks: Observable<[CompletionTask]> { get } } diff --git a/Tests/TestSendable/FixtureSendable.swift b/Tests/TestSendable/FixtureSendable.swift index 95514fa1..80398725 100644 --- a/Tests/TestSendable/FixtureSendable.swift +++ b/Tests/TestSendable/FixtureSendable.swift @@ -1,7 +1,7 @@ import MockoloFramework let sendableProtocol = """ -/// \(String.mockAnnotation) +/// @mockable public protocol SendableProtocol: Sendable { func update(arg: Int) -> String func update(arg0: some Sendable, arg1: AnyObject) async throws @@ -65,7 +65,7 @@ public final class SendableProtocolMock: SendableProtocol, @unchecked Sendable { let uncheckedSendableClass = """ -/// \(String.mockAnnotation) +/// @mockable public class UncheckedSendableClass: @unchecked Sendable { func update(arg: Int) -> String } @@ -102,7 +102,7 @@ public protocol SendableSendable: Sendable { func update(arg: Int) -> String } -/// \(String.mockAnnotation) +/// @mockable public protocol ConfirmedSendableProtocol: SendableSendable { } """ @@ -134,7 +134,7 @@ public final class ConfirmedSendableProtocolMock: ConfirmedSendableProtocol, @un """# let generatedConcurrencyHelpers = """ -/// \(String.mockAnnotation) +/// @mockable public protocol SendableProtocol: Sendable { } """ diff --git a/Tests/TestSupportMacros.swift b/Tests/TestSupportMacros.swift new file mode 100644 index 00000000..e6381389 --- /dev/null +++ b/Tests/TestSupportMacros.swift @@ -0,0 +1,2 @@ +@attached(member, names: named(_source)) +macro Fixture() = #externalMacro(module: "MockoloTestSupportMacros", type: "Fixture") diff --git a/Tests/TestTestableImports/FixtureTestableImportStatements.swift b/Tests/TestTestableImports/FixtureTestableImportStatements.swift index 9ac2a33b..d262e7bb 100644 --- a/Tests/TestTestableImports/FixtureTestableImportStatements.swift +++ b/Tests/TestTestableImports/FixtureTestableImportStatements.swift @@ -4,7 +4,7 @@ let testableImports = """ \(String.headerDoc) import Foundation -/// \(String.mockAnnotation) +/// @mockable protocol SimpleVar { var name: Int { get set } } @@ -32,7 +32,7 @@ let testableImportsWithOverlap = """ import Foundation import SomeImport1 -/// \(String.mockAnnotation) +/// @mockable protocol SimpleVar { var name: Int { get set } } diff --git a/Tests/TestThrowingErrors/ThrowingErrorsTests.swift b/Tests/TestThrowingErrors/ThrowingErrorsTests.swift index 51cff828..44b0df09 100644 --- a/Tests/TestThrowingErrors/ThrowingErrorsTests.swift +++ b/Tests/TestThrowingErrors/ThrowingErrorsTests.swift @@ -10,8 +10,8 @@ class ThrowingErrorsTests: MockoloTestCase { "\(nonExistentDstDirPath) is expected not to exist, but it exists" ) - verifyThrows(srcContent: simpleFuncs, - dstContent: simpleFuncsMock, + verifyThrows(srcContent: simpleFuncs._source, + dstContent: simpleFuncs.expected._source, dstFilePath: nonExistentDstDirPath + "/Dst.swift") } } diff --git a/Tests/TestTuplesBrackets/FixtureTuplesBrackets.swift b/Tests/TestTuplesBrackets/FixtureTuplesBrackets.swift index 933c1970..a54bb5d7 100644 --- a/Tests/TestTuplesBrackets/FixtureTuplesBrackets.swift +++ b/Tests/TestTuplesBrackets/FixtureTuplesBrackets.swift @@ -2,7 +2,7 @@ import MockoloFramework let tuplesBrackets = """ -/// \(String.mockAnnotation) +/// @mockable protocol NonSimpleTypes { func variadicFunc(_ arg: Int, for key: String) func variadicFunc(_ arg: Int, for key: String...) diff --git a/Tests/TestVars/FixtureAsyncThrowsVars.swift b/Tests/TestVars/FixtureAsyncThrowsVars.swift index c73e579d..b4955c22 100644 --- a/Tests/TestVars/FixtureAsyncThrowsVars.swift +++ b/Tests/TestVars/FixtureAsyncThrowsVars.swift @@ -1,7 +1,7 @@ import MockoloFramework let asyncThrowsVars = """ -/// \(String.mockAnnotation) +/// @mockable public protocol AsyncThrowsVars { var getOnly: Int { get } static var getAndSet: Int { get set } @@ -60,7 +60,7 @@ public class AsyncThrowsVarsMock: AsyncThrowsVars { """ let throwsNeverVars = """ -/// \(String.mockAnnotation) +/// @mockable protocol P { var foo: Int { get throws(Never) } } diff --git a/Tests/TestVars/FixtureNonSimpleVars.swift b/Tests/TestVars/FixtureNonSimpleVars.swift index 2a7115c1..dfb9d1c0 100644 --- a/Tests/TestVars/FixtureNonSimpleVars.swift +++ b/Tests/TestVars/FixtureNonSimpleVars.swift @@ -3,7 +3,7 @@ import MockoloFramework let nonSimpleVars = """ import Foundation -/// \(String.mockAnnotation) +/// @mockable @objc public protocol NonSimpleVars { @available(iOS 10.0, *) diff --git a/Tests/TestVars/FixtureSimpleVars.swift b/Tests/TestVars/FixtureSimpleVars.swift index c85d1442..576b3c33 100644 --- a/Tests/TestVars/FixtureSimpleVars.swift +++ b/Tests/TestVars/FixtureSimpleVars.swift @@ -4,7 +4,7 @@ let simpleVars = """ \(String.headerDoc) import Foundation -/// \(String.mockAnnotation) +/// @mockable protocol SimpleVar { var name: Int { get set } } diff --git a/Tests/Types.swift b/Tests/Types.swift new file mode 100644 index 00000000..ef6e7286 --- /dev/null +++ b/Tests/Types.swift @@ -0,0 +1,3 @@ +@MainActor class UIViewController {} +struct CGImage {} +struct CGRect {}