lernie 0.1.60

lernie: the operator seat — the window and wire client for a yog server
Documentation
//! Help, answered here: the roster's alignment, one verb's page, and the word
//! that is not a verb.

use super::{page, roster};
use crate::verbs::table;

/// Every verb has a line, and the column is computed from the widest of them —
/// so a verb added tomorrow cannot leave the alignment behind.
#[test]
fn the_roster_holds_every_verb_and_aligns_on_the_widest() {
    let text = roster();
    let lines: Vec<&str> = text.lines().collect();
    assert_eq!(lines.len(), table().len());
    for verb in table() {
        assert!(text.contains(&verb.usage()), "{} is missing", verb.word);
        assert!(text.contains(verb.summary), "{} has no summary", verb.word);
    }
    let widest = table()
        .iter()
        .map(|verb| verb.usage().len())
        .max()
        .expect("a verb");
    for (line, verb) in lines.iter().zip(table()) {
        let summary_at = line.find(verb.summary).expect("the summary");
        assert_eq!(summary_at, 2 + widest + 3, "{line:?}");
    }
}

/// One page: what to type, what it is for, and the detail folded to a width a
/// terminal holds.
#[test]
fn a_page_states_the_usage_the_summary_and_the_detail() {
    let text = page("follow").expect("a page");
    assert!(
        text.starts_with("usage: lernie follow <workspace> <agent>"),
        "{text}"
    );
    // **The phrases are sought in the page UNFOLDED.** The detail is wrapped
    // to a terminal width, so where a line break falls is a function of every
    // sentence ahead of it: asserting on the folded text lets an edit anywhere
    // in the page break a claim about a phrase further down, which is the
    // fold's doing and not the page's.
    let said = text.split_whitespace().collect::<Vec<&str>>().join(" ");
    assert!(said.contains("holds the line"), "{text}");
    // **The page states the protocol's own rule** (REMOTE §5.5, bl-5185): it
    // used to say the opposite — that each frame was the whole accumulated
    // fold, so a frame missed was nothing missed — which would be believed by
    // anyone reading this seat's raw output.
    assert!(said.contains("APPEND"), "{text}");
    assert!(said.contains("onto an empty fold"), "{text}");
    // **And that mail queued is not rest** (bl-3ecd, behaviour bl-87ab). The
    // page said a conversation already at rest is told to you at once, full
    // stop, which stopped being true of one with a deposit in its inbox — and
    // this page is where an operator learns why `follow` is holding.
    assert!(said.contains("MAIL QUEUED IS NOT REST"), "{text}");
    for line in text.lines() {
        assert!(line.len() <= 72, "{line:?} is {} wide", line.len());
    }
}

/// Every verb has a page, and none of them is empty — the table's `detail` is
/// not an optional field that a row may quietly skip.
#[test]
fn every_verb_answers_a_page() {
    for verb in table() {
        let text = page(verb.word).expect("a page");
        assert!(text.contains(verb.summary), "{}", verb.word);
        assert!(
            text.len() > verb.usage().len() + verb.summary.len(),
            "{}",
            verb.word
        );
    }
}

/// A word that is not a verb refuses **naming it**, and points at the list —
/// the operator who typed it is the one who needs it.
#[test]
fn a_word_that_is_not_a_verb_refuses_and_points_at_the_roster() {
    let refusal = page("wokspaces").expect_err("not a verb");
    assert!(refusal.contains("\"wokspaces\""), "{refusal}");
    assert!(refusal.contains("lernie help"), "{refusal}");
}