Cotton code
47 lines · 2.5 KB · SwiftRaw
// Cotton Story's faces (contract, 17 Nov 2026): the scene read as a chat// folds its lines into bubbles and narration, one side per speaker in a// two-hander; a card without the core's lines draws its body as action.@testable import CottonFacesimport CottonValuesimport XCTestfinal class StoryFacesTests: XCTestCase {    /// RULE: In a two-hander the first speaker's speech sits left and the other's right; an aside rides in its speech's bubble; action is narration.    func testATwoHanderFoldsIntoTwoSides() {        let beats = StoryChatBeat.of(StorySpecimenLinesCatalogue.twoHander)        let speeches = beats.filter { !$0.narration }        XCTAssertEqual(speeches.map(\.speaker), ["MEERA", "RAVI", "MEERA", "RAVI"])        XCTAssertEqual(speeches.map(\.side), [.left, .right, .left, .right])        XCTAssertEqual(speeches[1].aside, "(not looking up)")        XCTAssertEqual(speeches[1].words, "I said someone wanted it.")        XCTAssertTrue(beats.first?.narration ?? false)        XCTAssertEqual(beats.last?.words, "CUT TO:")    }    /// RULE: With more than two voices every bubble sits left, and a name's extension does not make a new speaker.    func testACrowdSpeaksFromTheLeft() {        let lines: [StoryLine] = [            StoryLine(.character, "ANU"), StoryLine(.dialogue, "One."), StoryLine(.blank, ""),            StoryLine(.character, "OLD SAILOR"), StoryLine(.dialogue, "Two."), StoryLine(.blank, ""),            StoryLine(.character, "RAVI (O.S.)"), StoryLine(.dialogue, "Three."), StoryLine(.blank, ""),            StoryLine(.character, "ANU (CONT'D)"), StoryLine(.dialogue, "Four."),        ]        let speeches = StoryChatBeat.of(lines)        XCTAssertEqual(speeches.map(\.speaker), ["ANU", "OLD SAILOR", "RAVI", "ANU"])        XCTAssertTrue(speeches.allSatisfy { $0.side == .left })    }    /// RULE: A card without the core's lines draws its body, each line as action and blank lines kept.    func testABodyWithoutLinesIsAction() {        let card = DeckCard(face: "scene.card", corner: nil, pressing: false, pace: nil, plate: nil, fields: ["body": .text("One\n\nTwo")])        XCTAssertEqual(StoryLine.of(card), [StoryLine(.action, "One"), StoryLine(.blank, ""), StoryLine(.action, "Two")])    }    /// RULE: Initials come from up to two words, in whatever script the name is written.    func testInitials() {        XCTAssertEqual(StoryPortrait.initials("Old Sailor"), "OS")        XCTAssertEqual(StoryPortrait.initials("Meera"), "M")        XCTAssertEqual(StoryPortrait.initials("రవి"), "ర")    }}