use super::*;
fn equated<F: EqualsFilter<T>, T>(value: T) -> F {
F::equals(value)
}
#[test]
fn every_row_is_its_kind_s_own_new_and_with_eq() {
assert_eq!(
equated::<ScalarFilter<i64>, _>(7),
ScalarFilter::new().with_eq(7)
);
assert_eq!(
equated::<TextFilter<String>, _>("clapper".to_owned()),
TextFilter::new().with_eq("clapper".to_owned())
);
assert_eq!(
equated::<BooleanFilter, _>(true),
BooleanFilter::new().with_eq(true)
);
assert_eq!(
equated::<BytesFilter<Vec<u8>>, _>(vec![0x89]),
BytesFilter::new().with_eq(vec![0x89])
);
assert_eq!(
equated::<EnumFilter<u8>, _>(3),
EnumFilter::new().with_eq(3)
);
}
#[test]
fn the_operand_lands_in_eq_alone() {
let scoped: ScalarFilter<i64> = equated(1);
assert_eq!(scoped.eq(), Some(&1));
assert!(!scoped.is_empty(), "an equated filter narrows something");
assert!(
scoped.is_referential(),
"eq alone is the shape a foreign key collapses on: {scoped:?}"
);
}
#[test]
fn a_nullable_column_equates_through_its_inner_kind() {
let scoped: Nullable<ScalarFilter<i64>> = equated(Some(1));
assert_eq!(scoped.inner().eq(), Some(&1));
assert_eq!(scoped.null(), None, "the null test is not an operand");
assert_eq!(scoped, Nullable::new(ScalarFilter::new().with_eq(1)));
}
#[test]
fn an_absent_operand_on_a_nullable_column_asks_for_null() {
let scoped: Nullable<ScalarFilter<i64>> = equated(None);
assert_eq!(scoped.null(), Some(&true));
assert!(
scoped.inner().is_empty(),
"the inner kind is untouched: {scoped:?}"
);
}
#[test]
fn one_call_serves_a_column_and_its_nullable_twin() {
type Column<T> = <<T as DefaultMarker>::Marker as crate::ToGraphqlFilter>::Filter;
fn scoped<T>(value: T) -> Column<T>
where
T: DefaultMarker,
Column<T>: EqualsFilter<T>,
{
EqualsFilter::equals(value)
}
assert_eq!(scoped(1_i64), ScalarFilter::new().with_eq(1));
assert_eq!(
scoped(Some(1_i64)),
Nullable::new(ScalarFilter::new().with_eq(1))
);
}
#[test]
fn the_getter_and_the_builder_do_not_collide() {
let scoped = <ScalarFilter<i64> as EqualsFilter<i64>>::equals(1);
assert_eq!(scoped.eq(), Some(&1), "the bare name is still the getter");
assert_eq!(ScalarFilter::<i32>::equals(2).eq(), Some(&2));
}