use ingraph_codegen::model::DatabaseKind;
use super::tests::{accepted, refused};
#[test]
fn the_three_shipped_engines_are_taken_and_carried() {
for (word, kind) in [
("sqlite", DatabaseKind::Sqlite),
("postgres", DatabaseKind::Postgres),
("mysql", DatabaseKind::Mysql),
] {
let word = syn::Ident::new(word, proc_macro2::Span::call_site());
let model = accepted(quote::quote! {
#[ingraph(generations(#word))]
struct App {
videos: Video,
}
});
let seat = model
.generations
.expect("the word was written, so the seat is there");
assert_eq!(seat.engine, kind);
}
}
#[test]
fn a_root_that_wrote_nothing_declares_no_seat() {
let model = accepted(quote::quote! {
struct App {
videos: Video,
}
});
assert!(model.generations.is_none());
}
#[test]
fn a_document_store_is_not_a_word_here() {
let refusal = refused(quote::quote! {
#[ingraph(generations(mongo))]
struct App {
videos: Video,
}
});
assert!(
refusal.contains("`mongo` is not an engine the generations seat builds"),
"{refusal}"
);
assert!(
refusal.contains("MEMBERSHIP sweep"),
"the refusal says WHY the vocabulary is shorter: {refusal}"
);
assert!(
refusal.contains("`ingraph::GenerationsStore`"),
"and where the road is instead: {refusal}"
);
}
#[test]
fn a_word_that_is_no_engine_is_refused_with_the_three_that_are() {
let refusal = refused(quote::quote! {
#[ingraph(generations(redb))]
struct App {
videos: Video,
}
});
assert!(refusal.contains("`redb` is not an engine"), "{refusal}");
assert!(
refusal.contains("`sqlite`, `postgres` or `mysql`"),
"{refusal}"
);
}
#[test]
fn the_engine_is_a_bare_word_and_the_knobs_are_the_documents() {
let refusal = refused(quote::quote! {
#[ingraph(generations(sqlite(dsn = "sqlite://var/x.db")))]
struct App {
videos: Video,
}
});
assert!(refusal.contains("`sqlite` is a bare word"), "{refusal}");
assert!(refusal.contains("`[generations]` section"), "{refusal}");
assert!(refusal.contains("`keep = <n>`"), "{refusal}");
}
#[test]
fn a_multi_segment_path_is_not_an_engine_word() {
let refusal = refused(quote::quote! {
#[ingraph(generations(app::store::Redb))]
struct App {
videos: Video,
}
});
assert!(
refusal.contains("the engine inside `generations(…)` is ONE word"),
"{refusal}"
);
}
#[test]
fn one_root_declares_one_seat() {
let refusal = refused(quote::quote! {
#[ingraph(generations(sqlite), generations(postgres))]
struct App {
videos: Video,
}
});
assert!(
refusal.contains("`generations(…)` already named `sqlite`"),
"the FIRST word is the one kept: {refusal}"
);
}
#[test]
fn one_block_names_one_engine() {
let refusal = refused(quote::quote! {
#[ingraph(generations(sqlite, postgres))]
struct App {
videos: Video,
}
});
assert!(
refusal.contains("`generations(…)` already named `sqlite`"),
"{refusal}"
);
}
#[test]
fn the_word_is_on_the_roster_a_wrong_guess_is_answered_with() {
let refusal = refused(quote::quote! {
#[ingraph(generation(sqlite))]
struct App {
videos: Video,
}
});
assert!(refusal.contains("generations(<engine>)"), "{refusal}");
}