Cotton code
191 lines · 10.2 KB · RustRaw
use super::*;use crate::rules::shell_lines::LineSet;// Every app's defaults name a paper, an ink and a face it offers, and the default look is the app's look as it was.#[test]fn every_app_has_its_default_look() {    for id in APPS {        let look = app(id).unwrap_or_else(|| panic!("{id} has a look"));        let d = look.defaults();        assert!(look.paper(&d.light).is_some() && look.paper(&d.dark).is_some(), "{id}'s default papers");        assert!(look.ink(&d.ink).is_some(), "{id}'s default ink");        assert!(look.face(&d.face).is_some(), "{id}'s default face");        assert!(look.offers_size(d.size), "{id}'s default size");        assert_eq!(look.inks.len(), if ["keys", "mail", "data", "sites"].contains(&id) { 5 } else { 4 }, "{id}: four inks, five in Secrets, Post, Data and Sites");        for paper in &look.papers {            for half in [&paper.light, &paper.dark] {                for token in look.tokens.iter().filter(|t| !look.inks[0].light.contains_key(*t)) {                    assert!(half.contains_key(token), "{id} {} has no {token}", paper.id);                }            }        }        for choice in &kit().choices {            assert!(look.face(choice).is_some(), "{id} offers {choice}");        }    }    // Words: Linen and Slate in blue, Figtree at 17, exactly as before Look.    let words = app("notes").unwrap();    let linen = words.paper("linen").unwrap();    assert_eq!(words.inked(linen, words.ink("blue").unwrap(), false)["accent"], "#2B4A8F");    assert_eq!(words.defaults().size, 17.0);    assert_eq!(words.face("own").unwrap().family, "Figtree");    // Days and Story stay light in a dark phone (Grey's two halves are one), in their own blue.    for (id, blue) in [("days", "#1D3FD8"), ("story", "#1F3FE0")] {        let look = app(id).unwrap();        let grey = look.paper("grey").unwrap();        assert_eq!(grey.light, grey.dark);        assert_eq!(look.inked(grey, look.ink("blue").unwrap(), true)["accent"], blue);    }    // Comms: terracotta by day, amber at night, on the warm ground.    let comms = app("messages").unwrap();    let warm = comms.paper("warm").unwrap();    let terracotta = comms.ink("terracotta").unwrap();    assert_eq!(comms.inked(warm, terracotta, false)["accent"], "#C8552D");    assert_eq!(comms.inked(warm, terracotta, true)["accent"], "#E0A243");    // Secrets (the owner, 25 Nov 2026): plum on lilac by day, lilac plum on night; Red Hat Text its own face, and Red    // Hat Mono bundled for every secret value whatever face is chosen.    let secrets = app("keys").unwrap();    let d = secrets.defaults();    assert_eq!((d.light.as_str(), d.dark.as_str(), d.ink.as_str()), ("lilac", "night", "plum"));    let plum = secrets.ink("plum").unwrap();    assert_eq!(secrets.inked(secrets.paper("lilac").unwrap(), plum, false)["accent"], "#7A3C9E");    assert_eq!(secrets.inked(secrets.paper("lilac").unwrap(), plum, false)["ground"], "#F1EEF3");    assert_eq!(secrets.inked(secrets.paper("night").unwrap(), plum, true)["accent"], "#C39BE3");    assert_eq!(secrets.inked(secrets.paper("night").unwrap(), plum, true)["ground"], "#18131D");    assert_eq!(secrets.face("own").unwrap().family, "Red Hat Text");    assert!(kit().faces.iter().any(|f| f.id == "red_hat_mono" && f.family == "Red Hat Mono"));    assert_eq!(secrets.inks.iter().map(|i| i.id.as_str()).collect::<Vec<_>>(), ["plum", "jade", "garnet", "indigo", "graphite"]);}// Secrets' main button and its words read on every paper in every ink (the accent there is a button's fill).#[test]fn secrets_inks_read_on_every_paper() {    let secrets = app("keys").unwrap();    for paper in &secrets.papers {        for ink in &secrets.inks {            for dark in [false, true] {                let c = secrets.inked(paper, ink, dark);                assert!(contrast(&c["ink"], &c["ground"]) >= 4.5, "{} {} dark={dark}: words", paper.id, ink.id);                assert!(contrast(&c["on_accent"], &c["accent"]) >= 4.5, "{} {} dark={dark}: a button's words", paper.id, ink.id);                assert!(contrast(&c["accent"], &c["ground"]) >= 3.0, "{} {} dark={dark}: the accent on the ground", paper.id, ink.id);            }        }    }}// The default look reads: its words stand at least 4.5:1 on its ground (only the default is ours to prove).#[test]fn the_default_look_reads() {    for id in APPS {        let look = app(id).unwrap();        let d = look.defaults();        for (paper, dark) in [(&d.light, false), (&d.dark, true)] {            let colours = look.inked(look.paper(paper).unwrap(), look.ink(&d.ink).unwrap(), dark);            let ground = colours.get("sheet").or(colours.get("ground")).unwrap();            let text = colours.get("ink").or(colours.get("text")).unwrap();            assert!(contrast(text, ground) >= 4.5, "{id} {paper} dark={dark}: {text} on {ground}");        }    }}// Every face is bundled with its licence where the kit says, and every word is the look set's.#[test]fn faces_are_bundled_and_named() {    let repo = cotton_store::manifest_dir().join("../..");    for face in &kit().faces {        assert!(face.licence.starts_with("SIL OFL 1.1"), "{}", face.id);        assert!(repo.join(&face.dir).join(&face.licence_file).is_file(), "{}'s licence", face.id);        for file in &face.files {            assert!(repo.join(&face.dir).join(&file.file).is_file(), "{} {}", face.id, file.file);        }    }    let lines = LineSet::shipped("look").expect("the look set ships");    for key in ["title", "paper", "ink", "text", "face", "size", "light", "dark", "reset.title", "reset.yes", "reset.no"] {        assert!(lines.say(key, &[]).is_some(), "look {key}");    }    for choice in kit().choices.iter().filter(|c| *c != "own") {        assert!(lines.say(&format!("faces.{choice}"), &[]).is_some(), "{choice}");    }    for id in APPS {        let look = app(id).unwrap();        assert!(lines.say(&format!("apps.{id}"), &[]).is_some());        for ink in &look.inks {            assert!(lines.say(&format!("inks.{}", ink.id), &[]).is_some(), "{id} {}", ink.id);        }        if id != "notes" {            for paper in &look.papers {                assert!(lines.say(&format!("papers.{id}.{}", paper.id), &[]).is_some(), "{id} {}", paper.id);            }        }    }}// Post (the owner, 25 Nov 2026): the Stamp look, franking green on sage by day, pale green on night; Instrument Sans// its own face, with Newsreader for a mail's words and JetBrains Mono for passwords and records bundled beside it.#[test]fn post_has_the_stamp_look() {    let post = app("mail").unwrap();    let d = post.defaults();    assert_eq!((d.light.as_str(), d.dark.as_str(), d.ink.as_str()), ("sage", "night", "franking"));    let franking = post.ink("franking").unwrap();    assert_eq!(post.inked(post.paper("sage").unwrap(), franking, false)["accent"], "#1E6B4A");    assert_eq!(post.inked(post.paper("sage").unwrap(), franking, false)["ground"], "#F1F3EE");    assert_eq!(post.inked(post.paper("night").unwrap(), franking, true)["accent"], "#7CC9A0");    assert_eq!(post.inked(post.paper("night").unwrap(), franking, true)["ground"], "#131915");    assert_eq!(post.face("own").unwrap().family, "Instrument Sans");    for (id, family) in [("newsreader", "Newsreader"), ("jetbrains_mono", "JetBrains Mono")] {        assert!(kit().faces.iter().any(|f| f.id == id && f.family == family), "{id} is bundled");    }    assert_eq!(post.inks.iter().map(|i| i.id.as_str()).collect::<Vec<_>>(), ["franking", "teal", "oxblood", "ink_blue", "graphite"]);}// Post's main button and its words read on every paper in every ink.#[test]fn post_inks_read_on_every_paper() {    let post = app("mail").unwrap();    for paper in &post.papers {        for ink in &post.inks {            for dark in [false, true] {                let c = post.inked(paper, ink, dark);                assert!(contrast(&c["ink"], &c["ground"]) >= 4.5, "{} {} dark={dark}: words", paper.id, ink.id);                assert!(contrast(&c["on_accent"], &c["accent"]) >= 4.5, "{} {} dark={dark}: a button's words", paper.id, ink.id);                assert!(contrast(&c["accent"], &c["ground"]) >= 3.0, "{} {} dark={dark}: the accent on the ground", paper.id, ink.id);            }        }    }}// Sites (the owner, 25 Nov 2026, DECISIONS "The look", palette B): the Thread look, cranberry on rose by day, rose on// night; Instrument Sans its own face; papers rose, paper, night and black; inks cranberry first, then petrol, indigo,// ochre and graphite.#[test]fn sites_has_the_thread_look() {    let sites = app("sites").unwrap();    let d = sites.defaults();    assert_eq!((d.light.as_str(), d.dark.as_str(), d.ink.as_str()), ("rose", "night", "cranberry"));    let cranberry = sites.ink("cranberry").unwrap();    assert_eq!(sites.inked(sites.paper("rose").unwrap(), cranberry, false)["accent"], "#9A2C4C");    assert_eq!(sites.inked(sites.paper("rose").unwrap(), cranberry, false)["ground"], "#F5F1F1");    assert_eq!(sites.inked(sites.paper("night").unwrap(), cranberry, true)["accent"], "#E58AA6");    assert_eq!(sites.inked(sites.paper("night").unwrap(), cranberry, true)["ground"], "#171213");    assert_eq!(sites.inked(sites.paper("black").unwrap(), cranberry, true)["ground"], "#000000");    assert_eq!(sites.face("own").unwrap().family, "Instrument Sans");    assert_eq!(sites.papers.iter().map(|p| p.id.as_str()).collect::<Vec<_>>(), ["rose", "paper", "night", "black"]);    assert_eq!(sites.inks.iter().map(|i| i.id.as_str()).collect::<Vec<_>>(), ["cranberry", "petrol", "indigo", "ochre", "graphite"]);}// Sites' words, a button's words and the accent read on every paper in every ink.#[test]fn sites_inks_read_on_every_paper() {    let sites = app("sites").unwrap();    for paper in &sites.papers {        for ink in &sites.inks {            for dark in [false, true] {                let c = sites.inked(paper, ink, dark);                assert!(contrast(&c["ink"], &c["ground"]) >= 4.5, "{} {} dark={dark}: words", paper.id, ink.id);                assert!(contrast(&c["on_accent"], &c["accent"]) >= 4.5, "{} {} dark={dark}: a button's words", paper.id, ink.id);                assert!(contrast(&c["accent"], &c["ground"]) >= 3.0, "{} {} dark={dark}: the accent on the ground", paper.id, ink.id);            }        }    }}