use std::collections::HashMap;
use crate::types::Value;
pub struct Context {
pub vars: HashMap<String, Value>,
}
impl Context {
pub fn new(vars: HashMap<String, Value>) -> Self {
let normalized = vars.into_iter()
.map(|(k, v)| (k.to_uppercase(), v))
.collect();
Self { vars: normalized }
}
pub fn empty() -> Self {
Self { vars: HashMap::new() }
}
pub fn get(&self, name: &str) -> Value {
self.vars
.get(&name.to_uppercase())
.cloned()
.unwrap_or(Value::Empty)
}
pub fn set(&mut self, name: String, value: Value) -> Option<Value> {
self.vars.insert(name.to_uppercase(), value)
}
pub fn remove(&mut self, name: &str) {
self.vars.remove(&name.to_uppercase());
}
}
#[cfg(test)]
mod tests;