From 16124e890e34d64616d398a2d13398c9407019b6 Mon Sep 17 00:00:00 2001 From: Bat Date: Wed, 18 Jul 2018 18:35:50 +0200 Subject: [PATCH] Add some test for mentions --- plume-common/src/utils.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/plume-common/src/utils.rs b/plume-common/src/utils.rs index 8b14959..364a391 100644 --- a/plume-common/src/utils.rs +++ b/plume-common/src/utils.rs @@ -68,3 +68,26 @@ pub fn md_to_html(md: &str) -> (String, Vec) { html::push_html(&mut buf, parser); (buf, mentions.collect()) } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_mentions() { + let tests = vec![ + ("nothing", vec![]), + ("@mention", vec!["mention"]), + ("@mention@instance.tld", vec!["mention@instance.tld"]), + ("@many @mentions", vec!["many", "mentions"]), + ("@start with a mentions", vec!["start"]), + ("mention at @end", vec!["end"]), + ("between parenthesis (@test)", vec!["test"]), + ("with some punctuation @test!", vec!["test"]), + ]; + + for (md, mentions) in tests { + assert_eq!(md_to_html(md).1, mentions.into_iter().map(|s| s.to_string()).collect::>()); + } + } +}