diff options
author | Andreas Grois <andi@grois.info> | 2023-01-19 22:14:49 +0100 |
---|---|---|
committer | Andreas Grois <andi@grois.info> | 2023-01-19 22:14:49 +0100 |
commit | 26b9bc316d8db76b7840f5598877590310a9f49f (patch) | |
tree | b30ca73f3f2b38a3ed019bea45df995f3b7f4202 /src/passwordmaker/mod.rs | |
parent | fb5bd1a86ff5b62e1272c8b66e4dd3d860b74e3f (diff) |
Add unit tests for prefix-password-suffix combine
Diffstat (limited to 'src/passwordmaker/mod.rs')
-rw-r--r-- | src/passwordmaker/mod.rs | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/passwordmaker/mod.rs b/src/passwordmaker/mod.rs index 405d469..db01a78 100644 --- a/src/passwordmaker/mod.rs +++ b/src/passwordmaker/mod.rs @@ -328,4 +328,29 @@ impl AlgoSelection { #[allow(clippy::cast_possible_truncation)] //clippy, stop complaining. Truncating is the very purpose of this function... fn yeet_upper_bytes(input : &str) -> impl Iterator<Item=u8> + Clone + '_ { input.encode_utf16().map(|wide_char| wide_char as u8) +} + +#[cfg(test)] +mod passwordmaker_tests { + use super::*; + + #[test] + fn test_combine_prefix_password_suffix(){ + let parameters = PasswordAssemblyParameters::from_public_parameters("prefi", "suffi", 15); + let result = combine_prefix_password_suffix(Grapheme::iter_from_str("passwo"), ¶meters); + assert_eq!(&result, "prefipasswsuffi"); + } + #[test] + fn test_combine_prefix_password_suffix_too_short(){ + let parameters = PasswordAssemblyParameters::from_public_parameters("prefi", "suffi", 8); + let result = combine_prefix_password_suffix(Grapheme::iter_from_str("passwo"), ¶meters); + assert_eq!(&result, "presuffi"); + } + + #[test] + fn test_yeet_upper_bytes(){ + let testinput = "€©ĦÆÆ"; + let result = yeet_upper_bytes(testinput).collect::<Vec<_>>(); + assert_eq!(result, vec![0xac,0xa9,0x26,0xc6,0xc6]); + } }
\ No newline at end of file |