Skip to content

Commit c0584cc

Browse files
committed
Fix generating initialiser when variable has fileprivate access level and create separate test data target
1 parent 444598e commit c0584cc

5 files changed

Lines changed: 62 additions & 3 deletions

File tree

Package.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ let package = Package(
2121
]
2222
),
2323
.target(name: "Buildable", dependencies: ["BuildableMacro"]),
24-
.executableTarget(name: "BuildableClient", dependencies: ["Buildable"]),
24+
.target(name: "BuildableClientTestData", dependencies: ["Buildable"]),
25+
.executableTarget(name: "BuildableClient", dependencies: ["Buildable", "BuildableClientTestData"]),
2526
.testTarget(
2627
name: "BuildableMacroTests",
2728
dependencies: [

Sources/BuildableClient/main.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Buildable
22
import Foundation
3+
import BuildableClientTestData
34

45
@Buildable
56
public struct MyObject {
@@ -97,3 +98,5 @@ public struct Address: Sendable {}
9798
let anyPerson = PersonBuilder().build()
9899
let max = PersonBuilder(name: "Max", favouriteSeason: .summer).build()
99100
let appState = AppStateBuilder(persons: [max]).build()
101+
102+
let myObject = MyObjectBuilder().build()
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import Buildable
2+
import Foundation
3+
4+
@Buildable
5+
public struct MyObject {
6+
let m01: String
7+
let m02: Int
8+
let m03: Int8
9+
let m04: Int16
10+
let m05: Int32
11+
let m06: Int64
12+
let m07: UInt
13+
let m08: UInt8
14+
let m09: UInt16
15+
let m10: UInt32
16+
let m11: UInt64
17+
let m12: Bool
18+
let m13: Double
19+
let m14: Float
20+
let m15: Date
21+
let m16: UUID
22+
let m17: Data
23+
let m18: URL
24+
let m19: CGFloat
25+
let m20: CGPoint
26+
let m21: CGRect
27+
let m22: CGSize
28+
let m23: CGVector
29+
let m24: String?
30+
let m25: String!
31+
let m26: [String]
32+
let m27: [String: String]
33+
var m28: String
34+
let m29: () -> Void
35+
let m30: (() -> Void)?
36+
let m31: (() -> Void)!
37+
let m32: (String) -> Void
38+
let m33: ((String) -> Void)?
39+
let m34: (String, Int) -> Void
40+
let m35: (String, Int) -> String
41+
var myEnum: MyEnum
42+
}
43+
44+
@MainActor
45+
let abc = MyObjectBuilder().build()
46+
47+
@Buildable
48+
public enum MyEnum {
49+
case `none`
50+
case myCase
51+
}

Sources/BuildableMacro/StructAndClass/Helper/ExtractMembers.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ private func hasStaticModifier(_ variable: VariableDeclSyntax) -> Bool {
3636
}
3737

3838
private func hasPrivateModifier(_ variable: VariableDeclSyntax) -> Bool {
39-
variable.modifiers.contains(where: { $0.name.text.contains("private") })
39+
variable.modifiers.contains(where: { $0.name.text == "private" })
4040
}
4141

4242
private func isConstant(_ variable: VariableDeclSyntax) -> Bool {

Tests/BuildableMacroTests/BuildableStructTests.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ class BuildableStructTests: XCTestCase {
260260
let m1: String?
261261
private var m2: String?
262262
public var m3: String?
263+
fileprivate var m4: String?
263264
}
264265
""",
265266
expandedSource: """
@@ -268,16 +269,19 @@ class BuildableStructTests: XCTestCase {
268269
let m1: String?
269270
private var m2: String?
270271
public var m3: String?
272+
fileprivate var m4: String?
271273
}
272274
273275
struct MyObjectBuilder {
274276
var m1: String?
275277
var m3: String?
278+
var m4: String?
276279
277280
func build() -> MyObject {
278281
return MyObject(
279282
m1: m1,
280-
m3: m3
283+
m3: m3,
284+
m4: m4
281285
)
282286
}
283287
}

0 commit comments

Comments
 (0)