Skip to content

Commit

Permalink
Add test to ignore all except stored properties
Browse files Browse the repository at this point in the history
  • Loading branch information
pitt500 committed Aug 12, 2023
1 parent a7153e2 commit 244a217
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 15 deletions.
54 changes: 41 additions & 13 deletions Sources/SwiftAndTipsMacrosClient/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,44 @@ print(x)
// var array2: [Int]
//}

@SampleBuilder(numberOfItems: 3)
struct Example {
let x: Int
var y: String

static var notAValidStoredProperty: Self {
.init(x: 0, y: "Hello World")
}

var aComputedProperty: String {
"Hello"
}
}
//@SampleBuilder(numberOfItems: 3)
//struct Example {
// let x: Int
// var y: String
//
// static var notAValidStoredProperty: Self {
// .init(x: 0, y: "Hello World")
// }
//
// var aComputedProperty: String {
// "Hello"
// }
//}


//@SampleBuilder(numberOfItems: 3)
//struct Example {
// let x: Int
// private var y: String {
// didSet {
// print("didSet called")
// }
// willSet {
// print("willSet called")
// }
// }
// static var asd: Self {
// .init(x: 0, y: "Hello World")
// }
// var z: String {
// get { y }
// }
// var w: String {
// get {
// y
// }
// set {
// y = newValue
// }
// }
//}
78 changes: 76 additions & 2 deletions Tests/SwiftAndTipsMacrosTests/SampleBuilderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ final class SampleBuilderTests: XCTestCase {
@SampleBuilder(numberOfItems: 3)
struct Example {
let x: Int
var y: String
private var y: String
static var asd: Self {
.init(x: 0, y: "Hello World")
}
Expand All @@ -219,7 +219,7 @@ final class SampleBuilderTests: XCTestCase {
expandedSource: """
struct Example {
let x: Int
var y: String
private var y: String
static var asd: Self {
.init(x: 0, y: "Hello World")
}
Expand All @@ -238,4 +238,78 @@ final class SampleBuilderTests: XCTestCase {
throw XCTSkip("macros are only supported when running tests for the host platform")
#endif
}

func testSampleBuilderMacro_ignore_not_stored_properties() throws{
#if canImport(Macros)
assertMacroExpansion(
#"""
@SampleBuilder(numberOfItems: 3)
struct Example {
let x: Int
private var y: String {
didSet {
print("didSet called")
}
willSet {
print("willSet called")
}
}
static var asd: Self {
.init(x: 0, y: "Hello World")
}
var z: String {
get { y }
}
var w: String {
get {
y
}
set {
y = newValue
}
}
}
"""#,
expandedSource: """
struct Example {
let x: Int
private var y: String {
didSet {
print("didSet called")
}
willSet {
print("willSet called")
}
}
static var asd: Self {
.init(x: 0, y: "Hello World")
}
var z: String {
get {
y
}
}
var w: String {
get {
y
}
set {
y = newValue
}
}
static var sample: [Self] {
[
.init(x: 0, y: "Hello World"),
.init(x: 0, y: "Hello World"),
.init(x: 0, y: "Hello World"),
]
}
}
""",
macros: testMacros
)
#else
throw XCTSkip("macros are only supported when running tests for the host platform")
#endif
}
}

0 comments on commit 244a217

Please sign in to comment.