use crate::{
emit::sortable_tests::sortable,
model::RecordModel,
tests::{
edge_declared_in_postgres, emission, enum_named, gathered, gathered_in_mysql,
gathered_in_postgres,
},
};
fn squeezed(model: &RecordModel) -> String {
model.emit().to_string().replace(' ', "")
}
fn slots(model: &RecordModel, cursor: &str) -> Vec<String> {
enum_named(&emission(model), cursor)
.variants
.iter()
.map(|variant| variant.ident.to_string())
.collect()
}
const BYTES: &str = "::std::vec::Vec<::core::primitive::u8>";
#[test]
fn a_sortable_collection_joins_the_cursor_sum_at_the_companions_type() {
let worded = sortable(gathered());
assert_eq!(
slots(&worded, "MediaSqliteCursor"),
["Id", "Checksum", "Chapters", "CoverId"],
"the collection is a boundary this database can take"
);
assert!(
squeezed(&worded).contains(&format!("Chapters({BYTES})")),
"and the slot holds the sort key, which is one ordinary blob"
);
}
#[test]
fn the_value_arm_reads_the_projected_alias() {
let tokens = squeezed(&sortable(gathered()));
assert!(
tokens.contains(&format!(
"try_get::<{BYTES},_>(__ingraph_raw,__ingraph_alias)"
)),
"the boundary is the ordered row's own bytes: {tokens}"
);
}
#[test]
fn the_other_edge_dialect_answers_alike() {
let worded = sortable(gathered_in_mysql());
assert!(slots(&worded, "MediaMysqlCursor").contains(&"Chapters".to_owned()));
assert!(squeezed(&worded).contains("__ingraph_alias"));
}
#[test]
fn the_array_dialect_keeps_the_list_slot_it_already_had() {
let worded = sortable(gathered_in_postgres());
let tokens = squeezed(&worded);
assert!(
slots(&worded, "MediaPostgresCursor").contains(&"Chapters".to_owned()),
"the slot was already there — a native array binds as one parameter"
);
assert!(
!tokens.contains(&format!("Chapters({BYTES})")),
"and it still holds the LIST: {tokens}"
);
assert!(
!tokens.contains("__ingraph_alias"),
"no term of this order reads the raw row: {tokens}"
);
}
#[test]
fn the_array_dialect_takes_the_companion_slot_where_the_word_moved_the_collection() {
let worded = sortable(edge_declared_in_postgres());
let tokens = squeezed(&worded);
assert!(
slots(&worded, "MediaPostgresCursor").contains(&"Chapters".to_owned()),
"the collection is a boundary here too, through its companion"
);
assert!(
tokens.contains(&format!("Chapters({BYTES})")),
"and the slot holds the sort key, on the dialect whose ARRAY row holds the list: {tokens}"
);
assert!(
tokens.contains(&format!(
"try_get::<{BYTES},_>(__ingraph_raw,__ingraph_alias)"
)),
"read off the ordered row, as on every other dialect: {tokens}"
);
}
#[test]
fn a_wordless_edge_collection_has_no_slot() {
let wordless = gathered();
assert_eq!(
slots(&wordless, "MediaSqliteCursor"),
["Id", "Checksum", "CoverId"],
"no companion, no boundary, no slot"
);
assert!(
!squeezed(&wordless).contains("__ingraph_alias"),
"and nothing reads the raw row"
);
}
#[test]
fn the_slot_and_the_write_plan_name_one_type() {
let tokens = squeezed(&sortable(gathered()));
assert!(tokens.contains(&format!("Chapters({BYTES})")), "{tokens}");
assert!(
tokens.contains(&format!(
"<{BYTES}as::ingraph::__private::comparison::sql::Carrier<__INGRAPH_DB__>>::push_bind"
)),
"the write plan binds the same type the slot holds: {tokens}"
);
}