mod common;
use common::Sandbox;
fn descend(c: &Sandbox, goal: &str, n: usize) -> String {
let mut last = c.ok(&["push", goal, "--why", "the goal itself"]);
for i in 1..n {
last = c.ok(&[
"push",
&format!("Detour {i}"),
"--why",
"spotted along the way",
]);
}
last
}
#[test]
fn under_four_deep_there_is_no_advice() {
let c = Sandbox::new_seeded("shallow");
let s = descend(&c, "A goal", 3);
assert!(!s.contains("levels away"), "it warned at three deep:\n{s}");
}
#[test]
fn at_four_deep_the_advice_names_where_the_stack_began() {
let c = Sandbox::new_seeded("deep");
let s = descend(&c, "A goal", 4);
assert!(
s.contains("You are 4 levels away from g1 \"A goal\"."),
"{s}"
);
assert!(s.contains("did the real goal move?"), "{s}");
assert!(
s.contains("vivac promote"),
"no way out of the warning:\n{s}"
);
}
#[test]
fn with_several_roots_the_advice_names_your_own() {
let c = Sandbox::new_seeded("roots");
c.ok(&["push", "First goal", "--why", "it came first"]);
c.ok(&["pop", "done"]);
let s = descend(&c, "Second goal", 4);
assert!(
s.contains("You are 4 levels away from g2 \"Second goal\"."),
"it named a root that is not the one this stack came from:\n{s}"
);
assert!(!s.contains("First goal"), "{s}");
}