// The album's sleeve: its back types every song a line each, numbered on its // disc, a line naming each disc after the first, and when the back is full // how many more; the year left, the songs and length right; an album kept // without a cover sets its title balanced on the blank stock in the sleeve's // sans; the parts tagged on either side; the sleeve lies on the tolex, cuts, // and every material it lays is in the catalogue. @testable import CottonFaces import CottonPaper import CottonSpecimens import CottonValues import CoreText import SwiftUI import XCTest /// The parts a drawn face tagged. private final class SleevePartsTagged { var parts: Set = [] } @MainActor final class AlbumSleeveTests: XCTestCase { private typealias Catalogue = AlbumSleeveFaceCatalogue private typealias Knobs = AlbumSleeveFaceKnobs private func album(_ songs: [(String, TimeInterval, Int)], title: String = "Night Ferry") -> DeckCard { Catalogue.album(["title": .text(title)], songs: songs) } /// RULE: Nine songs on one disc are nine lines, numbered from one, each its title and its length; nothing more. func testTheBackTypesEverySongALineEach() { let lines = AlbumSleeveSetting.lines(Catalogue.ferry) XCTAssertEqual(lines.count, Knobs.trackLines) XCTAssertEqual(lines.first, .song(number: 1, title: "Harbour Lights", seconds: 242)) XCTAssertEqual(lines.last, .song(number: 9, title: "Night Ferry", seconds: 319)) XCTAssertEqual(AlbumSleeveSetting.number(1), "01") XCTAssertEqual(AlbumSleeveSetting.number(12), "12") XCTAssertEqual(TrackClock.said(242), "4:02") XCTAssertEqual(AlbumSleeveSetting.lines(album([])), [], "no songs, no list") } /// RULE: On an album of several discs each disc after the first starts with a line naming it, its songs numbered from one again; more lines than the back holds, it types one less and a last line says how many songs it left out, never ending on a disc's name. func testDiscsBreakAndTheBackSaysHowManyMore() { let lines = AlbumSleeveSetting.lines(Catalogue.moons) XCTAssertEqual(lines.count, Knobs.trackLines) XCTAssertEqual(lines[5], .disc(2)) XCTAssertEqual(lines[6], .song(number: 1, title: "Night Ferry", seconds: 284)) XCTAssertEqual(lines.last, .more(7), "fourteen songs, seven typed") XCTAssertEqual(AlbumSleeveSetting.said(.disc(2)), ShellLines.line("cards", "sleeve.disc", ["n": "2"])) XCTAssertEqual(AlbumSleeveSetting.said(.disc(2)), "Disc 2") XCTAssertEqual(AlbumSleeveSetting.said(.more(7)), "and 7 more") // The ninth line would name disc 2: it is dropped, not left hanging. let eight = (1...8).map { ("Song \($0)", TimeInterval(200), 1) } + [("Low Tide", 200, 2), ("Fog Bell", 200, 2)] let hanging = AlbumSleeveSetting.lines(album(eight)) XCTAssertEqual(hanging.count, Knobs.trackLines) XCTAssertEqual(hanging.last, .more(2)) XCTAssertFalse(hanging.contains(.disc(2))) // Exactly full: every song, no "more". let full = (1...4).map { ("Song \($0)", TimeInterval(200), 1) } + (1...4).map { ("Song \($0)", TimeInterval(200), 2) } XCTAssertEqual(AlbumSleeveSetting.lines(album(full)).count, Knobs.trackLines) XCTAssertFalse(AlbumSleeveSetting.lines(album(full)).contains { if case .more = $0 { true } else { false } }) } /// RULE: The back's facts are the year, and the album's songs and length joined as the cards join words; never a catalogue number. func testTheFactsAreTheYearAndTheWhole() { XCTAssertEqual(Catalogue.ferry.text("year"), "2024") XCTAssertEqual(AlbumSleeveSetting.whole(Catalogue.ferry), "9 songs \u{00B7} 38:46") XCTAssertNil(AlbumSleeveSetting.whole(album([]))) } /// RULE: An album kept without a cover sets its title in capitals on the blank stock in at most three balanced lines within the room the rule and the artist leave it, taken down only when it must, and past the least size cut with an ellipsis. func testTheBlankSetsItsTitleBalanced() { let (lines, size) = AlbumSleeveSetting.title(Catalogue.common) XCTAssertEqual(lines.joined(separator: " "), "COMMON GROUND") XCTAssertLessThanOrEqual(lines.count, Knobs.titleLines) for line in lines { XCTAssertLessThanOrEqual(HighlightPassageSetting.wide(line, AlbumSleeveSetting.sans(size)), Knobs.words.width + 0.5) } let (long, least) = AlbumSleeveSetting.title(Catalogue.largest) XCTAssertEqual(long.count, Knobs.titleLines) XCTAssertEqual(long.last?.last, "\u{2026}", "too long even at the least size: cut") XCTAssertGreaterThanOrEqual(least, Knobs.titleLeast) let room = Knobs.words.height - Knobs.ruleGap - Knobs.rule.height - Knobs.artistGap - Knobs.artistSize * Knobs.artistLine XCTAssertLessThanOrEqual(CGFloat(lines.count) * size * Knobs.titleStep, room) XCTAssertEqual(AlbumSleeveSetting.title(album([], title: "Fog")).size, Knobs.titleSize, "a title that fits is set at the sleeve's own size") let harbour = AlbumSleeveSetting.title(album([], title: "Harbour Test")).lines XCTAssertEqual(harbour.joined(separator: " "), "HARBOUR TEST") XCTAssertTrue(harbour.allSatisfy { line in line.split(separator: " ").allSatisfy { ["HARBOUR", "TEST"].contains(String($0)) } }, "every word whole, never HARBOU / R TEST: \(harbour)") XCTAssertEqual(AlbumSleeveSetting.title(DeckCard(face: "album.sleeve", corner: nil, pressing: false, pace: nil, plate: nil, fields: [:])).lines, []) } /// RULE: The front tags its cut-out as its picture (and, on the blank stock, its title and artist); the back tags its title, artist, year and track list. func testTheSleeveTagsItsParts() { let cover = FixturePictures.image("cover-night-ferry") XCTAssertNotNil(cover) func parts(_ face: Drawn, turned: Bool = false) -> Set { let tagged = SleevePartsTagged() let drawn = face .environment(\.faceTurnedOver, turned) .frame(width: 340, height: 451) .backgroundPreferenceValue(FacePartsKey.self) { regions in let _ = tagged.parts.formUnion(regions.map(\.part)) Color.clear } XCTAssertNotNil(ImageRenderer(content: drawn).cgImage) return tagged.parts } XCTAssertEqual(parts(AlbumSleeveFace(card: Catalogue.ferry, cover: cover)), [.picture]) XCTAssertEqual(parts(AlbumSleeveFace(card: Catalogue.common)), [.picture, .title, .subtitle]) XCTAssertEqual(parts(AlbumSleeveFace(card: Catalogue.ferry, cover: cover), turned: true), [.title, .subtitle, .when, .body]) XCTAssertEqual(parts(AlbumSleeveFace(card: Catalogue.moons), turned: true), [.title, .subtitle, .when, .body]) } /// RULE: The sleeve lies bare on the music's tolex, draws its own sheet, and is stepped by a cut; its specimens show it with a cover, typeset, turned over with nine songs and with two discs and more, and the fullest; every material it lays is in the catalogue and its sans is bundled. func testTheSleeveLiesOnTheTolexAndCuts() { XCTAssertEqual(FaceRegistry.ground("album.sleeve"), .tolex) XCTAssertEqual(FaceRegistry.stock("album.sleeve"), .own) XCTAssertEqual(Catalogue.face.steps, .cut) XCTAssertEqual(Catalogue.face.specimens.map(\.name), ["cover", "no-cover", "back", "back-two-discs", "largest"]) XCTAssertEqual(Catalogue.face.specimens.filter(\.turned).map(\.name), ["back", "back-two-discs"]) XCTAssertNil(Catalogue.face.specimens.first { $0.name == "no-cover" }?.picture) for name in ["sleeve-front", "sleeve-blank", "sleeve-back", "sleeve-shadow", "tolex", "lamp-glow"] { XCTAssertNotNil(CottonMedia.image(name, scale: 3), "\(name) is not in the catalogue") } XCTAssertTrue(CottonFonts.faces.contains(CottonFonts.sleeveFace)) XCTAssertEqual(CTFontCopyPostScriptName(AlbumSleeveSetting.sans(20)) as String, CottonFonts.sleeveFace, "the sans is registered") } }