From 766732fe697df947538fe12ca92a8eb8e7bfea3e Mon Sep 17 00:00:00 2001 From: heyrict Date: Sat, 25 Apr 2020 22:56:02 +0800 Subject: [PATCH] fix: Add test for StyleVariableHolder --- src/formatter/model.rs | 4 ++++ src/formatter/string_formatter.rs | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/formatter/model.rs b/src/formatter/model.rs index 27839400f..bc64d57d7 100644 --- a/src/formatter/model.rs +++ b/src/formatter/model.rs @@ -81,6 +81,10 @@ impl<'a> StyleVariableHolder> for Vec> { acc.extend(textgroup.style.get_style_variables()); acc } + FormatElement::Positional(format) => { + acc.extend(format.get_style_variables()); + acc + } _ => acc, }) } diff --git a/src/formatter/string_formatter.rs b/src/formatter/string_formatter.rs index e7977cbdc..a58966219 100644 --- a/src/formatter/string_formatter.rs +++ b/src/formatter/string_formatter.rs @@ -408,6 +408,16 @@ mod tests { assert_eq!(variables, expected_variables); } + #[test] + fn test_style_variable_holder() { + const FORMAT_STR: &str = "($a [($b) $c](none $s)) $d [t]($t)"; + let expected_variables = BTreeSet::from_iter(vec!["s", "t"].into_iter().map(String::from)); + + let formatter = StringFormatter::new(FORMAT_STR).unwrap().map(empty_mapper); + let variables = formatter.get_style_variables(); + assert_eq!(variables, expected_variables); + } + #[test] fn test_parse_error() { // brackets without escape