Cotton code
73 lines · 5.6 KB · SwiftRaw
// A list's rows as slips and the lift a held row or message rises into// (recordslips, slipacts): a list slip is the page's paper with the chevron,// a held thing lifts over the whole dimmed screen, and nothing that lifts// listens for a drag of its own or spells a field, a width or an act.import CottonKitimport Foundationimport XCTest@testable import CottonUIfinal class ListSlipTests: XCTestCase {    /// RULE: The lift leaves every drag to the page but one: the drag down that folds a lifted list belongs to the dimmed region over the page (walk of 17 Oct: a person's page would not scroll from its summary).    func testTheLiftHasOneDragTheDimmedRegionsFold() throws {        let host = try SourceSweep.mustRead("apps/cotton/Sources/CottonUI/Slips/LiftedActs.swift", ownedBy: "slipacts")        XCTAssertEqual(host.components(separatedBy: "DragGesture(").count - 1, 1, "one drag: the dimmed region's fold")        let slips = try SourceSweep.mustRead("apps/cotton/Sources/CottonUI/Slips/ListSlip.swift", ownedBy: "recordslips")        XCTAssertFalse(slips.contains("DragGesture("), "a slip listens for a drag")    }    /// RULE: No file that draws or lifts slips spells a column type, a reach, a width, an act or an object as a literal.    func testNoSlipDrawingSpellsAFieldAWidthAnActOrAnObject() throws {        let spelled = Set(["half", "full", "phone", "email", "instagram"]            + DefinitionColumnType.allCases.map(\.rawValue) + CardEnamel.allCases.map(\.rawValue))        let literal = try NSRegularExpression(pattern: #""([a-z_.-]+)""#)        for path in ["apps/cotton/Sources/CottonUI/Slips/ListSlip.swift", "apps/cotton/Sources/CottonUI/Slips/LiftedActs.swift"] {            let text = try SourceSweep.mustRead(path, ownedBy: "slipacts")            XCTAssertFalse(text.contains("systemName:"), "\(path) names a glyph")            for match in literal.matches(in: text, range: NSRange(text.startIndex..., in: text)) {                let word = (text as NSString).substring(with: match.range(at: 1))                XCTAssertFalse(spelled.contains(word), "\(path) spells \(word)")            }        }    }    /// RULE: A list's rows (Handles, Languages, "Same person?") draw as link slips of the page's paper and one "and N more" slip — no colour-filled record card, no inline Add (Add lives on the list's page and in the tray's Edit), no "All N" (architect's review R3, 18 Oct 2026; walk of 17 Oct: Handles drew "All 6" over "and 3 more" under an "Add a handle").    func testAListIsLinkSlipsAndOneMore() throws {        let section = try SourceSweep.mustRead("apps/cotton/Sources/CottonUI/Surfaces/RecordsSection.swift", ownedBy: "recordslips")        let lines = section.components(separatedBy: "\n")        var guarded = 0        for (index, line) in lines.enumerated() where line.contains("wholeRow(definition") || line.contains("newRow(definition") {            let above = lines[max(0, index - 2)...index].joined(separator: "\n")            XCTAssertTrue(above.contains("slipRows == nil"), "an All or Add row drawn under a list of slips: \(line)")            guarded += 1        }        XCTAssertGreaterThanOrEqual(guarded, 5, "the sweep found the Add and All rows")        XCTAssertTrue(section.contains("switch slipRows == nil ? Self.gatheredLayout(list, definition: definition) : .stack"),                      "a list of slips never lays its rows several across")        for call in ["listSlip(definition, record)", "listSlip(row.definition, row.record)", "ListSlip(title: words)"] {            XCTAssertTrue(section.contains(call), "a list of slips draws \(call)")        }        let slips = try SourceSweep.mustRead("apps/cotton/Sources/CottonUI/Slips/ListSlip.swift", ownedBy: "recordslips")        let listSlip = try XCTUnwrap(slips.components(separatedBy: "struct ListSlip").last)        XCTAssertTrue(listSlip.contains("SlipPaper()") && listSlip.contains("SlipChevron()"), "a list slip is the page's paper with the chevron")        XCTAssertFalse(listSlip.contains("FaceTint") || listSlip.contains("dye"), "a list slip wears no colour fill")    }    /// RULE: One idiom across the app: a held message and a held list row lift over the whole dimmed screen into the same lift, never a tray under a tilted message or the system's menu; an act whose hold asks still asks (slipacts rule 5).    func testAHeldMessageLiftsIntoTheSameListAsARow() throws {        let thread = try SourceSweep.mustRead("apps/cotton/Sources/CottonUI/Surfaces/PageStyles/ConversationPage.swift", ownedBy: "slipacts")        XCTAssertTrue(thread.contains("lift.lift(Lifted("), "a held message lifts into the page's lift")        XCTAssertFalse(thread.contains("rotationEffect(.degrees(held"), "a held message tilts in place")        // A row in a list lifts the same way; the system's context menu is gone from it.        let list = try SourceSweep.mustRead("apps/cotton/Sources/CottonUI/Surfaces/RecordListSurface.swift", ownedBy: "slipacts")        let press = try XCTUnwrap(list.components(separatedBy: "struct SlipPressMenu").last?.components(separatedBy: "final class RowFrame").first)        XCTAssertTrue(press.contains("lift.lift(Lifted("), "a held row lifts into the screen's lift")        XCTAssertFalse(press.contains(".contextMenu"), "a held row opens the system's menu")        // The window is the lift's region: the root hosts it, so the status-bar and        // home-indicator strips, the dial and the record button dim with the page.        let root = try SourceSweep.mustRead("apps/cotton/Sources/CottonUI/Boot/RootView.swift", ownedBy: "slipacts")        XCTAssertTrue(root.contains(".liftsActs()"), "the window's root hosts the lift")    }}