Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Sources/StateStruct/TrackingRuntime.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ public enum TrackingRuntime {
value: Optional<WrappedValue>,
trackingContext: borrowing _TrackingContext
) -> WrappedValue? {

guard let value = value else {
return nil
}

return dynamic_processGet(component: component, value: value, trackingContext: trackingContext)
return dynamic_processGet(
component: component,
value: value,
trackingContext: trackingContext
)

}

Expand Down
7 changes: 7 additions & 0 deletions Tests/StateStructTests/MyState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,9 @@ struct MyState {

var nested: Nested = .init(name: "")
var nestedAttached: NestedAttached = .init(name: "")

var optional_custom_type: CustomType?
var optional_int: Int?

@Tracking
struct Nested {
Expand All @@ -610,3 +613,7 @@ struct MyState {
}

}

enum CustomType {
case a
}
42 changes: 42 additions & 0 deletions Tests/StateStructTests/TrackingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,48 @@ import Testing

@Suite("TrackingTests")
struct TrackingTests {

@Test
func read_optional_custom_tyupe() {

var original = MyState.init()

original.startNewTracking()
_ = original.optional_custom_type
let result = original.trackingResult!

original.endTracking()

#expect(
result.graph.prettyPrint() == """
StateStructTests.MyState {
optional_custom_type-(1)
}
"""
)

}

@Test
func read_optional_int() {

var original = MyState.init()

original.startNewTracking()
_ = original.optional_int
let result = original.trackingResult!

original.endTracking()

#expect(
result.graph.prettyPrint() == """
StateStructTests.MyState {
optional_int-(1)
}
"""
)

}

@Test
func tracking_stored_property() {
Expand Down