macro_rules! switch {
($($name:ident => $variable:literal, $documentation:literal;)*) => {
$(
#[doc = $documentation]
pub fn $name() -> bool {
static HELD: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
*HELD.get_or_init(|| is_on(std::env::var_os($variable)))
}
)*
};
}
fn is_on(value: Option<std::ffi::OsString>) -> bool {
value.is_some_and(|value| !value.is_empty())
}
switch! {
trivia => "CPPLS_TRIVIA",
"Assert that the cursor never stands on trivia when `bump` emits — the live defect of \
`docs/parser-review.md` §4, made to fail loudly instead of silently dropping bytes.";
declaration_trace => "CPPLS_TRACE_DECLARATION",
"Print one line per declaration reading that failed, with the offset and the error — the trace that named \
the shape a construct was misread as.";
stats => "CPPLS_PARSER_STATS",
"Time every phase of a parse and print the table at the end of a run.";
}
#[cfg(test)]
mod tests {
use super::is_on;
#[test]
fn an_unset_variable_is_off_and_so_is_an_empty_one() {
assert!(!is_on(None));
assert!(!is_on(Some(std::ffi::OsString::from(""))));
assert!(is_on(Some(std::ffi::OsString::from("1"))));
}
}