#if canImport(UIKit) @testable import CottonFaces @testable import CottonUI import CottonPaper import CottonValues import SwiftUI import XCTest /// RULE: a book's card reads where the reader is off `used` of `limit` and says it in the deck's own line ("212 / 340"), reads it finished once a date is kept — the core's "Add date" on an undated book is not one — or the place has reached its end, and draws the rating off `count` as stars out of five in halves (faces lane, 23 Oct 2026, cover-led faces). final class BookFaceTests: XCTestCase { private func book(_ fields: [String: RecordValue]) -> DeckCard { DeckCard(face: .bookHardback, fields: fields) } func testThePlaceIsUsedOfLimitInTheDecksLine() throws { let reading = book(["used": .number(212), "limit": .number(340)]) let progress = try XCTUnwrap(reading.progress) XCTAssertEqual(progress.share, 212.0 / 340.0, accuracy: 0.0001) XCTAssertEqual(progress.said, ShellLines.line("cards", "deck.position", ["at": "212", "of": "340"])) XCTAssertFalse(reading.finished) } func testUsedAloneIsAShareOfAHundred() throws { let progress = try XCTUnwrap(book(["used": .number(62)]).progress) XCTAssertEqual(progress.share, 0.62, accuracy: 0.0001) XCTAssertEqual(progress.said, 0.62.formatted(.percent.precision(.fractionLength(0)))) XCTAssertNil(book(["limit": .number(340)]).progress, "no place without used") } func testAKeptDateIsFinishedAndAddDateIsNot() { let undated = book(["date": .text(ShellLines.line("cards", "date.add")), "used": .number(10), "limit": .number(300)]) XCTAssertNil(undated.dated) XCTAssertFalse(undated.finished) let done = book(["date": .text("Sun 18 Oct")]) XCTAssertEqual(done.dated, "Sun 18 Oct") XCTAssertTrue(done.finished) XCTAssertTrue(book(["used": .number(340), "limit": .number(340)]).finished, "the last page read is finished") } func testTheRatingIsCountInHalvesOutOfFive() { XCTAssertEqual(book(["count": .text("4")]).rating, 4) XCTAssertEqual(book(["count": .number(3.4)]).rating, 3.5) XCTAssertEqual(book(["count": .text("\u{2605}\u{2605}\u{2605}")]).rating, 3) XCTAssertEqual(book(["count": .number(9)]).rating, 5, "never past five") XCTAssertNil(book(["count": .number(0)]).rating, "nought is unrated") XCTAssertNil(book([:]).rating) } func testTheFootSaysTheDayFinishedElseThePlaceAndTheStarsEitherWay() { let done = MediaFoot(book(["date": .text("Sun 18 Oct"), "used": .number(340), "limit": .number(340), "count": .text("4")])) XCTAssertEqual(done, MediaFoot(book(["date": .text("Sun 18 Oct"), "count": .text("4")])), "a finished book draws its day, not the rule") XCTAssertEqual(done.finished, "Sun 18 Oct") XCTAssertEqual(done.rating, 4) let reading = MediaFoot(book(["date": .text(ShellLines.line("cards", "date.add")), "used": .number(212), "limit": .number(340)])) XCTAssertNil(reading.finished) XCTAssertEqual(reading.progress?.said, ShellLines.line("cards", "deck.position", ["at": "212", "of": "340"])) XCTAssertNil(reading.rating) } @MainActor func testTheDeckDrawsTheBookAndLabelsItsStart() { XCTAssertTrue(DeckFace.draws(.bookHardback)) XCTAssertTrue(DeckFace.draws(book(["title": .text("Invented Rivers")]))) XCTAssertEqual(FactLabel.of("book", "started"), ShellLines.line("cards", "label.face.book.started"), "the day begun is labelled in the core's word") } /// RULE: every kind is drawn from Loom's registry by its id — a book with its notes turned to after its face, a recording with its pages, a film — the deck adapting none (faces plain, 28 Oct 2026). @MainActor func testEveryKindIsDrawnFromTheRegistry() { for kind in ["book.hardback", "audio", "note.page", "person.rolodex", "document", "thread.slips", "track", "album.board", "session", "plain", "film.vhs"] { XCTAssertEqual(DeckFace.registered(DeckCard(face: kind, corner: nil, pressing: false, pace: nil, plate: nil, fields: [:]))?.id, kind, "the deck does not draw a \(kind) from Loom's registry") } } } #endif