use serde_json::Value;
use super::super::{Read, read};
use crate::channel::edition::{EDITION, FLOOR};
use crate::test_support::corpus::editions::{mutate, project, words};
use crate::test_support::corpus::{Signature, files, fixture, record};
const UNHEARD: &str = "a-word-no-engine-has-ever-written";
fn painted() -> Vec<(String, Signature, Vec<Value>)> {
let shapes = record().shapes;
files("answers")
.iter()
.map(|path| fixture(path))
.filter_map(|file| {
let shape = file.shape.clone()?;
let signature = shapes
.get(&format!("reply/{shape}"))
.unwrap_or_else(|| panic!("upstream stamps no signature for {shape}"));
Some((shape, signature.clone(), file.frames))
})
.collect()
}
#[test]
fn every_answer_reads_at_every_edition_of_this_major() {
let mut replayed = 0_usize;
for (shape, signature, frames) in painted() {
for at in FLOOR..=EDITION {
for frame in &frames {
let older = project(frame, &signature, at);
let answered = read(&older);
assert!(
matches!(answered, Read::Answer(_)),
"{shape} projected to edition {at} reads as {answered:?} — a \
field stamped after {at} is being required",
);
replayed += 1;
}
}
}
assert!(
replayed > 0,
"no vendored answer was projected — the walk is broken, not the corpus"
);
}
#[test]
fn an_unheard_of_word_in_any_vocabulary_is_still_an_answer() {
let mut mutated = 0_usize;
for (shape, signature, frames) in painted() {
for path in words(&signature) {
for frame in &frames {
let Some(said) = mutate(frame, &path, UNHEARD) else {
continue;
};
let answered = read(&said);
assert!(
matches!(answered, Read::Answer(_)),
"{shape} with {path} set to an unheard-of word reads as \
{answered:?} — a vocabulary is refusing instead of carrying",
);
mutated += 1;
}
}
}
assert!(
mutated > 0,
"no word was mutated — the walk is broken, not the corpus"
);
}