diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/web.rs | 55 |
1 files changed, 53 insertions, 2 deletions
diff --git a/tests/web.rs b/tests/web.rs index de5c1da..607f16d 100644 --- a/tests/web.rs +++ b/tests/web.rs @@ -3,11 +3,62 @@ #![cfg(target_arch = "wasm32")] extern crate wasm_bindgen_test; + use wasm_bindgen_test::*; +use genpass::generate; wasm_bindgen_test_configure!(run_in_browser); +const ATTEMPTS: usize = 5; + +#[wasm_bindgen_test] +fn generate_length() { + for x in (0..=100).step_by(5) { + let password = generate(x, true, true, true, true); + assert_eq!(x, password.len()) + } +} + +#[wasm_bindgen_test] +fn generate_not_upper_letters() { + let lower_charset = "abcdefghijklmnopqrstuvwxyz"; + for _ in 0..ATTEMPTS { + let password = generate(100, false, true, true, true); + for char in String::from(lower_charset).chars().into_iter() { + assert!(!password.contains(char)) + } + } +} + +#[wasm_bindgen_test] +fn generate_not_lower_letters() { + let upper_charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + for x in 0..ATTEMPTS { + let password = generate(x, true, false, true, true); + for char in String::from(upper_charset).chars().into_iter() { + assert!(!password.contains(char)) + } + } +} + +#[wasm_bindgen_test] +fn generate_not_number_letters() { + let upper_charset = "1234567890"; + for x in 0..ATTEMPTS { + let password = generate(x, true, true, false, true); + for char in String::from(upper_charset).chars().into_iter() { + assert!(!password.contains(char)) + } + } +} + #[wasm_bindgen_test] -fn pass() { - assert_eq!(1 + 1, 2); +fn generate_not_special_letters() { + let upper_charset = "!@#$%^&*()+{}[]"; + for x in 0..ATTEMPTS { + let password = generate(x, true, true, true, false); + for char in String::from(upper_charset).chars().into_iter() { + assert!(!password.contains(char)) + } + } } |