Cotton code
63 lines · 2.8 KB · RustRaw
use super::*;fn enters(name: &str) -> String {    format!("{name} enters.")}fn names() -> Vec<String> {    vec!["RAVI".to_string(), "MAYA".to_string()]}/// RULE (Story's new scene, 18 Nov 2026): an old scene's body reads as beats/// with nothing lost: action, speech with its aside, a note, a cut.#[test]fn an_old_body_reads_as_beats() {    let body = "Maya scrubs a plate.\nOver and over.\n\nRAVI\n(quietly)\nYou'll wear a hole in that.\n\n[[She should look at the drawer first.]]\n\nCUT TO:";    let read = read(body, &names());    let kinds: Vec<BeatKind> = read.iter().map(|beat| beat.kind).collect();    assert_eq!(kinds, [BeatKind::Action, BeatKind::Dialogue, BeatKind::Note, BeatKind::Action]);    assert_eq!(read[0].text, "Maya scrubs a plate.\nOver and over.");    assert_eq!((read[1].who.as_deref(), read[1].aside.as_deref()), (Some("RAVI"), Some("quietly")));    assert_eq!(read[2].text, "She should look at the drawer first.");    assert_eq!((read[3].form.as_deref(), read[3].text.as_str()), (Some("transition"), "CUT TO:"));}/// RULE: beats written out as a body read back as the same beats.#[test]fn beats_come_back_from_their_body() {    let body = "Maya scrubs a plate.\n\nRAVI\n(quietly)\nYou'll wear a hole in that.\nStop.\n\n[[Look at the drawer.]]\n\n>THE END<\n\nCUT TO:";    let beats = read(body, &names());    let again = compose(&beats, &names(), &enters);    assert_eq!(read(&again, &names()), beats);}/// RULE: action that would read as a cut stays action once composed.#[test]fn action_shaped_like_a_cut_stays_action() {    let beats = vec![Beat { kind: BeatKind::Action, who: None, aside: None, form: None, text: "SMASH TO:".to_string() }];    let body = compose(&beats, &names(), &enters);    assert_eq!(body, "!SMASH TO:");    assert_eq!(read(&body, &names())[0].form, None);}/// RULE: a speaker in a script without capitals is forced with `@`, and/// someone entering is written as a line of action.#[test]fn names_and_entrances_are_written_for_fountain() {    let beats = vec![        Beat { kind: BeatKind::Enters, who: Some("Ravi".into()), aside: None, form: None, text: String::new() },        Beat { kind: BeatKind::Dialogue, who: Some("రవి".into()), aside: None, form: None, text: "ఎక్కడ?".into() },    ];    assert_eq!(compose(&beats, &[], &enters), "Ravi enters.\n\n@రవి\nఎక్కడ?");}/// RULE: a key goes between two neighbours until they stand too close, and/// then says so instead of colliding.#[test]fn order_keys_split_until_the_gap_is_gone() {    assert_eq!(between(None, None), Some(1.0));    assert_eq!(between(Some(2.0), None), Some(3.0));    assert_eq!(between(None, Some(2.0)), Some(1.0));    assert_eq!(between(Some(1.0), Some(2.0)), Some(1.5));    assert_eq!(between(Some(1.0), Some(1.0 + SMALLEST_GAP / 2.0)), None);}