diff options
| author | Teddy Wing | 2016-04-21 20:58:21 -0400 |
|---|---|---|
| committer | Teddy Wing | 2016-04-21 20:59:38 -0400 |
| commit | e008a5b8340ebf2a9965f3ce953a954997e0bb54 (patch) | |
| tree | c0594a7254fadc41bf062f640ef9c475c1b39512 /src | |
| parent | 3a5b7dd83642f5ab93aa70b612dcdbbc10e70935 (diff) | |
| download | mutt-alias-auto-add-e008a5b8340ebf2a9965f3ce953a954997e0bb54.tar.bz2 | |
Add Alias#update_alias_id
This function takes a list of aliases and updates the current `Alias`'s
alias using an auto-incremented numeric id.
Not happy with the repetition in the tests. Need to figure out if
there's a way to abstract that.
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.rs | 6 | ||||
| -rw-r--r-- | src/tests.rs | 32 |
2 files changed, 38 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs index fdeab31..89deb49 100644 --- a/src/main.rs +++ b/src/main.rs @@ -48,6 +48,12 @@ impl Alias { format!("alias {} {} {}", self.alias, self.name, self.email) } } + + fn update_alias_id(&mut self, similar_aliases: Vec<String>) { + if !similar_aliases.is_empty() { + self.alias = format!("{}-{}", self.alias, similar_aliases.len() + 1); + } + } } fn handle_alias(s: &str) { diff --git a/src/tests.rs b/src/tests.rs index 0dc3901..f877408 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -88,3 +88,35 @@ fn find_alias_in_file_finds_a_match() { ) ); } + + +#[test] +fn update_alias_id_does_nothing_given_an_empty_vector() { + let alias_identifier = "hooves-derpy"; + let mut alias = Alias { + alias: alias_identifier.to_owned(), + name: "Derpy Hooves".to_owned(), + email: "derpyhooves@postmaster.pv".to_owned() + }; + alias.update_alias_id(vec![]); + + assert_eq!(alias_identifier, &alias.alias); +} + +#[test] +fn update_alias_id_increments_alias() { + let alias_identifier = "hooves-derpy"; + let mut alias = Alias { + alias: alias_identifier.to_owned(), + name: "Derpy Hooves".to_owned(), + email: "derpyhooves@postmaster.pv".to_owned() + }; + alias.update_alias_id(vec![ + "hooves-derpy".to_owned(), + "hooves-derpy-2".to_owned(), + "hooves-derpy-3".to_owned(), + "hooves-derpy-4".to_owned() + ]); + + assert_eq!("hooves-derpy-5", &alias.alias); +} |
