use super::assertions::render_assertion;
use crate::e2e::field_access::FieldResolver;
use crate::e2e::fixture::Assertion;
use std::collections::{HashMap, HashSet};
fn empty_resolver() -> FieldResolver {
FieldResolver::new(
&HashMap::new(),
&HashSet::new(),
&HashSet::new(),
&HashSet::new(),
&HashSet::new(),
)
}
fn not_error_assertion() -> Assertion {
Assertion {
assertion_type: "not_error".to_string(),
..Default::default()
}
}
fn is_empty_assertion() -> Assertion {
Assertion {
assertion_type: "is_empty".to_string(),
..Default::default()
}
}
fn render(assertion: &Assertion, has_other_assertions: bool) -> String {
let resolver = empty_resolver();
let mut out = String::new();
render_assertion(
&mut out,
assertion,
"result",
&resolver,
"SampleModule",
&HashSet::new(),
&HashMap::new(),
false,
false,
false,
has_other_assertions,
);
out
}
#[test]
fn not_error_paired_with_is_empty_does_not_assert_presence() {
let out = render(¬_error_assertion(), true);
assert_eq!(
out, "",
"not_error must render nothing when a sibling assertion exists; got: {out}"
);
}
#[test]
fn not_error_as_sole_assertion_still_asserts_presence() {
let out = render(¬_error_assertion(), false);
assert_eq!(out, " refute is_nil(result)\n");
}
#[test]
fn not_error_then_is_empty_in_sequence_emits_only_is_empty() {
let mut out = String::new();
let resolver = empty_resolver();
for assertion in [¬_error_assertion(), &is_empty_assertion()] {
render_assertion(
&mut out,
assertion,
"result",
&resolver,
"SampleModule",
&HashSet::new(),
&HashMap::new(),
false,
false,
false,
true,
);
}
assert!(
!out.contains("refute is_nil(result)"),
"not_error must not assert presence alongside is_empty; got: {out}"
);
assert!(
out.contains("assert is_nil(result)"),
"is_empty must still render its own nil check; got: {out}"
);
}