Expanded the test definition and fixed part of the problem.

This commit is contained in:
Tom Alexander 2020-05-03 13:21:02 -04:00
parent 7670db9259
commit b8c59f012b
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE

View File

@ -147,23 +147,26 @@ pub enum TemplateElement<'a> {
/// ///
/// These elements are always wrapped in curly braces /// These elements are always wrapped in curly braces
fn dust_tag(i: &str) -> IResult<&str, DustTag> { fn dust_tag(i: &str) -> IResult<&str, DustTag> {
alt(( preceded(
map(special, DustTag::DTSpecial), opt(span_end_of_line),
map(comment, DustTag::DTComment), alt((
map(reference, DustTag::DTReference), map(special, DustTag::DTSpecial),
conditional("{#", DustTag::DTSection), map(comment, DustTag::DTComment),
conditional("{?", DustTag::DTExists), map(reference, DustTag::DTReference),
conditional("{^", DustTag::DTNotExists), conditional("{#", DustTag::DTSection),
named_block("{+", DustTag::DTBlock), conditional("{?", DustTag::DTExists),
named_block("{<", DustTag::DTInlinePartial), conditional("{^", DustTag::DTNotExists),
partial("{>", DustTag::DTPartial), named_block("{+", DustTag::DTBlock),
parameterized_block("{@", "gte", DustTag::DTHelperGreaterThenOrEquals), named_block("{<", DustTag::DTInlinePartial),
parameterized_block("{@", "lte", DustTag::DTHelperLessThenOrEquals), partial("{>", DustTag::DTPartial),
parameterized_block("{@", "eq", DustTag::DTHelperEquals), parameterized_block("{@", "gte", DustTag::DTHelperGreaterThenOrEquals),
parameterized_block("{@", "ne", DustTag::DTHelperNotEquals), parameterized_block("{@", "lte", DustTag::DTHelperLessThenOrEquals),
parameterized_block("{@", "gt", DustTag::DTHelperGreaterThan), parameterized_block("{@", "eq", DustTag::DTHelperEquals),
parameterized_block("{@", "lt", DustTag::DTHelperLessThan), parameterized_block("{@", "ne", DustTag::DTHelperNotEquals),
))(i) parameterized_block("{@", "gt", DustTag::DTHelperGreaterThan),
parameterized_block("{@", "lt", DustTag::DTHelperLessThan),
)),
)(i)
} }
/// Special characters /// Special characters
@ -978,7 +981,7 @@ mod tests {
} }
#[test] #[test]
fn test_temp_full_document() { fn test_full_document_new_line_equality() {
assert_eq!( assert_eq!(
super::template( super::template(
"- simple -{~n} "- simple -{~n}
@ -996,7 +999,40 @@ mod tests {
TemplateElement::TESpan(Span { TemplateElement::TESpan(Span {
contents: vec!["- simple -"] contents: vec!["- simple -"]
}), }),
TemplateElement::TETag(DustTag::DTSpecial(Special::NewLine)) TemplateElement::TETag(DustTag::DTSpecial(Special::NewLine)),
TemplateElement::TETag(DustTag::DTSection(Container {
path: Path {
keys: vec!["names"]
},
contents: Some(Body {
elements: vec![TemplateElement::TETag(DustTag::DTReference(
Reference {
path: Path { keys: vec![] },
filters: vec![]
}
))]
}),
else_contents: None,
})),
TemplateElement::TETag(DustTag::DTSpecial(Special::NewLine)),
TemplateElement::TESpan(Span {
contents: vec!["- new lines -"]
}),
TemplateElement::TETag(DustTag::DTSpecial(Special::NewLine)),
TemplateElement::TETag(DustTag::DTSection(Container {
path: Path {
keys: vec!["names"]
},
contents: Some(Body {
elements: vec![TemplateElement::TETag(DustTag::DTReference(
Reference {
path: Path { keys: vec![] },
filters: vec![]
}
))]
}),
else_contents: None,
})),
] ]
} }
} }