aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitlab-ci.yml2
-rw-r--r--less7
-rw-r--r--src/lib.rs5
-rw-r--r--tests/web.rs12
4 files changed, 25 insertions, 1 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 176339b..0cb348c 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -13,6 +13,8 @@ test:
- make test
pages:
+ needs:
+ - test
before_script:
- export PATH="$PATH:$HOME/.cargo/bin"
- apk add npm make curl build-base
diff --git a/less b/less
new file mode 100644
index 0000000..5ce7d2e
--- /dev/null
+++ b/less
@@ -0,0 +1,7 @@
+wasm-pack test --headless --firefox
+no tests to run!
+ Set timeout to 20 seconds...
+Executing bindgen... Running headless tests in Firefox on `http://127.0.0.1:42097/`
+Try find `webdriver.json` for configure browser's capabilities:
+Not found
+Starting new webdriver session... \ No newline at end of file
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());
diff --git a/tests/web.rs b/tests/web.rs
index 607f16d..b83608f 100644
--- a/tests/web.rs
+++ b/tests/web.rs
@@ -62,3 +62,15 @@ fn generate_not_special_letters() {
}
}
}
+
+#[wasm_bindgen_test]
+fn generate_0_len() {
+ let password = generate(0, true, true, true, true);
+ assert_eq!(0, password.len())
+}
+
+#[wasm_bindgen_test]
+fn generate_no_letters() {
+ let password = generate(100, false, false, false, false);
+ assert_eq!(0, password.len())
+}