use crate::testing::asserts::{*, assert_eq};
use super::*;
#[test]
fn empty() {
let ctx = Context::empty();
assert_eq!(ctx.name_count(), 0);
}
#[test]
fn default() {
assert_gt!(Context::new().name_count(), 0);
assert_gt!(Context::default().name_count(), 0);
}
#[test]
fn namespace_different_types() {
let mut ctx = Context::empty();
ctx.set(Ident::from("foo"), false);
assert_eq!(ctx.get("foo").unwrap(), &false.into());
ctx.set(Ident::from("bar"), 42);
assert_eq!(ctx.get(Ident::from("bar")).unwrap(), &42.into());
}
#[test]
fn namespace_hierarchy() {
let mut ctx = Context::empty();
ctx.set("foo", 4);
{
let mut child = ctx.child();
assert_eq!(child.resolve("foo").unwrap(), &4.into());
child.set("bar", 42);
assert_eq!(child.resolve("bar").unwrap(), &42.into());
child.set("foo", 13);
assert_eq!(child.resolve("foo").unwrap(), &13.into());
}
assert_eq!(ctx.resolve("foo").unwrap(), &4.into());
assert!(ctx.resolve("bar").is_err());
}