#[derive(Debug, Default, Clone)]
pub struct DiagnosticOptions {
pub show_work: bool,
pub show_stats: bool,
pub show_match_checks: bool,
pub show_pruned_arith: bool,
pub show_pruned_range: bool,
pub show_db_adds: bool,
pub show_newton: bool,
pub unsupported_channels: Vec<char>,
}
pub fn parse_diagnostics(
diagnostics: Option<&str>,
show_work_flag: bool,
show_stats_flag: bool,
) -> DiagnosticOptions {
let mut opts = DiagnosticOptions {
show_work: show_work_flag,
show_stats: show_stats_flag,
show_match_checks: false,
show_pruned_arith: false,
show_pruned_range: false,
show_db_adds: false,
show_newton: false,
unsupported_channels: Vec::new(),
};
if let Some(spec) = diagnostics {
const COMPAT_NOOP_CHANNELS: &str = "CcDdEeFfHhIiJjKkLlPpQqRrTtUuVvWwXxZz";
for ch in spec.chars() {
match ch {
's' | 'N' => opts.show_work = true,
'y' | 'M' => opts.show_stats = true,
'o' => opts.show_match_checks = true,
'A' | 'a' => opts.show_pruned_arith = true,
'B' | 'b' => opts.show_pruned_range = true,
'G' | 'g' => opts.show_db_adds = true,
'n' => opts.show_newton = true,
_ if COMPAT_NOOP_CHANNELS.contains(ch) => {
}
_ => opts.unsupported_channels.push(ch),
}
}
}
opts
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_parse_diagnostics_empty() {
let opts = parse_diagnostics(None, false, false);
assert!(!opts.show_work);
assert!(!opts.show_stats);
assert!(opts.unsupported_channels.is_empty());
}
#[test]
fn test_parse_diagnostics_show_work() {
let opts = parse_diagnostics(Some("s"), false, false);
assert!(opts.show_work);
assert!(!opts.show_stats);
}
#[test]
fn test_parse_diagnostics_show_stats() {
let opts = parse_diagnostics(Some("y"), false, false);
assert!(!opts.show_work);
assert!(opts.show_stats);
}
#[test]
fn test_parse_diagnostics_multiple_channels() {
let opts = parse_diagnostics(Some("sny"), false, false);
assert!(opts.show_work);
assert!(opts.show_stats);
assert!(opts.show_newton);
}
#[test]
fn test_parse_diagnostics_flags_override() {
let opts = parse_diagnostics(None, true, true);
assert!(opts.show_work);
assert!(opts.show_stats);
}
#[test]
fn test_parse_diagnostics_unsupported_channel() {
let opts = parse_diagnostics(Some("z9"), false, false);
assert_eq!(opts.unsupported_channels, vec!['9']);
}
}