use std::collections::{BTreeMap, BTreeSet};
use super::{DEPRECATED, EDITION, FLOOR, STAMPS, spells, spells_at, stamp};
use crate::test_support::corpus::record;
type Row = (String, String, u32);
fn stamped() -> BTreeMap<(String, String), u32> {
let mut found: BTreeMap<(String, String), u32> = BTreeMap::new();
for (shape, signature) in record().shapes {
for (spelled, edition) in signature {
let (path, _) = spelled
.rsplit_once(':')
.unwrap_or_else(|| panic!("{shape}: {spelled} names no type"));
let edition = u32::try_from(edition).expect("an edition");
let at = (shape.clone(), path.to_owned());
let held = found.entry(at).or_insert(edition);
*held = (*held).min(edition);
}
}
found
}
fn above_the_floor() -> BTreeSet<Row> {
stamped()
.into_iter()
.filter(|(_, edition)| *edition > FLOOR)
.map(|((shape, path), edition)| (shape, path, edition))
.collect()
}
#[test]
fn the_floor_and_the_edition_are_read_back_out_of_the_corpus() {
let corpus = record();
assert_eq!(
u64::from(FLOOR),
corpus.floor,
"the vendored FLOOR is not the corpus's — refresh one or correct the other"
);
let newest = stamped().into_values().max().expect("a stamped corpus");
assert_eq!(
EDITION, newest,
"the vendored EDITION is not the newest stamp in the corpus — a seat \
that overstates what it can spell is a seat that greys nothing"
);
}
#[test]
fn the_ledger_holds_exactly_what_the_corpus_stamps_above_the_floor() {
let carried: BTreeSet<Row> = STAMPS
.iter()
.map(|(shape, path, edition)| ((*shape).to_owned(), (*path).to_owned(), *edition))
.collect();
assert_eq!(
carried.len(),
STAMPS.len(),
"a path is stamped twice in the ledger"
);
assert_eq!(
carried,
above_the_floor(),
"the vendored edition ledger and the corpus disagree about what this \
major has grown — add the row in the commit that re-vendors the corpus"
);
}
#[test]
fn the_deprecation_list_is_the_corpus_own() {
let carried: Vec<String> = DEPRECATED.iter().map(|&named| named.to_owned()).collect();
assert_eq!(
carried,
record().deprecated,
"upstream has announced a removal this build has not written down — \
REMOTE §3.2's window rule gives three releases to answer it"
);
}
#[test]
fn a_path_the_ledger_does_not_carry_reads_as_the_floor() {
assert_eq!(stamp(STAMPS, "reply/workspaces", "/rows/[]/name"), FLOOR);
assert!(spells(FLOOR, "reply/workspaces", "/rows/[]/name"));
}
#[test]
fn a_post_floor_path_is_greyed_by_an_engine_that_cannot_spell_it() {
let grown: &[(&str, &str, u32)] = &[("reply/follow", "/rows/[]/parked", FLOOR + 2)];
assert_eq!(stamp(grown, "reply/follow", "/rows/[]/parked"), FLOOR + 2);
assert!(!spells_at(grown, FLOOR, "reply/follow", "/rows/[]/parked"));
assert!(!spells_at(
grown,
FLOOR + 1,
"reply/follow",
"/rows/[]/parked"
));
assert!(spells_at(
grown,
FLOOR + 2,
"reply/follow",
"/rows/[]/parked"
));
assert!(spells_at(grown, FLOOR, "reply/follow", "/rows/[]/says"));
assert!(spells_at(grown, FLOOR, "reply/steps", "/rows/[]/parked"));
}