#![expect(clippy::expect_used)]
use std::path::Path;
const SHAPE_MODULES: [&str; 6] = [
"all_v2_chain",
"two_hop_seed_v4",
"two_hop_v4_led",
"three_hop",
"two_hop_uniswap_only",
"tag_residual",
];
const MAX_DERIVE_PLAN_LINES: usize = 80;
#[test]
fn walker_shape_modules_exist() {
for m in SHAPE_MODULES {
let p = Path::new(env!("CARGO_MANIFEST_DIR"))
.join("src/grammar_walker/shapes")
.join(format!("{m}.rs"));
assert!(
p.exists(),
"missing walker shape module {} — T1 structural split wants \
one module per enclosure block (arch review)",
p.display()
);
}
}
#[test]
fn derive_plan_is_a_thin_dispatcher() {
let src = include_str!("../src/grammar_walker.rs");
let start = src
.find("pub(crate) fn derive_plan(")
.expect("derive_plan exists");
let body = &src[start..];
let end_off = body
.split_inclusive('\n')
.position_of_col0_close()
.expect("derive_plan body closes at col 0");
let span = body.split_inclusive('\n').take(end_off).count();
assert!(
span <= MAX_DERIVE_PLAN_LINES,
"derive_plan spans {span} lines (max {MAX_DERIVE_PLAN_LINES}) — the \
six enclosure blocks must live in walker/shapes/, one module each, \
with derive_plan as a (len, repay-sequence) dispatcher only"
);
}
trait Col0Close {
fn position_of_col0_close(&mut self) -> Option<usize>;
}
impl<'a, I: Iterator<Item = &'a str>> Col0Close for I {
fn position_of_col0_close(&mut self) -> Option<usize> {
let mut i = 0;
for line in self.by_ref() {
i += 1;
if line == "}\n" || line == "}" {
return Some(i);
}
}
None
}
}