use cydonia::agent::{OUTPUT_KEEP, record};
fn printed(lines: &[&str]) -> Vec<String> {
let mut held = Vec::new();
for line in lines {
record(&mut held, (*line).to_owned());
}
held
}
#[test]
fn the_last_line_is_the_step_it_has_reached() {
let held = printed(&["downloading claude.tar.gz", "downloaded 8 MB", "unpacking"]);
assert_eq!(held.last().map(String::as_str), Some("unpacking"));
}
#[test]
fn a_long_install_is_held_to_its_tail() {
let lines: Vec<String> = (0..OUTPUT_KEEP + 10).map(|n| format!("line {n}")).collect();
let mut held = Vec::new();
for line in lines {
record(&mut held, line);
}
assert_eq!(held.len(), OUTPUT_KEEP);
assert_eq!(held.first().map(String::as_str), Some("line 10"));
assert_eq!(
held.last().map(String::as_str),
Some(format!("line {}", OUTPUT_KEEP + 9).as_str())
);
}
#[test]
fn nothing_printed_is_no_status() {
assert!(printed(&[]).is_empty());
}