Cotton code
63 lines · 3.9 KB · SwiftRaw
import SwiftUIimport XCTest@testable import CottonUI/// RULE (owner, 2 Nov 2026): while a stroke is over the light record card it/// is drawn in the card's own ink, the theme's print on its paper, not the/// ground's — a cream stroke on a dark ground was pale on the card.final class InkInksTests: XCTestCase {    private let cream = Color(red: 0.96, green: 0.93, blue: 0.86)    private let print = Color(red: 0.12, green: 0.11, blue: 0.10)    private let card = CGRect(x: 40, y: 120, width: 300, height: 420)    func testOverTheCardTheStrokeIsInTheCardsInk() {        let inks = InkInks(ground: cream, card: InkCard(papers: [card], ink: print))        XCTAssertEqual(inks.ink(at: CGPoint(x: 200, y: 300)), print, "on the card")        XCTAssertEqual(inks.ink(at: CGPoint(x: 20, y: 300)), cream, "beside it")        XCTAssertEqual(inks.ink(at: CGPoint(x: 200, y: 80)), cream, "above it")        XCTAssertEqual(inks.crossed, InkCard(papers: [card], ink: print), "the stroke changes ink at the card's edge")    }    func testOnPaperOrWithNoCardTheStrokeIsOneInk() {        XCTAssertNil(InkInks(ground: print, card: InkCard(papers: [card], ink: print)).crossed, "paper: the card's ink is the ground's")        XCTAssertNil(InkInks(ground: cream, card: nil).crossed, "no card showing")        XCTAssertNil(InkInks(ground: cream, card: InkCard(papers: [.zero], ink: print)).crossed, "a card not yet laid out")        XCTAssertEqual(InkInks(ground: cream, card: nil).ink(at: CGPoint(x: 200, y: 300)), cream)    }    /// A card that lays more than one sheet: the stroke is in the card's    /// ink over any of them.    func testOverAnyOfTheCardsPapersTheStrokeIsInTheCardsInk() {        let tab = CGRect(x: 60, y: 90, width: 120, height: 40)        let inks = InkInks(ground: cream, card: InkCard(papers: [card, tab], ink: print))        XCTAssertEqual(inks.ink(at: CGPoint(x: 100, y: 100)), print, "on the tab above the card")        XCTAssertEqual(inks.ink(at: CGPoint(x: 300, y: 100)), cream)    }    /// The deck hands the ink its front card's papers, as each paper says    /// where it lies on the screen — told to the front card alone. Not the    /// face's frame (its whole slot: walk 1 drew a T below the tray dark on    /// the dark ground), nor a preference (walk 2: the paper never got the    /// card's ink).    func testTheDeckHandsTheInkItsFrontCardsPapers() throws {        let source = try String(contentsOf: SourceSweep.source("CottonUI/Deck/DeckSurface.swift"), encoding: .utf8)        XCTAssertTrue(source.contains("card: cards.indices.contains(at) ? InkCard(papers: inkPapers, ink: DeckGround.ink(.ink, on: nil, theme: theme)) : nil"))        XCTAssertTrue(source.contains("frontSheet(record: record, card: card, cards: cards)\n        // Its papers say where they lie, for the ink (`InkCard`).\n        .environment(\\.cardPaperReport"))        let paper = try String(contentsOf: SourceSweep.source("CottonPaper/Paper/CardPaper.swift"), encoding: .utf8)        XCTAssertTrue(paper.contains(".onGeometryChange(for: CGRect.self) { $0.frame(in: .global) } action: { frame in report?.laid(id, frame) }"), "a paper says where it lies")        XCTAssertTrue(paper.contains("        .cardPaperLaid()\n    }\n}"), "the stock's paper is marked")    }    /// The faces on a dark ground paint their own light paper — no deck    /// stock (walk 3: the todo card never said where it lay) — and mark it.    /// The rolodex's card is the shared `Rolodex`, which every face wearing    /// one draws.    func testTheDarkGroundFacesMarkTheirPaintedPaper() throws {        for file in ["CottonFaces/Cotton/TodoCardFace.swift", "CottonFaces/Shared/Rolodex.swift",                     "CottonFaces/Cotton/NotePageFace.swift", "CottonFaces/Cotton/MoneyObjects.swift"] {            let source = try String(contentsOf: SourceSweep.source(file), encoding: .utf8)            XCTAssertTrue(source.contains(".cardPaperLaid()"), "\(file) marks its paper")        }    }}