Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix spies variables access level #64

Merged
merged 1 commit into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions Sources/Rubicon/Generator/SpyGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,24 @@ final class SpyGenerator {
private let functionNameGenerator: FunctionNameGenerator
private let initGenerator: InitGenerator
private let structGenerator: StructGenerator
private let accessLevelGenerator: AccessLevelGenerator

init(
protocolGenerator: ProtocolGenerator,
variableGenerator: VariableGenerator,
functionGenerator: FunctionGenerator,
functionNameGenerator: FunctionNameGenerator,
initGenerator: InitGenerator,
structGenerator: StructGenerator
structGenerator: StructGenerator,
accessLevelGenerator: AccessLevelGenerator
) {
self.protocolGenerator = protocolGenerator
self.variableGenerator = variableGenerator
self.functionGenerator = functionGenerator
self.functionNameGenerator = functionNameGenerator
self.initGenerator = initGenerator
self.structGenerator = structGenerator
self.accessLevelGenerator = accessLevelGenerator
}

func generate(from protocolType: ProtocolDeclaration) -> String {
Expand Down Expand Up @@ -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)]()"
}
}

Expand Down
3 changes: 2 additions & 1 deletion Sources/Rubicon/Integration/Rubicon.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}

Expand Down
15 changes: 9 additions & 6 deletions Tests/RubiconTests/Generator/SpyGeneratorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
)
}

Expand Down Expand Up @@ -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",
"",
Expand Down Expand Up @@ -114,7 +117,7 @@ final class SpyGeneratorTests: XCTestCase {
])
equal(protocolGeneratorSpy.makeProtocol.first?.content, rows: [
"variable",
"var functionNameCount = 0",
"accessLevel var functionNameCount = 0",
"",
"init",
"",
Expand All @@ -140,7 +143,7 @@ final class SpyGeneratorTests: XCTestCase {
])
equal(protocolGeneratorSpy.makeProtocol.first?.content, rows: [
"variable",
"var functionNameCount = 0",
"accessLevel var functionNameCount = 0",
"",
"init",
"",
Expand Down Expand Up @@ -172,7 +175,7 @@ final class SpyGeneratorTests: XCTestCase {
equal(protocolGeneratorSpy.makeProtocol.first?.content, rows: [
"variable",
"variable",
"var functionNameCount = 0",
"accessLevel var functionNameCount = 0",
"",
"init",
"",
Expand All @@ -189,7 +192,7 @@ final class SpyGeneratorTests: XCTestCase {
equal(protocolGeneratorSpy.makeProtocol.first?.content, rows: [
"struct",
"",
"var functionName = [StructName]()",
"accessLevel var functionName = [StructName]()",
"",
"init",
"",
Expand Down
Loading