Cotton code
40 lines · 1.9 KB · RustRaw
//! A chat's text, over invented people.use super::*;/// 2026-11-23T14:05:00Z.const AT: i64 = 1_795_442_700_000;fn words() -> Words {    Words { heading: "{name}".into(), exported: "Exported from Cotton Comms on {day}".into(), attached: "<attached: {file}>".into(), not_here: "<{what}, not on this phone>".into() }}#[test]fn each_message_is_one_line_with_its_day_clock_and_speaker() {    let said = vec![        Said { at: AT, who: Some("Asha".into()), words: Some("Hello there".into()), files: vec![] },        Said { at: AT + 60_000, who: Some("You".into()), words: Some("On my way\nfive minutes".into()), files: vec![] },        Said { at: AT + 120_000, who: Some("Asha".into()), words: Some("The tickets".into()), files: vec![Attachment::Here("files/tickets.pdf".into()), Attachment::NotHere("a picture".into())] },        Said { at: AT + 180_000, who: None, words: Some("Ravi joined".into()), files: vec![] },        Said { at: AT + 240_000, who: Some("Asha".into()), words: None, files: vec![] },    ];    // In Kolkata, 14:05Z is 19:35.    let text = transcript("Asha", &said, "Asia/Kolkata", AT + 86_400_000, &words());    assert_eq!(        text,        "Asha\nExported from Cotton Comms on 2026-11-24\n\n\         2026-11-23 19:35 · Asha: Hello there\n\         2026-11-23 19:36 · You: On my way\nfive minutes\n\         2026-11-23 19:37 · Asha: The tickets <attached: files/tickets.pdf> <a picture, not on this phone>\n\         2026-11-23 19:38 · Ravi joined\n",        "a message with nothing to say is left out"    );}#[test]fn names_become_names_a_folder_takes_and_stay_apart() {    assert_eq!(file_name("Mum / Dad: plans?", "Chat"), "Mum Dad plans");    assert_eq!(file_name("..hidden", "Chat"), "hidden");    assert_eq!(file_name("  ", "Chat"), "Chat");    assert_eq!(distinct(&["Asha".into(), "asha".into(), "scan.pdf".into(), "scan.pdf".into(), "Asha".into()]), ["Asha", "asha 2", "scan.pdf", "scan 2.pdf", "Asha 3"]);}