d84914ef1e5a
parity.rs
//! Menu parity with the target menu tree: which catalog items are live. `cargo test -p texturecraft-ui-egui
//! parity` checks the floor; with `TC_UPDATE_PARITY=1` it rewrites `docs/parity.md`.
use crate::menus::{CATALOG, implemented};
/// Live menu items must never drop below this (raise it when parity rises).
pub const FLOOR: usize = 51;
/// (live, total) over the catalog, separators excluded.
pub fn counts() -> (usize, usize) {
let items: Vec<_> = CATALOG.iter().filter(|i| i.label != "-").collect();
(items.iter().filter(|i| implemented(i.id)).count(), items.len())
}
/// The Markdown report.
pub fn report() -> String {
let (live, total) = counts();
let mut out = String::new();
out.push_str("# Menu parity\n\nGenerated by `TC_UPDATE_PARITY=1 cargo test -p texturecraft-ui-egui parity`. ");
out.push_str("Each row is a menu item of the target menu layout with TextureCraft's command id; ");
out.push_str("**live** means the id is implemented. Feature parity beyond menus is tracked in [`ROADMAP.md`](../ROADMAP.md).\n\n");
out.push_str(&format!("**{live} of {total} menu items live ({:.0}%).**\n\n", live as f32 * 100.0 / total.max(1) as f32));
for top in crate::menus::TOP {
out.push_str(&format!("## {top}\n\n| Item | Id | Shortcut | Status |\n|---|---|---|---|\n"));
for i in CATALOG.iter().filter(|i| i.menu == top && i.label != "-") {
let label = match i.sub {
Some(s) => format!("{s} ▸ {}", i.label),
None => i.label.to_string(),
};
let status = if implemented(i.id) { "live" } else { "missing" };
out.push_str(&format!("| {label} | `{}` | {} | {status} |\n", i.id, i.shortcut.unwrap_or("")));
}
out.push('\n');
}
out
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn parity_floor_and_report() {
let (live, total) = counts();
assert!(live >= FLOOR, "menu parity dropped: {live} < {FLOOR}");
assert!(total >= live);
if std::env::var("TC_UPDATE_PARITY").is_ok() {
let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("../../docs/parity.md");
std::fs::write(path, report()).unwrap();
}
}
}
No file is open. Choose one in the tree, or press Ctrl+O (⌘O on a Mac) to find one by name.
Syntax highlighting could not load. The unmodified read-only text remains available above.