aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTeddy Wing2016-04-06 01:12:58 -0400
committerTeddy Wing2016-04-06 01:12:58 -0400
commit02688030cb7b1de5c63732b8b820017391bfd2a0 (patch)
treea4723464e79c07d7e4c13d7509b51dc9b8b03637 /src
parent9b178d48e0aa218bdb2fccaf46f2ce40c3148c7e (diff)
downloadmutt-alias-auto-add-02688030cb7b1de5c63732b8b820017391bfd2a0.tar.bz2
Add a couple tests for `build_alias`
Create a new `tests` module. This lives in its own file. Not sure if this is idiomatic Rust, but I prefer the idea of my tests living in a different file from my code. This module gets included in `main.rs`. We `use` `build_alias` directly because it's currently a private function, so doing `use super::*` didn't import it. Not sure if I should be making it a public function in order to mitigate this. Add a couple of variant test cases to check the string transformation that this function should be doing.
Diffstat (limited to 'src')
-rw-r--r--src/main.rs3
-rw-r--r--src/tests.rs14
2 files changed, 17 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs
index 3e4a343..92ea8e1 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,5 +1,8 @@
use std::io::{self, BufRead};
+#[cfg(test)]
+mod tests;
+
fn handle_alias(s: &str) {
let alias = build_alias(s);
}
diff --git a/src/tests.rs b/src/tests.rs
new file mode 100644
index 0000000..20bbcc5
--- /dev/null
+++ b/src/tests.rs
@@ -0,0 +1,14 @@
+use super::build_alias;
+
+#[test]
+fn test_build_alias() {
+ assert_eq!(
+ "alias farnsworth-hubert Hubert Farnsworth <professor@planetexpress.com>",
+ build_alias("From: Hubert Farnsworth <professor@planetexpress.com>")
+ );
+
+ assert_eq!(
+ "alias lab-harvard Harvard Innovation Lab <noreply@eventbrite.com>",
+ build_alias("From: Harvard Innovation Lab <noreply@eventbrite.com>")
+ );
+}