Have greater than helper very close to correct. Just need to make it compare arrays of scalars.

This commit is contained in:
Tom Alexander 2020-05-16 16:24:36 -04:00
parent 48e35c54bb
commit 6758d515f1
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
3 changed files with 65 additions and 0 deletions
js/test_cases/helpers_gt
src/renderer

View File

@ -17,3 +17,18 @@ greater than or equals to
All comparisons between non-matching types (for example, int vs string) appear to render the main block.
Comparisons between non-scalar types (like arrays) appears to render the main block
less than
---------
All comparisons between non-matching types (for example, int vs string) appear to render the else block.
Comparisons between non-scalar types (like arrays) appears to render the else block
less than or equal to
---------------------
All comparisons between non-matching types (for example, int vs string) appear to render the main block.
Comparisons between non-scalar types (like arrays) appears to render the main block

View File

@ -20,7 +20,10 @@ beta is {beta}{~n}
{@gt key="a" value="]"}"a" is greater than "]"{:else}"a" is less than or equal to "]"{/gt}{~n}
{@gt key="a" value="A"}"a" is greater than "A"{:else}"a" is less than or equal to "A"{/gt}{~n}
{@gt key="a" value="}"}"a" is greater than "}"{:else}"a" is less than or equal to "}"{/gt}{~n}
{!
Commented out because unicode not working in rust implementation yet
{@gt key="☃" value="☄"}"☃" is greater than "☄"{:else}"☃" is less than or equal to "☄"{/gt}{~n}
!}
{@gt key=true_value value=false_value}true is greater than false{:else}true is less than or equal to false{/gt}{~n}
{@gt key=array_lower value=array_higher}[3,5,7] is greater than [8,9]{:else}[3,5,7] is less than or equal to [8,9]{/gt}{~n}
{@gt key=array_higher value=array_lower}[8,9] is greater than [3,5,7]{:else}[8,9] is less than or equal to [3,5,7]{/gt}{~n}

View File

@ -340,6 +340,53 @@ impl<'a> DustRenderer<'a> {
.iter()
.map(|pair: &KVPair<'a>| (pair.key, &pair.value))
.collect();
let left_side: Result<&dyn ContextElement, WalkError> = match param_map.get("key") {
None => return Ok("".to_owned()),
Some(rval) => match rval {
RValue::RVString(text) => Ok(text),
RValue::RVPath(path) => walk_path(breadcrumbs, &path.keys),
RValue::RVPositiveInteger(num) => Ok(num),
},
};
let right_side: Result<&dyn ContextElement, WalkError> =
match param_map.get("value") {
None => Err(WalkError::CantWalk),
Some(rval) => match rval {
RValue::RVString(text) => Ok(text),
RValue::RVPath(path) => walk_path(breadcrumbs, &path.keys),
RValue::RVPositiveInteger(num) => Ok(num),
},
};
match (left_side, right_side) {
(Err(_), _) | (_, Err(_)) => match &parameterized_block.else_contents {
None => return Ok("".to_owned()),
Some(body) => {
let rendered_content = self.render_body(body, breadcrumbs, blocks)?;
return Ok(rendered_content);
}
},
(Ok(left_side_unwrapped), Ok(right_side_unwrapped)) => {
if left_side_unwrapped > right_side_unwrapped {
match &parameterized_block.contents {
None => return Ok("".to_owned()),
Some(body) => {
let rendered_content =
self.render_body(body, breadcrumbs, blocks)?;
return Ok(rendered_content);
}
}
} else {
match &parameterized_block.else_contents {
None => return Ok("".to_owned()),
Some(body) => {
let rendered_content =
self.render_body(body, breadcrumbs, blocks)?;
return Ok(rendered_content);
}
}
}
}
}
}
_ => (), // TODO: Implement the rest
}