use super::*;
#[derive(Default)]
struct RecordingFake {
read_line_calls: Vec<String>,
next: Option<ReadOutcome>,
}
impl InputSurface for RecordingFake {
fn read_line(&mut self, prompt: &str) -> anyhow::Result<ReadOutcome> {
self.read_line_calls.push(prompt.to_string());
Ok(self.next.take().unwrap_or(ReadOutcome::Eof))
}
fn add_history(&mut self, _entry: &str) {}
fn save_history(&mut self) {}
fn reload(&mut self) -> anyhow::Result<()> {
Ok(())
}
fn present_interaction(
&mut self,
_interaction: &newt_core::interaction_surface::SurfaceInteraction,
) -> newt_core::HumanQuestionOutcome {
newt_core::HumanQuestionOutcome::Unavailable
}
}
#[test]
fn the_default_forwards_the_unmodified_prompt_to_read_line() {
let mut fake = RecordingFake {
next: Some(ReadOutcome::Line("2: ship it".to_string())),
..Default::default()
};
let outcome = fake
.present_clarification(
"1: which lane?\n a) build\n b) ship",
"reply with an ordinal — or /discuss",
"› ",
true,
false,
)
.expect("default body never errors on a fake surface");
assert_eq!(fake.read_line_calls, vec!["› ".to_string()]);
assert!(matches!(outcome, ReadOutcome::Line(a) if a == "2: ship it"));
}
#[test]
fn the_default_reads_exactly_once() {
let mut fake = RecordingFake::default();
let _ = fake.present_clarification("batch", "hint", "prompt", false, false);
assert_eq!(fake.read_line_calls.len(), 1);
}
#[test]
fn every_read_outcome_variant_passes_through_unchanged() {
for outcome in [
ReadOutcome::Interrupted,
ReadOutcome::Eof,
ReadOutcome::Fatal("degraded".to_string()),
] {
let expect_debug = format!("{outcome:?}");
let mut fake = RecordingFake {
next: Some(outcome),
..Default::default()
};
let got = fake
.present_clarification("batch", "hint", "prompt", false, false)
.expect("default body never errors on a fake surface");
assert_eq!(format!("{got:?}"), expect_debug);
}
}