Cotton code
48 lines · 2.1 KB · RustRaw
use super::*;fn row(line: &str, words: &str) -> LineRow {    LineRow { set: "refusal".into(), line: line.into(), words: words.into() }}/// RULE: every connection refusal is said in the database's/// `refusal.connections` lines — a rewording is a row, and a line the/// database holds none of is the kit's. A refusal composed in Rust could/// not be reworded without a build.#[test]fn a_connection_refusal_is_said_in_the_databases_lines() {    assert_eq!(ConnectionRefusal::Paused.sentence(&[]), "It is paused. Resume it first, then read it.");    assert_eq!(ConnectionRefusal::Paused.sentence(&[row("connections.paused", "Paused.")]), "Paused.");    let gateway = ConnectionRefusal::Gateway { host: "server.smithery.ai".into(), gateway: "smithery.ai".into() };    assert!(gateway.sentence(&[]).starts_with("server.smithery.ai is smithery.ai, a hosted MCP gateway"));    assert_eq!(        gateway.sentence(&[row("connections.gateway", "{gateway} sits between ({host}).")]),        "smithery.ai sits between (server.smithery.ai)."    );    let warning = third_party_warning("mcp.example.org", &[]);    assert!(warning.starts_with("mcp.example.org is neither"));    assert_eq!(        unverified(&warning, &[row("connections.unverified", "{warning} Confirm?")]),        format!("{warning} Confirm?")    );}/// Every variant has a kit line: a missing one would say its dotted path.#[test]fn every_connection_refusal_has_a_kit_line() {    let all = [        ConnectionRefusal::Gone,        ConnectionRefusal::Paused,        ConnectionRefusal::NoStories,        ConnectionRefusal::NotGoogle,        ConnectionRefusal::SettingsUnreadable,        ConnectionRefusal::NotAUrl { url: "x".into() },        ConnectionRefusal::NoHost { url: "x".into() },        ConnectionRefusal::PlainHttp { url: "x".into() },        ConnectionRefusal::NotAWebScheme { url: "x".into(), scheme: "ftp".into() },        ConnectionRefusal::Gateway { host: "x".into(), gateway: "y".into() },    ];    for refusal in all {        let said = refusal.sentence(&[]);        assert!(!said.starts_with("refusal."), "{refusal:?} has no kit line: {said}");    }}