Add a check to the equality helper to mark identical paths as equal.

This commit is contained in:
Tom Alexander 2020-05-16 15:22:48 -04:00
parent d751df6fd5
commit 41e4874d75
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
2 changed files with 28 additions and 1 deletions

View File

@ -38,7 +38,7 @@ while read -r test_group; do
else
echo "$test_group_name::$test_case_name FAILED"
if [ $show_diff -eq 1 ]; then
diff --label "dustjs-linked" --label "duster" <(xargs -a <(find "$test_group" -maxdepth 1 -mindepth 1 -type f -name 'main.dust'; find "$test_group" -maxdepth 1 -mindepth 1 -type f -name '*.dust' ! -name 'main.dust' | sort) node "$DIR/dustjs_shim.js" < "$test_case" 2>/dev/null ) <(xargs -a <(find "$test_group" -maxdepth 1 -mindepth 1 -type f -name 'main.dust'; find "$test_group" -maxdepth 1 -mindepth 1 -type f -name '*.dust' ! -name 'main.dust' | sort) "$DIR/../target/debug/duster-cli" < "$test_case" 2>/dev/null )
diff --label "dustjs-linkedin" --label "duster" <(xargs -a <(find "$test_group" -maxdepth 1 -mindepth 1 -type f -name 'main.dust'; find "$test_group" -maxdepth 1 -mindepth 1 -type f -name '*.dust' ! -name 'main.dust' | sort) node "$DIR/dustjs_shim.js" < "$test_case" 2>/dev/null ) <(xargs -a <(find "$test_group" -maxdepth 1 -mindepth 1 -type f -name 'main.dust'; find "$test_group" -maxdepth 1 -mindepth 1 -type f -name '*.dust' ! -name 'main.dust' | sort) "$DIR/../target/debug/duster-cli" < "$test_case" 2>/dev/null )
fi
exit 1
fi

View File

@ -230,6 +230,20 @@ impl<'a> DustRenderer<'a> {
.iter()
.map(|pair: &KVPair<'a>| (pair.key, &pair.value))
.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(&param_map) {
return match &parameterized_block.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") {
None => return Ok("".to_owned()),
Some(rval) => match rval {
@ -324,6 +338,19 @@ impl<'a> DustRenderer<'a> {
Ok(walk_target) => walk_target.get_loop_elements(),
}
}
fn are_paths_identical<'b>(param_map: &HashMap<&str, &RValue<'b>>) -> bool {
match (param_map.get("key"), param_map.get("value")) {
(None, _) => false,
(_, None) => false,
(Some(key_rval), Some(value_rval)) => match (key_rval, value_rval) {
(RValue::RVPath(key_path), RValue::RVPath(value_path)) => {
key_path.keys == value_path.keys
}
_ => false,
},
}
}
}
#[cfg(test)]