Cotton code
61 lines · 3.9 KB · SwiftRaw
import CottonValuesimport XCTest@testable import CottonUI/// RULE (owner, 2 Nov 2026): the deck's counter says, while the showing/// table's rows are arriving or leaving, what is happening — "347 of 950/// todos arriving", "25 todos sending" — and is the plain count once the/// table is settled. The core names only a moving table/// (`sync_table_progress`); the words are the kit's.final class DeckMovingTests: XCTestCase {    private func progress(_ tables: [String: [String: Double]]) -> RecordValue {        .object(tables.mapValues { .object($0.mapValues(RecordValue.number)) })    }    func testASettledTableIsThePlainCount() {        XCTAssertEqual(DeckMoving.of("todo", in: nil), .settled, "no read: the plain count")        XCTAssertEqual(DeckMoving.of("todo", in: .null), .settled)        XCTAssertEqual(DeckMoving.of("todo", in: progress(["person": ["arriving": 9, "arrived": 2]])), .settled, "another table moving")        XCTAssertEqual(DeckMoving.of("todo", in: progress(["todo": ["arriving": 950, "arrived": 950]])), .settled, "every row came")        XCTAssertEqual(DeckMoving.of("todo", in: progress(["todo": ["sending": 0]])), .settled)        XCTAssertNil(DeckMoving.settled.line(name: "Todo", plural: "Todos"))    }    func testRowsArrivingSayHowManyOfHowMany() {        let moving = DeckMoving.of("todo", in: progress(["todo": ["arriving": 950, "arrived": 347, "sending": 25]]))        XCTAssertEqual(moving, .arriving(arrived: 347, of: 950), "rows coming are said before writes going")        XCTAssertEqual(moving.line(name: "Todo", plural: "Todos"), "347 of 950 todos arriving")        XCTAssertEqual(DeckMoving.arriving(arrived: 0, of: 1).line(name: "Person", plural: "People"), "0 of 1 person arriving")    }    func testWritesSendingSayHowMany() {        let moving = DeckMoving.of("todo", in: progress(["todo": ["sending": 25]]))        XCTAssertEqual(moving, .sending(25))        XCTAssertEqual(moving.line(name: "Todo", plural: "Todos"), "25 todos sending")        XCTAssertEqual(DeckMoving.sending(1).line(name: "Person", plural: "People"), "1 person sending")    }    /// The counter reads on while a table moves and while a pass is in    /// flight, and stops once both are over.    func testTheCounterReadsOnThroughAPass() throws {        XCTAssertTrue(DeckMoving.readsAgain(.settled, passing: true), "a pass's first read comes before its figures")        XCTAssertTrue(DeckMoving.readsAgain(.arriving(arrived: 0, of: 40), passing: false))        XCTAssertTrue(DeckMoving.readsAgain(.sending(2), passing: false))        XCTAssertFalse(DeckMoving.readsAgain(.settled, passing: false))        let source = try String(contentsOf: SourceSweep.source("CottonUI/Deck/DeckSurface.swift"), encoding: .utf8)        XCTAssertTrue(source.contains("guard DeckMoving.readsAgain(now, passing: sync?.passing == true) else { return }"))    }    /// The counter shows the moving line in the place of the position, in    /// its type and ink, and adds no control.    func testTheCounterSaysTheMovingLineInItsOwnPlace() throws {        let source = try String(contentsOf: SourceSweep.source("CottonUI/Deck/DeckSurface.swift"), encoding: .utf8)        // A card a send brought, opened in place, says where it came from first        // ("From Asha, Thu 13 Nov", 3b005ff3e). The keeping line says itself        // here unless it is On this phone's, which stands on its own row under        // Search and Plus (`onPhoneLine`).        XCTAssertTrue(source.contains("if let said = provenance(at: at, in: cards) ?? (onPhoneLine == nil ? keepingLine : nil) ?? moving.line(name: definition.name, plural: definition.plural) ?? head ?? position(at: at, in: cards) {\n                    Text(said)"),                      "one Text: where a sent card came from, else the keeping line, else the moving line — on an empty deck too — else the view's head, else the position the core said")    }}