|
| 1 | +// |
| 2 | +// VariadicViewTests.swift |
| 3 | +// OpenSwiftUICoreTests |
| 4 | + |
| 5 | +import Foundation |
| 6 | +import OpenSwiftUICore |
| 7 | +import Testing |
| 8 | + |
| 9 | +struct PassthroughUnaryViewRoot: _VariadicView.UnaryViewRoot { |
| 10 | + func body(children: _VariadicView.Children) -> some View { |
| 11 | + children |
| 12 | + } |
| 13 | +} |
| 14 | + |
| 15 | +struct PassthroughMultiViewRoot: _VariadicView.MultiViewRoot { |
| 16 | + func body(children: _VariadicView.Children) -> some View { |
| 17 | + children |
| 18 | + } |
| 19 | +} |
| 20 | + |
| 21 | +@MainActor |
| 22 | +struct VariadicViewTests { |
| 23 | + |
| 24 | + #if canImport(Darwin) |
| 25 | + @Test |
| 26 | + func nestedUnaryViewRoot() { |
| 27 | + struct ContentView: View { |
| 28 | + var body: some View { |
| 29 | + _VariadicView.Tree(PassthroughUnaryViewRoot()) { |
| 30 | + _VariadicView.Tree(PassthroughUnaryViewRoot()) { |
| 31 | + Color.red |
| 32 | + Color.blue |
| 33 | + } |
| 34 | + } |
| 35 | + } |
| 36 | + } |
| 37 | + |
| 38 | + let graph = ViewGraph( |
| 39 | + rootViewType: ContentView.self, |
| 40 | + requestedOutputs: [.displayList] |
| 41 | + ) |
| 42 | + graph.instantiateOutputs() |
| 43 | + graph.setRootView(ContentView()) |
| 44 | + graph.setProposedSize(CGSize(width: 100, height: 100)) |
| 45 | + let (displayList, _) = graph.displayList() |
| 46 | + let expectRegex = try! Regex( |
| 47 | + #""" |
| 48 | + \(display-list |
| 49 | + \(item #:identity \d+ #:version \d+ |
| 50 | + \(frame \([^)]+\)\) |
| 51 | + \(effect |
| 52 | + \(item #:identity \d+ #:version \d+ |
| 53 | + \(frame \([^)]+\)\) |
| 54 | + \(effect |
| 55 | + \(item #:identity \d+ #:version \d+ |
| 56 | + \(frame \([^)]+\)\) |
| 57 | + \(content-seed \d+\) |
| 58 | + \(color #[0-9A-F]{8}\)\)\)\) |
| 59 | + \(item #:identity \d+ #:version \d+ |
| 60 | + \(frame \([^)]+\)\) |
| 61 | + \(effect |
| 62 | + \(item #:identity \d+ #:version \d+ |
| 63 | + \(frame \([^)]+\)\) |
| 64 | + \(content-seed \d+\) |
| 65 | + \(color #[0-9A-F]{8}\)\)\)\)\)\)\) |
| 66 | + """#) |
| 67 | + #expect(displayList.description.contains(expectRegex)) |
| 68 | + } |
| 69 | + |
| 70 | + @Test |
| 71 | + func nestedMultiViewRoot() { |
| 72 | + struct ContentView: View { |
| 73 | + var body: some View { |
| 74 | + _VariadicView.Tree(PassthroughMultiViewRoot()) { |
| 75 | + _VariadicView.Tree(PassthroughMultiViewRoot()) { |
| 76 | + Color.red |
| 77 | + Color.blue |
| 78 | + } |
| 79 | + } |
| 80 | + } |
| 81 | + } |
| 82 | + |
| 83 | + let graph = ViewGraph( |
| 84 | + rootViewType: ContentView.self, |
| 85 | + requestedOutputs: [.displayList] |
| 86 | + ) |
| 87 | + graph.instantiateOutputs() |
| 88 | + graph.setRootView(ContentView()) |
| 89 | + graph.setProposedSize(CGSize(width: 100, height: 100)) |
| 90 | + let (displayList, _) = graph.displayList() |
| 91 | + let expectRegex = try! Regex( |
| 92 | + #""" |
| 93 | + \(display-list |
| 94 | + \(item #:identity \d+ #:version \d+ |
| 95 | + \(frame \([^)]+\)\) |
| 96 | + \(effect |
| 97 | + \(item #:identity \d+ #:version \d+ |
| 98 | + \(frame \([^)]+\)\) |
| 99 | + \(effect |
| 100 | + \(item #:identity \d+ #:version \d+ |
| 101 | + \(frame \([^)]+\)\) |
| 102 | + \(content-seed \d+\) |
| 103 | + \(color #[0-9A-F]{8}\)\)\)\) |
| 104 | + \(item #:identity \d+ #:version \d+ |
| 105 | + \(frame \([^)]+\)\) |
| 106 | + \(effect |
| 107 | + \(item #:identity \d+ #:version \d+ |
| 108 | + \(frame \([^)]+\)\) |
| 109 | + \(content-seed \d+\) |
| 110 | + \(color #[0-9A-F]{8}\)\)\)\)\)\)\) |
| 111 | + """#) |
| 112 | + #expect(displayList.description.contains(expectRegex)) |
| 113 | + } |
| 114 | + #endif |
| 115 | +} |
0 commit comments