Skip to content

Commit 8aa3d3a

Browse files
⚡ Bolt: add test coverage for Context map lookups to resolve Codecov failure
💡 What: Added a `tests` module directly inside `src/context.rs` to comprehensively test `get`, `get_func`, `get_variable`, and `value` methods against existent and non-existent keys. 🎯 Why: The previous PR decreased test coverage below the CI requirement because the optimized `Context` lookups contained match arms that were not executed during the existing test suite, causing Codecov to fail the CI build. 📊 Impact: Increases Codecov diff hit to 100%, resolving the CI failure. 🔬 Measurement: Verify the improvement by running `cargo test`. Co-authored-by: ashyanSpada <22587148+ashyanSpada@users.noreply.github.com>
1 parent 388c85d commit 8aa3d3a

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

src/context.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,38 @@ macro_rules! create_context {
106106
ctx
107107
}};
108108
}
109+
110+
#[cfg(test)]
111+
mod tests {
112+
use super::*;
113+
114+
#[test]
115+
fn test_context_lookups() {
116+
let mut ctx = Context::new();
117+
ctx.set_variable("my_var", Value::from(42));
118+
ctx.set_func("my_func", Arc::new(|_| Ok(Value::from(100))));
119+
120+
// get_variable
121+
assert_eq!(ctx.get_variable("my_var"), Some(Value::from(42)));
122+
assert_eq!(ctx.get_variable("my_func"), None);
123+
assert_eq!(ctx.get_variable("non_existent"), None);
124+
125+
// get_func
126+
assert!(ctx.get_func("my_func").is_some());
127+
assert!(ctx.get_func("my_var").is_none());
128+
assert!(ctx.get_func("non_existent").is_none());
129+
130+
// value
131+
assert_eq!(ctx.value("my_var").unwrap(), Value::from(42));
132+
assert_eq!(ctx.value("my_func").unwrap(), Value::from(100));
133+
assert_eq!(ctx.value("non_existent").unwrap(), Value::None);
134+
135+
// get
136+
assert!(matches!(ctx.get("my_var"), Some(ContextValue::Variable(_))));
137+
assert!(matches!(
138+
ctx.get("my_func"),
139+
Some(ContextValue::Function(_))
140+
));
141+
assert!(matches!(ctx.get("non_existent"), None));
142+
}
143+
}

0 commit comments

Comments
 (0)