use std::collections::{HashMap, HashSet};
use crate::e2e::field_access::FieldResolver;
use crate::e2e::fixture::Assertion;
use super::assertions::render_assertion;
fn permissive_resolver() -> FieldResolver {
FieldResolver::new(
&HashMap::new(),
&HashSet::new(),
&HashSet::new(),
&HashSet::new(),
&HashSet::new(),
)
}
#[test]
fn is_empty_on_a_serialized_json_array_field_accepts_the_empty_array_literal() {
let assertion = Assertion {
assertion_type: "is_empty".to_string(),
field: Some("data.children".to_string()),
value: None,
..Default::default()
};
let accessed_fields = [("data.children".to_string(), "data_children".to_string(), false)];
let mut out = String::new();
render_assertion(
&mut out,
&assertion,
"result",
"sample",
&permissive_resolver(),
&accessed_fields,
&HashMap::new(),
&HashMap::new(),
&HashMap::new(),
);
assert!(
out.contains("strcmp(data_children, \"[]\") == 0"),
"must accept the serialized-empty-array form: {out}"
);
assert!(
out.contains("strlen(data_children) == 0"),
"must still accept a genuinely empty string too: {out}"
);
}
#[test]
fn not_empty_on_a_serialized_json_array_field_rejects_the_empty_array_literal() {
let assertion = Assertion {
assertion_type: "not_empty".to_string(),
field: Some("data.children".to_string()),
value: None,
..Default::default()
};
let accessed_fields = [("data.children".to_string(), "data_children".to_string(), false)];
let mut out = String::new();
render_assertion(
&mut out,
&assertion,
"result",
"sample",
&permissive_resolver(),
&accessed_fields,
&HashMap::new(),
&HashMap::new(),
&HashMap::new(),
);
assert!(
out.contains("strcmp(data_children, \"[]\") != 0"),
"\"[]\" must not count as non-empty: {out}"
);
}