// A kept page's newspaper clipping: every word the core's, tagged; the clip// brass when the page is starred and steel otherwise, the star saying no word// of its own; one site always sets its headline in the same type; the// clipping lies bare on the Pages cobalt enamel and is stepped by a cut.@testable importCottonFacesimportCottonPaperimportCottonValuesimportSwiftUIimport XCTest@MainActorfinalclassPageClippingTests: XCTestCase {typealiasCatalogue = PageClippingFaceCatalogue/// RULE: The clip is brass when the core says the page is starred (the starred flag in its state place) and steel otherwise; the foot then prints no state, the clip saying it.func testTheClipIsBrassWhenStarred() { XCTAssertTrue(PageClippingSetting.starred(Catalogue.starred)) XCTAssertFalse(PageClippingSetting.starred(Catalogue.unread)) XCTAssertNil(PageClippingSetting.state(Catalogue.starred)) XCTAssertEqual(PageClippingSetting.state(Catalogue.unread), "Unread") XCTAssertEqual(PageClippingSetting.foot(Catalogue.starred), "12 min read \u{00B7} Weekend") XCTAssertEqual(PageClippingSetting.foot(Catalogue.unread), "6 min read \u{00B7} Unread") XCTAssertNil(PageClippingSetting.foot(DeckCard(face: "page.clipping", corner: nil, pressing: false, pace: nil, plate: nil, fields: [:]))) }/// RULE: A site's headlines are always set in one newspaper type, picked by the site; a page that names no site wears the broadsheet's.func testOneSiteWearsOneType() {let one = PageClippingSetting.headline(Catalogue.unread) XCTAssertEqual(PageClippingSetting.headline(Catalogue.unread), one) XCTAssertEqual(PageClippingSetting.headline(DeckCard(face: "page.clipping", corner: nil, pressing: false, pace: nil, plate: nil, fields: [:])), .broadsheet)let sites = (0..<40).map { DeckCard(face: "page.clipping", corner: nil, pressing: false, pace: nil, plate: nil, fields: ["source": .text("site-\($0).example")]) } XCTAssertEqual(Set(sites.map { PageClippingSetting.headline($0) }).count, PageClippingSetting.Headline.allCases.count, "every type is worn by some site") }/// RULE: The headline, byline, picture, excerpt, day, state and list are each the core's and tagged; a bare page tags only what it says.func testEveryWordIsTheCoresAndTagged() { XCTAssertEqual(tagged(Catalogue.unread, picture: true), [.title, .subtitle, .picture, .body, .when, .state]) XCTAssertEqual(tagged(Catalogue.starred, picture: true), [.title, .subtitle, .picture, .body, .when, .group]) XCTAssertEqual(tagged(Catalogue.bare, picture: false), [.title, .when, .state]) }/// RULE: The tear is the page's own: the same page tears the same every time, and the outline keeps inside its room.func testTheTearIsThePagesOwn() {let room = CGRect(x: 0, y: 0, width: 300, height: 400)let one = TornClipping(seed: "A page").path(in: room) XCTAssertEqual(one.description, TornClipping(seed: "A page").path(in: room).description) XCTAssertNotEqual(one.description, TornClipping(seed: "Another page").path(in: room).description) XCTAssertTrue(room.insetBy(dx: -0.01, dy: -0.01).contains(one.boundingRect)) }/// RULE: The clipping lies bare on the Pages cobalt enamel, draws its own paper, and is stepped by a cut.func testTheClippingLiesOnTheEnamelAndCuts() { XCTAssertEqual(FaceRegistry.ground("page.clipping"), .cobaltEnamel) XCTAssertEqual(FaceRegistry.stock("page.clipping"), .own) XCTAssertEqual(Catalogue.face.steps, .cut) XCTAssertEqual(Catalogue.face.specimens.map(\.name), ["unread", "starred", "no-picture", "bare", "largest"]) XCTAssertTrue(FaceGround.cobaltEnamel.dark, "words beside the card take the light ink on the cobalt enamel") XCTAssertNotNil(CottonMedia.image("pages-cobalt", scale: 3), "the enamel's tile is not in the catalogue") }privatefunc tagged(_ card: DeckCard, picture: Bool) -> Set<FacePart> {finalclassTagged { var parts: Set<FacePart> = [] }let tagged = Tagged()let drawn = PageClippingFace(card: card, picture: picture ? FacePicture(key: "kelmoor-jetty", edge: 300) : nil) .frame(width: 340, height: 425) .backgroundPreferenceValue(FacePartsKey.self) { regions inlet _ = tagged.parts.formUnion(regions.map(\.part))Color.clear } XCTAssertNotNil(ImageRenderer(content: drawn).cgImage)return tagged.parts }}