From e008a5b8340ebf2a9965f3ce953a954997e0bb54 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Thu, 21 Apr 2016 20:58:21 -0400 Subject: 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. --- src/tests.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'src/tests.rs') 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); +} -- cgit v1.2.3