fix: Add test for StyleVariableHolder

This commit is contained in:
heyrict
2020-04-25 22:56:02 +08:00
parent 444334ad20
commit 766732fe69
2 changed files with 14 additions and 0 deletions

View File

@ -81,6 +81,10 @@ impl<'a> StyleVariableHolder<Cow<'a, str>> for Vec<FormatElement<'a>> {
acc.extend(textgroup.style.get_style_variables()); acc.extend(textgroup.style.get_style_variables());
acc acc
} }
FormatElement::Positional(format) => {
acc.extend(format.get_style_variables());
acc
}
_ => acc, _ => acc,
}) })
} }

View File

@ -408,6 +408,16 @@ mod tests {
assert_eq!(variables, expected_variables); 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] #[test]
fn test_parse_error() { fn test_parse_error() {
// brackets without escape // brackets without escape