use std::collections::BTreeMap;
const DEFAULT_PALETTE: [(&str, &str); 4] = [
("keyword", "#ff7b72"),
("function", "#d2a8ff"),
("comment", "#8b949e"),
("type", "#ffa657"),
];
#[must_use]
pub fn default_syntax_theme() -> BTreeMap<String, String> {
DEFAULT_PALETTE
.iter()
.map(|(capture, color)| ((*capture).to_owned(), (*color).to_owned()))
.collect()
}
#[cfg(test)]
mod tests {
use super::default_syntax_theme;
#[test]
fn default_palette_values_are_hex_colors() {
let theme = default_syntax_theme();
assert_eq!(theme.len(), 4);
for (capture, color) in &theme {
assert!(!capture.is_empty(), "capture name must be non-empty");
assert_eq!(color.len(), 7, "{capture}: {color} must be #rrggbb");
assert!(
color.starts_with('#'),
"{capture}: {color} must start with #"
);
assert!(
color[1..].bytes().all(|byte| byte.is_ascii_hexdigit()),
"{capture}: {color} must be hex after #"
);
}
}
#[test]
fn default_palette_matches_the_fake_feed_source_of_truth() {
let theme = default_syntax_theme();
assert_eq!(theme.get("keyword").map(String::as_str), Some("#ff7b72"));
assert_eq!(theme.get("function").map(String::as_str), Some("#d2a8ff"));
assert_eq!(theme.get("comment").map(String::as_str), Some("#8b949e"));
assert_eq!(theme.get("type").map(String::as_str), Some("#ffa657"));
}
}