diff options
| author | Teddy Wing | 2016-04-22 08:03:47 -0400 | 
|---|---|---|
| committer | Teddy Wing | 2016-04-22 08:03:47 -0400 | 
| commit | 483b297db9604f7c1d8ae63e6ab4aadec70ce1cb (patch) | |
| tree | c98380a71b6e7dbd7a732e5187cc6b11d3c378b1 /src/tests.rs | |
| parent | bf3b4fa20746f074ebbdbe1b0d45a24da69837f5 (diff) | |
| download | mutt-alias-auto-add-483b297db9604f7c1d8ae63e6ab4aadec70ce1cb.tar.bz2 | |
Add `Alias#write_to_file`
Writes the alias to a given file.
Thinking I should modify the test so that we can know it works with
multiple alias lines.
Diffstat (limited to 'src/tests.rs')
| -rw-r--r-- | src/tests.rs | 20 | 
1 files changed, 20 insertions, 0 deletions
| diff --git a/src/tests.rs b/src/tests.rs index b3a172c..1034bc6 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -1,3 +1,6 @@ +use std::fs::{self, File}; +use std::io::Read; +  use super::{Alias, AliasSearchError, find_alias_in_file};  #[test] @@ -120,3 +123,20 @@ fn update_alias_id_increments_alias() {      assert_eq!("hooves-derpy-5", &alias.alias);  } + + +#[test] +fn alias_write_to_file_must_write_given_alias_to_file() { +    let alias = update_alias_id_sample_alias(); + +    let test_file = "./testdata/write_to_file"; +    File::create(test_file).unwrap(); +    alias.write_to_file(test_file).unwrap(); + +    let mut f = File::open(test_file).unwrap(); +    let mut file_contents = String::new(); +    f.read_to_string(&mut file_contents).unwrap(); +    fs::remove_file(test_file).unwrap(); + +    assert_eq!(alias.to_string(), file_contents); +} | 
