Cotton code
58 lines · 2.8 KB · SwiftRaw
// The unlock card: the question, who asks, the reason, one switch per table// as the core and the person left it, the window's length and wait struck as// stamps, and the queue behind it; its one tap of its own is a table's// switch, handed in by the shell.@testable import CottonFacesimport CottonPaperimport CottonSpecimensimport CottonValuesimport SwiftUIimport XCTest@MainActorfinal class UnlockCardTests: XCTestCase {    private typealias Catalogue = UnlockCardFaceCatalogue    /// RULE: The card reads its places as the core said them: the title, the asker, the reason, each table's switch (its label and whether it is on, in the core's order), the minutes and the wait as stamps, and the queue only when one waits behind.    func testTheCardReadsEveryPlaceAsTheCoreSaidIt() {        let queued = UnlockReading(Catalogue.queued)        XCTAssertEqual(queued.title, "Allow Claude (claude.ai) to read Messages, Notes and Money for 10 minutes?")        XCTAssertEqual(queued.asker, "Claude (claude.ai) · Claude")        XCTAssertEqual(queued.reason, "To total what was spent on the trip.")        XCTAssertEqual(queued.toggles.map(\.table), ["message", "note", "transaction"])        XCTAssertEqual(queued.toggles.map(\.label), ["Messages", "Notes", "Money"])        XCTAssertEqual(queued.toggles.map(\.on), [true, false, true])        XCTAssertEqual(queued.stamps, ["10 minutes", "Waits 3 more minutes"])        XCTAssertEqual(queued.queue, "2 more requests wait")        let oneOff = UnlockReading(Catalogue.oneOff)        XCTAssertNil(oneOff.reason)        XCTAssertNil(oneOff.queue)    }    /// RULE: A switch is drawn as the card says it, on or off: flipping one changes the drawing, and the face draws the same card the same way.    func testASwitchIsDrawnAsTheCardSaysIt() {        var off = Catalogue.asked        off.fields["toggles"] = Catalogue.toggles([("message", "Messages", false), ("note", "Notes", true)])        XCTAssertNotEqual(bytes(shot(off)), bytes(shot(Catalogue.asked)))        XCTAssertEqual(bytes(shot(Catalogue.asked)), bytes(shot(Catalogue.asked)))    }    /// RULE: The face is registered under the core's id, on framed paper on the page ground.    func testTheFaceIsRegisteredUnderTheCoresId() {        XCTAssertTrue(FaceRegistry.ids.contains("unlock.card"))        XCTAssertEqual(Catalogue.stock, .framed)        XCTAssertEqual(Catalogue.ground, .paper)    }    private func shot(_ drawn: DeckCard) -> CGImage? {        let renderer = ImageRenderer(content: UnlockCardFace(card: drawn).frame(width: 340, height: 482))        renderer.scale = 1        return renderer.cgImage    }    private func bytes(_ image: CGImage?) -> Data? {        guard let image, let data = image.dataProvider?.data else { return nil }        return data as Data    }}