themes.rs: add test that looks in source code for invalid theme key references

pull/144/head
Manos Pitsidianakis 2022-03-22 20:26:06 +02:00
parent 81184b182c
commit 5823178cc2
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
1 changed files with 37 additions and 0 deletions

View File

@ -2135,3 +2135,40 @@ color_aliases= { "Jebediah" = "$JebediahJr", "JebediahJr" = "mail.listing.tag_de
let parsed: Themes = toml::from_str(TEST_INVALID_LINK_KEY_FIELD_STR).unwrap();
assert!(parsed.validate().is_err());
}
#[test]
fn test_theme_key_values() {
use std::collections::VecDeque;
use std::fs::File;
use std::io::Read;
use std::path::PathBuf;
let mut rust_files: VecDeque<PathBuf> = VecDeque::new();
let mut dirs_queue: VecDeque<PathBuf> = VecDeque::new();
dirs_queue.push_back("src/".into());
let re_whitespace = regex::Regex::new(r#"\s*"#).unwrap();
let re_conf = regex::Regex::new(r#"value\([&]?context,"([^"]*)""#).unwrap();
while let Some(dir) = dirs_queue.pop_front() {
for entry in std::fs::read_dir(&dir).unwrap() {
let entry = entry.unwrap();
let path = entry.path();
if path.is_dir() {
dirs_queue.push_back(path.into());
} else if path.extension().map(|os_s| os_s == "rs").unwrap_or(false) {
rust_files.push_back(path.into());
}
}
}
for file_path in rust_files {
let mut file = File::open(&file_path).unwrap();
let mut content = String::new();
file.read_to_string(&mut content).unwrap();
let content = re_whitespace.replace_all(&content, "");
for mat in re_conf.captures_iter(&content) {
let theme_key = &mat[1];
if !DEFAULT_KEYS.contains(&theme_key) {
panic!("Source file {} contains a hardcoded theme key str, {:?}, that is not included in the DEFAULT_KEYS table.", file_path.display(), theme_key);
}
}
}
}