use crate::core::ir::{FieldDef, TypeDef, TypeRef};
use crate::e2e::config::E2eConfig;
use crate::e2e::field_access::FieldResolver;
use crate::e2e::fixture::Assertion;
use std::collections::{HashMap, HashSet};
fn process_result_import_info_type_defs() -> Vec<TypeDef> {
vec![
TypeDef {
name: "ProcessResult".to_string(),
fields: vec![FieldDef {
name: "imports".to_string(),
ty: TypeRef::Vec(Box::new(TypeRef::Named("ImportInfo".to_string()))),
..FieldDef::default()
}],
..TypeDef::default()
},
TypeDef {
name: "ImportInfo".to_string(),
fields: vec![FieldDef {
name: "source".to_string(),
ty: TypeRef::String,
..FieldDef::default()
}],
..TypeDef::default()
},
]
}
fn import_info_resolver() -> FieldResolver {
let type_defs = process_result_import_info_type_defs();
let result_field_map = FieldResolver::ir_result_field_facts(&type_defs, "ruby");
let collection_map = FieldResolver::ir_collection_fields(&type_defs);
let (reachable, excluded, optional) = FieldResolver::ir_field_sets(&type_defs);
let result_fields: HashSet<String> = ["imports".to_string()].into_iter().collect();
FieldResolver::new(
&HashMap::new(),
&HashSet::new(),
&result_fields,
&HashSet::new(),
&HashSet::new(),
)
.with_ir_result_fields(result_field_map, Some("ProcessResult".to_string()))
.with_ir_collection_map(collection_map, Some("ProcessResult".to_string()))
.with_ir_fields(reachable, excluded, optional)
}
fn render_imports_source_any(assertion_type: &str) -> String {
let assertion = Assertion {
assertion_type: assertion_type.to_string(),
field: Some("imports[].source".to_string()),
value: Some(serde_json::json!("os")),
..Default::default()
};
let mut out = String::new();
super::assertions::render_assertion(
&mut out,
&assertion,
"result",
&import_info_resolver(),
false,
&E2eConfig::default(),
&HashSet::new(),
&HashMap::new(),
);
out
}
#[test]
fn wildcard_element_half_resolves_against_the_element_type_not_the_container_path() {
let out = render_imports_source_any("contains");
assert!(
out.contains("{ |e| e.source.to_s.include?("),
"expected the element accessor to read straight off the block variable, got:\n{out}"
);
assert!(
!out.contains("e.imports"),
"element accessor must not re-walk the container path off the block variable, got:\n{out}"
);
}