|
| 1 | +// |
| 2 | +// ForEachUpdateTests.swift |
| 3 | +// OpenSwiftUITests |
| 4 | + |
| 5 | +import Foundation |
| 6 | +import OpenAttributeGraphShims |
| 7 | +@testable import OpenSwiftUI |
| 8 | +@_spi(ForOpenSwiftUIOnly) import OpenSwiftUICore |
| 9 | +import Testing |
| 10 | + |
| 11 | +@MainActor |
| 12 | +struct ForEachUpdateTests { |
| 13 | + @Test(.disabled(if: attributeGraphVendor == .oag), .bug("https://github.com/OpenSwiftUIProject/Game2048/issues/2")) |
| 14 | + func replacingBoardTilesPreservesRemainingTiles() { |
| 15 | + struct Board: View { |
| 16 | + let tiles: [Int] |
| 17 | + |
| 18 | + var body: some View { |
| 19 | + ZStack(alignment: .topLeading) { |
| 20 | + ForEach(0..<16) { position in |
| 21 | + Color.gray |
| 22 | + .frame(width: 20, height: 20) |
| 23 | + .offset(x: CGFloat(position % 4) * 24, y: CGFloat(position / 4) * 24) |
| 24 | + } |
| 25 | + ForEach(tiles, id: \.self) { tile in |
| 26 | + Color.orange |
| 27 | + .frame(width: 20, height: 20) |
| 28 | + .offset(x: CGFloat(tile % 4) * 24, y: CGFloat((tile / 4) % 4) * 24) |
| 29 | + .zIndex(1) |
| 30 | + } |
| 31 | + } |
| 32 | + } |
| 33 | + } |
| 34 | + |
| 35 | + let graph = ViewGraph(rootViewType: Board.self, requestedOutputs: [.layout, .displayList]) |
| 36 | + graph.instantiateOutputs() |
| 37 | + graph.setProposedSize(CGSize(width: 96, height: 96)) |
| 38 | + for turn in 0..<20 { |
| 39 | + graph.setRootView(Board(tiles: Array(turn..<(turn + 16)))) |
| 40 | + graph.updateOutputs(at: Time(seconds: Double(turn))) |
| 41 | + let (list, _) = graph.displayList() |
| 42 | + #expect(list.items.count == 32) |
| 43 | + } |
| 44 | + } |
| 45 | +} |
0 commit comments