Skip to content

Commit

Permalink
Merge pull request #64 from raptorxcz/bugfix/access-level
Browse files Browse the repository at this point in the history
Fix spies variables access level
  • Loading branch information
raptorxcz authored Mar 28, 2024
2 parents da8135a + 7b74472 commit e4676a8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
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

0 comments on commit e4676a8

Please sign in to comment.