From c97197509170982a1152d8502387a5eab0680210 Mon Sep 17 00:00:00 2001 From: Hunter Praska Date: Sat, 22 Jul 2017 02:19:40 -0500 Subject: [PATCH 1/2] Fixes a bug with iterating over the current value --- libs/bart_derive/src/scanner.rs | 2 +- tests/iteration.rs | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/libs/bart_derive/src/scanner.rs b/libs/bart_derive/src/scanner.rs index 2fbbb10..c6ec318 100644 --- a/libs/bart_derive/src/scanner.rs +++ b/libs/bart_derive/src/scanner.rs @@ -101,7 +101,7 @@ fn section_opener<'a>(input: &'a str) -> Result, Error> { let (input, tail) = if input.ends_with('?') { (&input[..input.len()-1], Tail::Conditional) - } else if input.ends_with('.') { + } else if input.ends_with('.') && input.len() > 1 { (&input[..input.len()-1], Tail::Scope) } else { (input, Tail::None) diff --git a/tests/iteration.rs b/tests/iteration.rs index d37fdb3..7663c20 100644 --- a/tests/iteration.rs +++ b/tests/iteration.rs @@ -62,3 +62,14 @@ fn it_can_iterate_function() { Test { a: 1, b: 2, c: 3 }.to_string() ); } + +#[test] +fn it_can_iterate_dot() { + #[derive(BartDisplay)] + #[template_string="{{#opt}}{{#.}}{{.}}{{/.}}{{/opt}}"] + struct Test { opt: Option> } + assert_eq!( + "123", + Test { opt: Some(vec![1, 2, 3]) }.to_string() + ); +} From 5d43b98d3d795a883202174bd6c0e8d46a4b0b46 Mon Sep 17 00:00:00 2001 From: Hunter Praska Date: Sat, 22 Jul 2017 19:11:23 -0500 Subject: [PATCH 2/2] Add scanner test --- libs/bart_derive/src/scanner.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/libs/bart_derive/src/scanner.rs b/libs/bart_derive/src/scanner.rs index c6ec318..1d817b0 100644 --- a/libs/bart_derive/src/scanner.rs +++ b/libs/bart_derive/src/scanner.rs @@ -262,6 +262,15 @@ mod tests { ); } + #[test] + fn bart_tag_matches_iteration_section_opener_dot() { + assert_eq!( + Ok(("", Token::SectionOpener(SectionType::Iteration, name(".").unwrap().1))), + bart_tag("{{#.}}") + ); + } + + #[test] fn bart_tag_matches_negative_iteration_section_opener() { assert_eq!(