use super::{Row, roster};
#[test]
fn every_row_is_the_name_the_binding_emits() {
for row in roster() {
assert_eq!(
(row.scalar_face)(),
row.scalar,
"the `{}` row's SCALAR name",
row.rust
);
match (row.filter, row.filter_face) {
(Some(name), Some(face)) => assert_eq!(face(), name, "the `{}` row's FILTER name", row.rust),
(None, None) => {}
_ => panic!(
"the `{}` row states a filter in one column and not the other",
row.rust
),
}
}
}
#[test]
fn a_filter_name_is_derived_from_its_scalar() {
for row in roster() {
let Some(filter) = row.filter else {
continue;
};
let mut raised = row.scalar.to_owned();
raised[..1].make_ascii_uppercase();
assert_eq!(filter, format!("{raised}Filter"), "the `{}` row", row.rust);
}
}
#[test]
fn the_roster_is_lowercase() {
for row in roster() {
assert_eq!(
row.scalar,
row.scalar.to_lowercase(),
"the `{}` row's scalar name is a framework default and takes lowercase",
row.rust
);
}
}
#[test]
fn the_roster_holds_exactly_these_rows() {
let mut names: Vec<&str> = roster().iter().map(|row| row.scalar).collect();
names.sort_unstable();
let mut expected = vec![
"bytes", "f32", "f64", "i128", "i16", "i32", "i64", "i8", "u128", "u16", "u32", "u64", "u8",
];
#[cfg(feature = "half")]
expected.push("f16");
#[cfg(feature = "rust_decimal")]
expected.push("f128");
expected.sort_unstable();
assert_eq!(names, expected);
}
fn named_text_rows() -> impl Iterator<Item = &'static Row> {
#[cfg(feature = "regex")]
let patterns: &'static [Row] = super::super::scalar::REGEX_ROWS;
#[cfg(not(feature = "regex"))]
let patterns: &'static [Row] = &[];
super::super::scalar::NET_ROWS
.iter()
.chain(super::super::scalar::UUID_ROWS)
.chain(patterns)
}
#[test]
fn every_parsed_text_row_derives_its_filter_name() {
for row in named_text_rows() {
let Row {
rust,
scalar,
filter,
scalar_face,
filter_face,
} = row;
assert_eq!(scalar_face(), *scalar, "the `{rust}` row's SCALAR name");
let (Some(name), Some(face)) = (filter, filter_face) else {
panic!("the `{rust}` row is a declarable column type and states a filter in both columns");
};
assert_eq!(face(), *name, "the `{rust}` row's FILTER name");
assert_eq!(
*name,
format!("{scalar}Filter"),
"the `{rust}` row derives its filter from its scalar, with no case to raise"
);
}
}
#[test]
fn every_parsed_text_row_is_pascal() {
for row in named_text_rows() {
let first = row
.scalar
.chars()
.next()
.expect("a scalar name is not empty");
assert!(
first.is_ascii_uppercase(),
"`{}` is a NAMED type and takes Pascal, not the roster's lowercase",
row.scalar
);
}
}