File tree Expand file tree Collapse file tree 3 files changed +46
-3
lines changed
Sources/StructTransactionMacros
Tests/StructTransactionTests Expand file tree Collapse file tree 3 files changed +46
-3
lines changed Original file line number Diff line number Diff line change @@ -111,7 +111,7 @@ extension COWTrackingPropertyMacro: AccessorMacro {
111
111
$0.write(identifier: .init(name: " \( raw: propertyName) " ))
112
112
}
113
113
if !isKnownUniquelyReferenced(& \( raw: backingName) ) {
114
- \( raw: backingName) = .init( \( raw : backingName ) .value )
114
+ \( raw: backingName) = .init(newValue )
115
115
} else {
116
116
\( raw: backingName) .value = newValue
117
117
}
Original file line number Diff line number Diff line change @@ -2,6 +2,10 @@ import StructTransaction
2
2
3
3
@Tracking
4
4
struct MyState {
5
+
6
+ init ( ) {
7
+ self . name = " "
8
+ }
5
9
6
10
var height : Int = 0
7
11
Original file line number Diff line number Diff line change
1
+ import StructTransaction
1
2
import Testing
2
3
3
4
@Suite ( " Tests " )
4
- enum Tests {
5
-
5
+ struct Tests {
6
+
7
+ @Test
8
+ func tracking_stored_property( ) {
9
+
10
+ var original = MyState . init ( )
11
+
12
+ let result = withTracking {
13
+ original. height = 100
14
+ }
15
+
16
+ #expect( result. writeIdentifiers. contains ( . init( name: " height " ) ) )
17
+
18
+ }
19
+
20
+ @Test
21
+ func tracking_computed_property( ) {
22
+
23
+ let original = MyState . init ( )
24
+
25
+ let result = withTracking {
26
+ let _ = original. computedName
27
+ }
28
+
29
+ #expect( result. readIdentifiers. contains ( . init( name: " name " ) ) )
30
+
31
+ }
32
+
33
+ @Test
34
+ func cow( ) {
35
+
36
+ let original = MyState . init ( )
37
+
38
+ var copy = original
39
+
40
+ copy. height = 100
41
+
42
+ #expect( copy. height == 100 )
43
+ #expect( original. height == 0 )
44
+ }
6
45
}
You can’t perform that action at this time.
0 commit comments