Add that check to the not-equals helper and update the json value implementation to mark all non-scalars as not-equals.
This commit is contained in:
parent
41e4874d75
commit
7d4cb14530
10
src/bin.rs
10
src/bin.rs
@ -145,7 +145,15 @@ impl CompareContextElement for serde_json::Value {
|
|||||||
// Handle other serde_json::Value
|
// Handle other serde_json::Value
|
||||||
match other.to_any().downcast_ref::<Self>() {
|
match other.to_any().downcast_ref::<Self>() {
|
||||||
None => (),
|
None => (),
|
||||||
Some(other_json_value) => return self == other_json_value,
|
Some(other_json_value) => match (self, other_json_value) {
|
||||||
|
// Non-scalar values not caught in the renderer by the
|
||||||
|
// identical-path shortcut are always not equal.
|
||||||
|
(serde_json::Value::Array(_), _)
|
||||||
|
| (_, serde_json::Value::Array(_))
|
||||||
|
| (serde_json::Value::Object(_), _)
|
||||||
|
| (_, serde_json::Value::Object(_)) => return false,
|
||||||
|
_ => return self == other_json_value,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
// Handle string literals
|
// Handle string literals
|
||||||
match other.to_any().downcast_ref::<String>() {
|
match other.to_any().downcast_ref::<String>() {
|
||||||
|
@ -285,6 +285,20 @@ impl<'a> DustRenderer<'a> {
|
|||||||
.iter()
|
.iter()
|
||||||
.map(|pair: &KVPair<'a>| (pair.key, &pair.value))
|
.map(|pair: &KVPair<'a>| (pair.key, &pair.value))
|
||||||
.collect();
|
.collect();
|
||||||
|
// Special case: when comparing two RVPaths, if the
|
||||||
|
// path is equal then dust assumes the values are
|
||||||
|
// equal (otherwise, non-scalar values are
|
||||||
|
// automatically not equal)
|
||||||
|
if Self::are_paths_identical(¶m_map) {
|
||||||
|
return match ¶meterized_block.else_contents {
|
||||||
|
None => Ok("".to_owned()),
|
||||||
|
Some(body) => {
|
||||||
|
let rendered_content = self.render_body(body, breadcrumbs, blocks)?;
|
||||||
|
Ok(rendered_content)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
let left_side: Result<&dyn ContextElement, WalkError> = match param_map.get("key") {
|
let left_side: Result<&dyn ContextElement, WalkError> = match param_map.get("key") {
|
||||||
None => return Ok("".to_owned()),
|
None => return Ok("".to_owned()),
|
||||||
Some(rval) => match rval {
|
Some(rval) => match rval {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user