use rustc_hash::FxHashMap;
use serde::Deserialize;
#[derive(Debug, Clone, Deserialize, Default)]
pub struct ContextConfig {
#[serde(default)]
pub files: FxHashMap<String, String>,
pub session: Option<String>,
}
#[cfg(test)]
mod tests {
use super::*;
use crate::serde_yaml;
#[test]
fn test_context_config_default() {
let config = ContextConfig::default();
assert!(config.files.is_empty());
assert!(config.session.is_none());
}
#[test]
fn test_context_config_deserialize_empty() {
let yaml = "";
let config: ContextConfig = serde_yaml::from_str(yaml).unwrap_or_default();
assert!(config.files.is_empty());
}
#[test]
fn test_context_config_deserialize_files() {
let yaml = r#"
files:
brand: ./context/brand.md
persona: ./context/persona.json
"#;
let config: ContextConfig = serde_yaml::from_str(yaml).unwrap();
assert_eq!(config.files.len(), 2);
assert_eq!(
config.files.get("brand"),
Some(&"./context/brand.md".to_string())
);
assert_eq!(
config.files.get("persona"),
Some(&"./context/persona.json".to_string())
);
}
#[test]
fn test_context_config_deserialize_session() {
let yaml = r#"
session: .nika/sessions/prev.json
"#;
let config: ContextConfig = serde_yaml::from_str(yaml).unwrap();
assert_eq!(config.session, Some(".nika/sessions/prev.json".to_string()));
}
#[test]
fn test_context_config_deserialize_full() {
let yaml = r#"
files:
brand: ./context/brand.md
examples: ./context/*.md
session: .nika/sessions/prev.json
"#;
let config: ContextConfig = serde_yaml::from_str(yaml).unwrap();
assert_eq!(config.files.len(), 2);
assert!(config.files.contains_key("brand"));
assert!(config.files.contains_key("examples"));
assert!(config.session.is_some());
}
#[test]
fn test_context_config_glob_pattern() {
let yaml = r#"
files:
examples: ./context/*.md
"#;
let config: ContextConfig = serde_yaml::from_str(yaml).unwrap();
assert!(config.files.get("examples").unwrap().contains('*'));
}
}