summaryrefslogtreecommitdiff
path: root/src/codegen.rs
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2020-12-10 10:22:02 +0000
committerDaniel Silverstone <dsilvers@digital-scurf.org>2020-12-10 10:22:02 +0000
commita639adc8e76e2b0c81f834c3f9b76658c0e4d81e (patch)
treec9c9cf1f4b46852790f8a2f246bf9a1587e54ed7 /src/codegen.rs
parentcded5bf666846309fa745ca761940df0042bb5b4 (diff)
downloadsubplot-a639adc8e76e2b0c81f834c3f9b76658c0e4d81e.tar.gz
codegen: Add tests for new filters
Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
Diffstat (limited to 'src/codegen.rs')
-rw-r--r--src/codegen.rs37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/codegen.rs b/src/codegen.rs
index f18fcc0..19a84e7 100644
--- a/src/codegen.rs
+++ b/src/codegen.rs
@@ -143,3 +143,40 @@ impl Func {
}
}
}
+
+#[cfg(test)]
+mod test {
+ use std::collections::HashMap;
+ use tera::Value;
+ #[test]
+ fn verify_commentsafe_filter() {
+ static GOOD_CASES: &[(&str, &str)] = &[
+ ("", ""), // Empty
+ ("hello world", "hello world"), // basic strings pass through
+ ("Capitalised Words", "Capitalised Words"), // capitals are OK
+ ("multiple\nlines\rblah", "multiple lines blah"), // line breaks are made into spaces
+ ];
+ for (input, output) in GOOD_CASES.iter().copied() {
+ let input = Value::from(input);
+ let output = Value::from(output);
+ let empty = HashMap::new();
+ assert_eq!(super::commentsafe(&input, &empty).ok(), Some(output));
+ }
+ }
+
+ #[test]
+ fn verify_name_slugification() {
+ static GOOD_CASES: &[(&str, &str)] = &[
+ ("foobar", "foobar"), // Simple words pass through
+ ("FooBar", "foobar"), // Capital letters are lowercased
+ ("Motörhead", "mot_rhead"), // Non-ascii characters are changed for underscores
+ ("foo bar", "foo_bar"), // As is whitespace etc.
+ ];
+ for (input, output) in GOOD_CASES.iter().copied() {
+ let input = Value::from(input);
+ let output = Value::from(output);
+ let empty = HashMap::new();
+ assert_eq!(super::nameslug(&input, &empty).ok(), Some(output));
+ }
+ }
+}