use super::FieldResolver;
use std::collections::{HashMap, HashSet};
fn resolver_with(config_optional: &[&str], ir_optional: &[&str]) -> FieldResolver {
let optional: HashSet<String> = config_optional.iter().map(|s| s.to_string()).collect();
let ir_optional: HashSet<String> = ir_optional.iter().map(|s| s.to_string()).collect();
FieldResolver::new(
&HashMap::new(),
&optional,
&HashSet::new(),
&HashSet::new(),
&HashSet::new(),
)
.with_ir_fields(HashSet::new(), HashSet::new(), ir_optional)
}
#[test]
fn an_ir_only_optional_name_is_not_reported_as_config_declared() {
let resolver = resolver_with(&[], &["structured_output"]);
assert!(
resolver.is_optional("structured_output"),
"classification must stay permissive: the IR really does prove this field optional"
);
assert_eq!(
resolver.declaring_config_key("structured_output"),
None,
"nothing in `[e2e].fields_optional` named this field -- the diagnostic must not claim it did"
);
}
#[test]
fn a_config_declared_optional_name_is_still_reported_with_its_key() {
let resolver = resolver_with(&["legacy_field"], &[]);
assert!(resolver.is_optional("legacy_field"));
assert_eq!(resolver.declaring_config_key("legacy_field"), Some("fields_optional"));
}
#[test]
fn config_declared_and_ir_only_names_are_told_apart_in_the_same_resolver() {
let resolver = resolver_with(&["legacy_field"], &["structured_output"]);
assert!(resolver.is_optional("legacy_field"));
assert!(resolver.is_optional("structured_output"));
assert_eq!(resolver.declaring_config_key("legacy_field"), Some("fields_optional"));
assert_eq!(resolver.declaring_config_key("structured_output"), None);
}