use crate::config::profile::with_home_override;
use crate::config::{Config, opencrabs_home};
use crate::tui::render::theme::configured_name;
fn stored_theme() -> String {
let text = std::fs::read_to_string(opencrabs_home().join("config.toml")).expect("config.toml");
let doc: toml::Value = toml::from_str(&text).expect("config must parse");
doc.get("tui")
.and_then(|t| t.get("theme"))
.and_then(|v| v.as_str())
.expect("tui.theme must be a string")
.to_string()
}
#[test]
fn a_persisted_theme_name_carries_no_quote_characters() {
let home = tempfile::tempdir().expect("tempdir");
with_home_override(home.path().to_path_buf(), || {
Config::write_key_string("tui", "theme", "dracula").expect("write");
assert_eq!(
stored_theme(),
"dracula",
"the stored value must be the name itself, or the boot lookup can never match it"
);
});
}
#[test]
fn resetting_clears_the_key_rather_than_storing_two_quotes() {
let home = tempfile::tempdir().expect("tempdir");
with_home_override(home.path().to_path_buf(), || {
Config::write_key_string("tui", "theme", "dracula").expect("write");
Config::write_key_string("tui", "theme", "").expect("reset");
let stored = stored_theme();
assert!(
stored.is_empty(),
"reset must leave an empty value so boot falls through to the default, \
not a two-character string of quotes: {stored:?}"
);
});
}
#[test]
fn a_config_poisoned_before_the_fix_still_resolves() {
assert_eq!(configured_name("\"dracula\""), "dracula");
assert_eq!(configured_name("dracula"), "dracula");
assert_eq!(configured_name(""), "");
}
#[test]
fn only_a_matching_quote_pair_is_stripped() {
assert_eq!(configured_name("\"dracula"), "\"dracula");
assert_eq!(configured_name("dracula\""), "dracula\"");
}