aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorgabrielgio <gabriel.giovanini@pm.me>2022-03-25 22:43:47 +0100
committergabrielgio <gabriel.giovanini@pm.me>2022-03-25 22:43:47 +0100
commit860594ffb7c013e5f4257bd615472e08c8c685c6 (patch)
treea5a46af59046ca1c3a18a1c5a7d93c91024c22b3 /src
parentb92dd0a4c59287b661759d3cdcd6f62e1afcd815 (diff)
downloadgenpass-860594ffb7c013e5f4257bd615472e08c8c685c6.tar.gz
genpass-860594ffb7c013e5f4257bd615472e08c8c685c6.tar.bz2
genpass-860594ffb7c013e5f4257bd615472e08c8c685c6.zip
ref: Add test for edge case
Add test case for when you call with 0 length or no option (upper case, lower case, number and special).
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/lib.rs b/src/lib.rs
index a4fa227..a19cbfa 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -17,6 +17,10 @@ extern {
#[wasm_bindgen]
pub fn generate(len: usize, lower: bool, upper: bool, number: bool, special: bool) -> String {
+ if len == 0 ||!lower && !upper && !number && !special {
+ return "".to_string();
+ }
+
let mut upper_charset: Vec<char> = String::from("ABCDEFGHIJKLMNOPQRSTUVWXYZ").chars().collect();
let mut lower_charset: Vec<char> = String::from("abcdefghijklmnopqrstuvwxyz").chars().collect();
let mut number_charset: Vec<char> = String::from("1234567890").chars().collect();
@@ -41,7 +45,6 @@ pub fn generate(len: usize, lower: bool, upper: bool, number: bool, special: boo
result.append(&mut special_charset);
}
-
(0..len)
.map(|_| {
let idx = rng.gen_range(0..result.len());