Skip to content

Commit 21ce788

Browse files
committed
add test case for other policy
1 parent 7e07f70 commit 21ce788

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

Tests/AssociatedObjectTests/AssociatedObjectTests.swift

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,38 @@ final class AssociatedObjectTests: XCTestCase {
7272
)
7373
}
7474

75+
func testStringWithOtherPolicy() throws {
76+
assertMacroExpansion(
77+
"""
78+
@AssociatedObject(.OBJC_ASSOCIATION_COPY)
79+
var string: String = "text"
80+
""",
81+
expandedSource:
82+
"""
83+
var string: String = "text" {
84+
get {
85+
objc_getAssociatedObject(
86+
self,
87+
&Self.__associated_stringKey
88+
) as? String
89+
?? "text"
90+
}
91+
set {
92+
objc_setAssociatedObject(
93+
self,
94+
&Self.__associated_stringKey,
95+
newValue,
96+
.OBJC_ASSOCIATION_COPY
97+
)
98+
}
99+
}
100+
101+
static var __associated_stringKey: UInt8 = 0
102+
""",
103+
macros: macros
104+
)
105+
}
106+
75107
func testOptionalString() throws {
76108
assertMacroExpansion(
77109
"""

0 commit comments

Comments
 (0)