use crate::strings::latex::ToLatex;
use crate::strings::typst::ToTypst;
use crate::vars::{VarScheme, char_is_reserved};
use alloc::string::{String, ToString};
use alloc::vec::Vec;
pub fn var_scheme_properties<S: VarScheme>(scheme: &S, limit: usize) -> Vec<String> {
let n = scheme.capacity().map_or(limit, |c| c.min(limit));
let mut names = Vec::with_capacity(n);
for index in 0..n {
let name = scheme.var(index).to_string();
assert!(!name.is_empty(), "the name of variable {index} is empty");
if let Some(c) = name.chars().find(|&c| char_is_reserved(c)) {
panic!("the name {name:?} of variable {index} holds the reserved character {c:?}");
}
assert_eq!(
scheme.parse_var(&name),
Some(index),
"the name {name:?} of variable {index} does not read back as it"
);
assert_eq!(scheme.var(index).to_string(), name);
assert!(!scheme.var(index).to_latex_string().is_empty());
assert!(!scheme.var(index).to_typst_string().is_empty());
names.push(name);
}
let mut distinct = names.clone();
distinct.sort_unstable();
distinct.dedup();
assert_eq!(
distinct.len(),
names.len(),
"two variables have the same name"
);
for bad in ["", " ", "+", "^", "0"] {
assert_eq!(scheme.parse_var(bad), None, "{bad:?} reads as a variable");
}
names
}