From 982cafa061bca19e20ac1e8c26453b82394f9caf Mon Sep 17 00:00:00 2001 From: James Moschou Date: Sat, 14 Feb 2026 15:54:36 +0100 Subject: [PATCH] Add crashing test case --- .../View/VariadicViewTests.swift | 115 ++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 Tests/OpenSwiftUICoreTests/View/VariadicViewTests.swift diff --git a/Tests/OpenSwiftUICoreTests/View/VariadicViewTests.swift b/Tests/OpenSwiftUICoreTests/View/VariadicViewTests.swift new file mode 100644 index 000000000..bfa09dae8 --- /dev/null +++ b/Tests/OpenSwiftUICoreTests/View/VariadicViewTests.swift @@ -0,0 +1,115 @@ +// +// VariadicViewTests.swift +// OpenSwiftUICoreTests + +import Foundation +import OpenSwiftUICore +import Testing + +struct PassthroughUnaryViewRoot: _VariadicView.UnaryViewRoot { + func body(children: _VariadicView.Children) -> some View { + children + } +} + +struct PassthroughMultiViewRoot: _VariadicView.MultiViewRoot { + func body(children: _VariadicView.Children) -> some View { + children + } +} + +@MainActor +struct VariadicViewTests { + + #if canImport(Darwin) + @Test + func nestedUnaryViewRoot() { + struct ContentView: View { + var body: some View { + _VariadicView.Tree(PassthroughUnaryViewRoot()) { + _VariadicView.Tree(PassthroughUnaryViewRoot()) { + Color.red + Color.blue + } + } + } + } + + let graph = ViewGraph( + rootViewType: ContentView.self, + requestedOutputs: [.displayList] + ) + graph.instantiateOutputs() + graph.setRootView(ContentView()) + graph.setProposedSize(CGSize(width: 100, height: 100)) + let (displayList, _) = graph.displayList() + let expectRegex = try! Regex( + #""" + \(display-list + \(item #:identity \d+ #:version \d+ + \(frame \([^)]+\)\) + \(effect + \(item #:identity \d+ #:version \d+ + \(frame \([^)]+\)\) + \(effect + \(item #:identity \d+ #:version \d+ + \(frame \([^)]+\)\) + \(content-seed \d+\) + \(color #[0-9A-F]{8}\)\)\)\) + \(item #:identity \d+ #:version \d+ + \(frame \([^)]+\)\) + \(effect + \(item #:identity \d+ #:version \d+ + \(frame \([^)]+\)\) + \(content-seed \d+\) + \(color #[0-9A-F]{8}\)\)\)\)\)\)\) + """#) + #expect(displayList.description.contains(expectRegex)) + } + + @Test + func nestedMultiViewRoot() { + struct ContentView: View { + var body: some View { + _VariadicView.Tree(PassthroughMultiViewRoot()) { + _VariadicView.Tree(PassthroughMultiViewRoot()) { + Color.red + Color.blue + } + } + } + } + + let graph = ViewGraph( + rootViewType: ContentView.self, + requestedOutputs: [.displayList] + ) + graph.instantiateOutputs() + graph.setRootView(ContentView()) + graph.setProposedSize(CGSize(width: 100, height: 100)) + let (displayList, _) = graph.displayList() + let expectRegex = try! Regex( + #""" + \(display-list + \(item #:identity \d+ #:version \d+ + \(frame \([^)]+\)\) + \(effect + \(item #:identity \d+ #:version \d+ + \(frame \([^)]+\)\) + \(effect + \(item #:identity \d+ #:version \d+ + \(frame \([^)]+\)\) + \(content-seed \d+\) + \(color #[0-9A-F]{8}\)\)\)\) + \(item #:identity \d+ #:version \d+ + \(frame \([^)]+\)\) + \(effect + \(item #:identity \d+ #:version \d+ + \(frame \([^)]+\)\) + \(content-seed \d+\) + \(color #[0-9A-F]{8}\)\)\)\)\)\)\) + """#) + #expect(displayList.description.contains(expectRegex)) + } + #endif +}