Skip to content

Commit aca3d6d

Browse files
Kyle-Yeclaude
andcommitted
Update macro tests with extension conformance tests
- Add testMacroSpecs for testing Observable conformance extension - Add testBasicObservableExtension to test with @ObservationIgnored and extension - Fix typo in testMacroSpecs variable name - Add author comment to test file 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 24c959c commit aca3d6d

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

Tests/OpenObservationMacroTests/OpenObservationMacroTests.swift

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// OpenObservationMacroTests.swift
33
// OpenObservationTests
44
//
5+
// Created by Kyle on 2025/8/30.
6+
//
57

68
import SwiftSyntax
79
import SwiftSyntaxBuilder
@@ -19,9 +21,49 @@ let testMacros: [String: Macro.Type] = [
1921
"ObservationIgnored": ObservationIgnoredMacro.self,
2022
]
2123

24+
let testMacroSpecs: [String: MacroSpec] = [
25+
"Observable": .init(type: ObservableMacro.self, conformances: ["Observable"]),
26+
]
27+
2228
#endif
2329

2430
final class OpenObservationMacroTests: XCTestCase {
31+
func testBasicObservableExtension() throws {
32+
#if canImport(OpenObservationMacros)
33+
assertMacroExpansion(
34+
"""
35+
@Observable
36+
class Model {}
37+
""",
38+
expandedSource: """
39+
class Model {
40+
41+
@ObservationIgnored private let _$observationRegistrar = OpenObservation.ObservationRegistrar()
42+
43+
internal nonisolated func access<Member>(
44+
keyPath: KeyPath<Model, Member>
45+
) {
46+
_$observationRegistrar.access(self, keyPath: keyPath)
47+
}
48+
49+
internal nonisolated func withMutation<Member, MutationResult>(
50+
keyPath: KeyPath<Model, Member>,
51+
_ mutation: () throws -> MutationResult
52+
) rethrows -> MutationResult {
53+
try _$observationRegistrar.withMutation(of: self, keyPath: keyPath, mutation)
54+
}
55+
}
56+
57+
extension Model: OpenObservation.Observable {
58+
}
59+
""",
60+
macroSpecs: testMacroSpecs
61+
)
62+
#else
63+
throw XCTSkip("macros are only supported when running tests for the host platform")
64+
#endif
65+
}
66+
2567
func testBasicObservable() throws {
2668
#if canImport(OpenObservationMacros)
2769
assertMacroExpansion(
@@ -688,4 +730,4 @@ final class OpenObservationMacroTests: XCTestCase {
688730
throw XCTSkip("macros are only supported when running tests for the host platform")
689731
#endif
690732
}
691-
}
733+
}

0 commit comments

Comments
 (0)