From 7b74472443b05d55ba92e00149aa1571276ff662 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kry=C5=A1tof=20Mat=C4=9Bj?= Date: Thu, 28 Mar 2024 17:39:06 +0100 Subject: [PATCH] Fix spies variables access level --- Sources/Rubicon/Generator/SpyGenerator.swift | 9 ++++++--- Sources/Rubicon/Integration/Rubicon.swift | 3 ++- .../Generator/SpyGeneratorTests.swift | 15 +++++++++------ 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/Sources/Rubicon/Generator/SpyGenerator.swift b/Sources/Rubicon/Generator/SpyGenerator.swift index cd97bdb..ba8d61f 100644 --- a/Sources/Rubicon/Generator/SpyGenerator.swift +++ b/Sources/Rubicon/Generator/SpyGenerator.swift @@ -5,6 +5,7 @@ final class SpyGenerator { private let functionNameGenerator: FunctionNameGenerator private let initGenerator: InitGenerator private let structGenerator: StructGenerator + private let accessLevelGenerator: AccessLevelGenerator init( protocolGenerator: ProtocolGenerator, @@ -12,7 +13,8 @@ final class SpyGenerator { functionGenerator: FunctionGenerator, functionNameGenerator: FunctionNameGenerator, initGenerator: InitGenerator, - structGenerator: StructGenerator + structGenerator: StructGenerator, + accessLevelGenerator: AccessLevelGenerator ) { self.protocolGenerator = protocolGenerator self.variableGenerator = variableGenerator @@ -20,6 +22,7 @@ final class SpyGenerator { self.functionNameGenerator = functionNameGenerator self.initGenerator = initGenerator self.structGenerator = structGenerator + self.accessLevelGenerator = accessLevelGenerator } func generate(from protocolType: ProtocolDeclaration) -> String { @@ -90,10 +93,10 @@ final class SpyGenerator { let name = functionNameGenerator.makeUniqueName(for: declaration, in: protocolDeclaration.functions) if declaration.arguments.isEmpty { - return "var \(name)Count = 0" + return "\(accessLevelGenerator.makeContentAccessLevel())var \(name)Count = 0" } else { let structName = functionNameGenerator.makeStructUniqueName(for: declaration, in: protocolDeclaration.functions) - return "var \(name) = [\(structName)]()" + return "\(accessLevelGenerator.makeContentAccessLevel())var \(name) = [\(structName)]()" } } diff --git a/Sources/Rubicon/Integration/Rubicon.swift b/Sources/Rubicon/Integration/Rubicon.swift index b564f5c..272baff 100644 --- a/Sources/Rubicon/Integration/Rubicon.swift +++ b/Sources/Rubicon/Integration/Rubicon.swift @@ -76,7 +76,8 @@ public final class Rubicon { functionGenerator: dependencies.functionGenerator, functionNameGenerator: dependencies.functionNameGenerator, initGenerator: dependencies.initGenerator, - structGenerator: dependencies.structGenerator + structGenerator: dependencies.structGenerator, + accessLevelGenerator: dependencies.accessLevelGenerator ) } diff --git a/Tests/RubiconTests/Generator/SpyGeneratorTests.swift b/Tests/RubiconTests/Generator/SpyGeneratorTests.swift index 621e340..1eb664f 100644 --- a/Tests/RubiconTests/Generator/SpyGeneratorTests.swift +++ b/Tests/RubiconTests/Generator/SpyGeneratorTests.swift @@ -8,6 +8,7 @@ final class SpyGeneratorTests: XCTestCase { private var functionNameGeneratorSpy: FunctionNameGeneratorSpy! private var initGeneratorSpy: InitGeneratorSpy! private var structGeneratorSpy: StructGeneratorSpy! + private var accessLevelGeneratorSpy: AccessLevelGeneratorSpy! private var sut: SpyGenerator! private let type = TypeDeclaration.makeStub(name: "Color", isOptional: false) @@ -19,13 +20,15 @@ final class SpyGeneratorTests: XCTestCase { functionNameGeneratorSpy = FunctionNameGeneratorSpy(makeUniqueNameReturn: "functionName", makeStructUniqueNameReturn: "StructName") initGeneratorSpy = InitGeneratorSpy(makeCodeReturn: ["init"]) structGeneratorSpy = StructGeneratorSpy(makeCodeReturn: ["struct"]) + accessLevelGeneratorSpy = AccessLevelGeneratorSpy(makeClassAccessLevelReturn: "", makeContentAccessLevelReturn: "accessLevel ") sut = SpyGenerator( protocolGenerator: protocolGeneratorSpy, variableGenerator: variableGeneratorSpy, functionGenerator: functionGeneratorSpy, functionNameGenerator: functionNameGeneratorSpy, initGenerator: initGeneratorSpy, - structGenerator: structGeneratorSpy + structGenerator: structGeneratorSpy, + accessLevelGenerator: accessLevelGeneratorSpy ) } @@ -85,7 +88,7 @@ final class SpyGeneratorTests: XCTestCase { _ = sut.generate(from: protocolDeclaration) equal(protocolGeneratorSpy.makeProtocol.first?.content, rows: [ - "var functionNameCount = 0", + "accessLevel var functionNameCount = 0", "", "init", "", @@ -114,7 +117,7 @@ final class SpyGeneratorTests: XCTestCase { ]) equal(protocolGeneratorSpy.makeProtocol.first?.content, rows: [ "variable", - "var functionNameCount = 0", + "accessLevel var functionNameCount = 0", "", "init", "", @@ -140,7 +143,7 @@ final class SpyGeneratorTests: XCTestCase { ]) equal(protocolGeneratorSpy.makeProtocol.first?.content, rows: [ "variable", - "var functionNameCount = 0", + "accessLevel var functionNameCount = 0", "", "init", "", @@ -172,7 +175,7 @@ final class SpyGeneratorTests: XCTestCase { equal(protocolGeneratorSpy.makeProtocol.first?.content, rows: [ "variable", "variable", - "var functionNameCount = 0", + "accessLevel var functionNameCount = 0", "", "init", "", @@ -189,7 +192,7 @@ final class SpyGeneratorTests: XCTestCase { equal(protocolGeneratorSpy.makeProtocol.first?.content, rows: [ "struct", "", - "var functionName = [StructName]()", + "accessLevel var functionName = [StructName]()", "", "init", "",