Skip to content

Commit 61977d9

Browse files
committed
test(identity): cover seed allocation and invalid reads
1 parent 6a86cb8 commit 61977d9

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
//
2+
// IdentityLinkTests.swift
3+
// OpenSwiftUITests
4+
5+
import OpenAttributeGraphShims
6+
#if OPENSWIFTUI_ENABLE_PRIVATE_IMPORTS
7+
@_private(sourceFile: "IdentityLink.swift")
8+
#endif
9+
@testable import OpenSwiftUI
10+
@_spi(ForOpenSwiftUIOnly) import OpenSwiftUICore
11+
import Testing
12+
13+
@MainActor
14+
@Suite
15+
struct IdentityLinkTests {
16+
@Test
17+
func seed() {
18+
let identities = (0..<64).map { _ in ViewIdentity() }
19+
#expect(Set(identities).count == 64)
20+
#expect(!identities.contains(.invalid))
21+
}
22+
23+
#if OPENSWIFTUI_ENABLE_PRIVATE_IMPORTS
24+
@Test
25+
func overflow() {
26+
ViewIdentity.nextSeed = UInt32.max
27+
let id1 = ViewIdentity()
28+
#expect(id1.seed == UInt32.max)
29+
let id2 = ViewIdentity()
30+
#expect(id2 != .invalid)
31+
#expect(id2.seed == 1)
32+
}
33+
#endif
34+
35+
#if !os(iOS) && !os(visionOS)
36+
@Test
37+
func readingBeforeInstallationFails() async throws {
38+
let result = try await #require(
39+
processExitsWith: .failure,
40+
observing: [\.standardErrorContent]
41+
) {
42+
_ = IdentityLink().wrappedValue
43+
}
44+
#if DEBUG
45+
let diagnostic = String(decoding: result.standardErrorContent, as: UTF8.self)
46+
#expect(diagnostic.contains("Reading IdentityLink outside View.body"))
47+
#else
48+
_ = result
49+
#endif
50+
}
51+
#endif
52+
}

0 commit comments

Comments
 (0)