Enable setting record keys values when record is NONE

This commit is contained in:
Tobie Morgan Hitchcock 2022-02-09 08:49:08 +00:00
parent 5e0e144acb
commit 9e50db40d8

View file

@ -66,6 +66,16 @@ impl Value {
} }
_ => Ok(()), _ => Ok(()),
}, },
// Current path part is empty
Value::Null => {
*self = Value::base();
self.set(ctx, opt, exe, path, val).await
}
// Current path part is empty
Value::None => {
*self = Value::base();
self.set(ctx, opt, exe, path, val).await
}
// Ignore everything else // Ignore everything else
_ => Ok(()), _ => Ok(()),
}, },
@ -95,6 +105,26 @@ mod tests {
assert_eq!(res, val); assert_eq!(res, val);
} }
#[tokio::test]
async fn set_empty() {
let (ctx, opt, exe) = mock();
let idi = Idiom::parse("test");
let mut val = Value::None;
let res = Value::parse("{ test: 999 }");
val.set(&ctx, &opt, &exe, &idi, Value::from(999)).await.unwrap();
assert_eq!(res, val);
}
#[tokio::test]
async fn set_blank() {
let (ctx, opt, exe) = mock();
let idi = Idiom::parse("test.something");
let mut val = Value::None;
let res = Value::parse("{ test: { something: 999 } }");
val.set(&ctx, &opt, &exe, &idi, Value::from(999)).await.unwrap();
assert_eq!(res, val);
}
#[tokio::test] #[tokio::test]
async fn set_reset() { async fn set_reset() {
let (ctx, opt, exe) = mock(); let (ctx, opt, exe) = mock();
@ -115,6 +145,16 @@ mod tests {
assert_eq!(res, val); assert_eq!(res, val);
} }
#[tokio::test]
async fn set_allow() {
let (ctx, opt, exe) = mock();
let idi = Idiom::parse("test.something.allow");
let mut val = Value::parse("{ test: { other: null } }");
let res = Value::parse("{ test: { other: null, something: { allow: 999 } } }");
val.set(&ctx, &opt, &exe, &idi, Value::from(999)).await.unwrap();
assert_eq!(res, val);
}
#[tokio::test] #[tokio::test]
async fn set_wrong() { async fn set_wrong() {
let (ctx, opt, exe) = mock(); let (ctx, opt, exe) = mock();