Render the else block in sections if the path does not exist or if the path can't be walked.

This fixes all existing compliance tests.
This commit is contained in:
Tom Alexander
2020-05-03 15:29:02 -04:00
parent cc6dbefcdb
commit e957caf386
3 changed files with 52 additions and 36 deletions

View File

@@ -65,11 +65,7 @@ fn read_context_from_stdin() -> serde_json::Value {
.read_to_string(&mut buffer)
.expect("Failed to read stdin");
let parsed: serde_json::Value = serde_json::from_str(&buffer).expect("Failed to parse json");
match parsed {
serde_json::Value::Object(obj) => serde_json::value::Value::Object(obj),
_ => panic!("Expected context to be an object"),
}
serde_json::from_str(&buffer).expect("Failed to parse json")
}
impl ContextElement for serde_json::Value {}
@@ -112,7 +108,10 @@ impl Walkable for serde_json::Value {
segment: segment.to_string(),
elem: self,
}),
serde_json::Value::Array(_arr) => todo!("Arrays not supported yet"),
serde_json::Value::Array(_arr) => Err(RenderError::CantWalk {
segment: segment.to_string(),
elem: self,
}),
serde_json::Value::Object(obj) => {
obj.get(segment)
.map(|val| val as _)