From 41e4874d75e67e0a75eefa40e9056fcb97b1e86b Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sat, 16 May 2020 15:22:48 -0400 Subject: [PATCH] Add a check to the equality helper to mark identical paths as equal. --- js/run_compliance_suite.bash | 2 +- src/renderer/renderer.rs | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/js/run_compliance_suite.bash b/js/run_compliance_suite.bash index 4423242..a13d025 100755 --- a/js/run_compliance_suite.bash +++ b/js/run_compliance_suite.bash @@ -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 diff --git a/src/renderer/renderer.rs b/src/renderer/renderer.rs index addfa85..712ad63 100644 --- a/src/renderer/renderer.rs +++ b/src/renderer/renderer.rs @@ -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(¶m_map) { + return match ¶meterized_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)]