use super::{
SearchModel,
tests::{member, recipe, tight},
};
use crate::index::Dedup;
fn members() -> Vec<crate::search::MemberModel> {
vec![member("subs", "Subs"), member("shots", "Shots")]
}
fn rows(dedup: Dedup) -> (&'static str, &'static str) {
match dedup {
Dedup::Hash => (
"::ingraph::__private::retrieve::HashJoin",
"where__INGRAPH_ROOT__:::core::hash::Hash+::core::cmp::Eq+::core::clone::Clone,",
),
Dedup::Eq => (
"::ingraph::__private::retrieve::EqJoin",
"where__INGRAPH_ROOT__:::core::cmp::PartialEq+::core::clone::Clone,",
),
}
}
#[test]
fn both_rows_follow_the_word_and_the_other_mechanism_is_absent() {
for (chosen, other) in [(Dedup::Hash, Dedup::Eq), (Dedup::Eq, Dedup::Hash)] {
let emitted = tight(&recipe(members(), chosen));
let (join, admits) = rows(chosen);
let (unchosen_join, unchosen_admits) = rows(other);
assert!(
emitted.contains(join),
"`dedup({})` did not reach the fold's join: {emitted}",
chosen.as_str(),
);
assert!(
emitted.contains(admits),
"`dedup({})` did not reach the door's `where` row: {emitted}",
chosen.as_str(),
);
assert!(
!emitted.contains(unchosen_join),
"`dedup({})` emitted the other mechanism's join too: {emitted}",
chosen.as_str(),
);
assert!(
!emitted.contains(unchosen_admits),
"`dedup({})` emitted the other mechanism's bounds row too: {emitted}",
chosen.as_str(),
);
}
}
#[test]
fn the_default_emits_what_the_hash_word_emits() {
assert_eq!(
tight(&recipe(members(), Dedup::default())),
tight(&recipe(members(), Dedup::Hash)),
"the default is not the `hash` word",
);
assert_ne!(
tight(&recipe(members(), Dedup::Eq)),
tight(&recipe(members(), Dedup::Hash)),
"the two mechanisms emit one door, so neither pin above proves anything",
);
}
#[test]
fn the_emitted_doc_names_the_mechanism_it_chose() {
for dedup in [Dedup::Hash, Dedup::Eq] {
let emitted = recipe(members(), dedup).fuse().to_string();
assert!(
emitted.contains(&format!("Roots are placed through `{}`", dedup.join())),
"the door's doc does not name the mechanism: {emitted}",
);
assert!(
emitted.contains(&format!("this recipe's `dedup({})` chose", dedup.as_str())),
"the door's doc does not name the word that chose it: {emitted}",
);
assert!(
emitted.contains("a key that cannot hash is retrievable"),
"the door's doc drops the law the choice exists for: {emitted}",
);
}
}
#[test]
fn the_packages_and_the_evidence_do_not_move_with_the_word() {
let hash = recipe(members(), Dedup::Hash);
let eq = recipe(members(), Dedup::Eq);
let tokens = |model: &SearchModel, part: fn(&SearchModel) -> proc_macro2::TokenStream| {
part(model).to_string()
};
assert_eq!(
tokens(&hash, SearchModel::packages_emission),
tokens(&eq, SearchModel::packages_emission),
"the mechanism moved the packages",
);
assert_eq!(
tokens(&hash, SearchModel::evidence),
tokens(&eq, SearchModel::evidence),
"the mechanism moved the evidence and refusal enums",
);
assert_ne!(
tokens(&hash, SearchModel::door),
tokens(&eq, SearchModel::door),
"the mechanism did not reach the door it is spent in",
);
}