SwiftUI/지식 창고
Write Swift macros(2)
jgkim1008
2024. 11. 13. 23:51
Macro tests
- test를 통해 매크로의 에러 여부를 파악할수 있다.
let testMacros: [String: Macro.Type] = [
"SlopeSubset" : SlopeSubsetMacro.self,
]
final class WWDCTests: XCTestCase {
func testSlopeSubset() {
assertMacroExpansion(
"""
@SlopeSubset
enum EasySlope {
case beginnersParadise
case practiceRun
}
""",
expandedSource: """
enum EasySlope {
case beginnersParadise
case practiceRun
init?(_ slope: Slope) {
switch slope {
case .beginnersParadise:
self = .beginnersParadise
case .practiceRun:
self = .practiceRun
default:
return nil
}
}
}
""",
macros: testMacros
)
}
}
- 해당 wwdc 영상은 추후 한번더 확인해봐야겠다.