use std::fmt::Write as FmtWrite;
pub(super) fn render_not_error(out: &mut String, result_var: &str, bare_result_is_option: bool, is_streaming: bool) {
if bare_result_is_option {
let _ = writeln!(
out,
" // not_error: covered by the bare Optional's own assertion"
);
} else if is_streaming {
let _ = writeln!(
out,
" assertTrue(chunks.isNotEmpty(), \"expected at least one streamed chunk\")"
);
} else {
let _ = writeln!(out, " assertNotNull({result_var}, \"expected non-null result\")");
}
}
#[cfg(test)]
mod tests {
use super::render_not_error;
#[test]
fn non_streaming_renders_a_real_assertion_on_the_result_variable() {
let mut out = String::new();
render_not_error(&mut out, "result", false, false);
assert_eq!(out, " assertNotNull(result, \"expected non-null result\")\n");
}
#[test]
fn streaming_asserts_on_the_drained_chunks_list_not_the_result_variable() {
let mut out = String::new();
render_not_error(&mut out, "result", false, true);
assert_eq!(
out,
" assertTrue(chunks.isNotEmpty(), \"expected at least one streamed chunk\")\n"
);
assert!(
!out.contains("result"),
"streaming must not reference result_var: got {out}"
);
}
#[test]
fn bare_optional_result_emits_no_not_null_assertion() {
let mut out = String::new();
render_not_error(&mut out, "result", true, false);
assert!(
!out.contains("assertNotNull(result"),
"bare Optional result must not assert non-null from not_error: got {out}"
);
}
}