Cotton code
47 lines · 2.7 KB · SwiftRaw
// The board as data (design note 26203e21): one renderer, `BoardSurface`,// draws a board's parts in order, each kind in one case of its part switch,// and no part draws a board or another part. A kind this build does not know// is passed over and said, never a crash; and the boards this build draws// while its row is read are the crate's own, copied.import CottonKitimport Foundationimport XCTest@testable import CottonUIfinal class BoardSurfaceGuardTests: XCTestCase {    private static let lane = "the board as data (26203e21)"    private static let surface = "apps/cotton/Sources/CottonUI/Surfaces/BoardSurface.swift"    /// The files the part views live in.    private static let partFiles = [        "apps/cotton/Sources/CottonUI/Surfaces/Board/BoardNotices.swift",        "apps/cotton/Sources/CottonUI/Surfaces/Board/BoardSourceParts.swift",        "apps/cotton/Sources/CottonUI/Surfaces/Board/BoardPage.swift",        "apps/cotton/Sources/CottonUI/Surfaces/Board/BoardHead.swift",    ]    /// The part switch's function, from its signature to its closing brace.    private func partSwitch() throws -> Substring {        let code = SourceSweep.withoutComments(try SourceSweep.mustRead(Self.surface, ownedBy: Self.lane))        let start = try XCTUnwrap(code.range(of: "private func part(_ entry: BoardEntry) -> AnyView {"), "the part switch is gone")        let end = try XCTUnwrap(code.range(of: "\n    }\n", range: start.upperBound..<code.endIndex), "the part switch never closes")        return code[start.lowerBound..<end.upperBound]    }    /// RULE: A board part of a kind this build does not know is skipped and filed in Feedback once per launch, never a crash — a board a newer build wrote is drawn by an older phone with the parts it knows (§8).    @MainActor    func testAnUnknownPartIsPassedOverAndSaidOnce() throws {        let passedOver = try BoardEntry.forTests(#"{"id":"carousel","kind":"carousel","shown":false,"why":{"key":"unknown","words":"A newer build's."},"settings":{}}"#)        XCTAssertEqual(passedOver.why?.key, "unknown", "the core says which kinds it does not know")        XCTAssertFalse(passedOver.shown)        let key = "guard-\(UUID().uuidString)"        XCTAssertTrue(BoardFeedback.firstTime(key), "the first time is said")        XCTAssertFalse(BoardFeedback.firstTime(key), "and only the first")        // Said as one Feedback row the core files (at most one per database,        // board and part), not as a crash report.        let read = SourceSweep.withoutComments(try SourceSweep.mustRead(            "apps/cotton/Sources/CottonUI/Surfaces/Board/BoardRead.swift", ownedBy: Self.lane))        XCTAssertFalse(read.contains("Reporting.report"), "a passed-over part is a Feedback row, not a crash report")    }}