aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorgabrielgio <gabriel.giovanini@pm.me>2022-03-25 22:28:51 +0100
committergabrielgio <gabriel.giovanini@pm.me>2022-03-25 22:28:51 +0100
commitb92dd0a4c59287b661759d3cdcd6f62e1afcd815 (patch)
tree934350cd4d080907337238817f75f55e964f77f2 /tests
parent34af714c51173075d3a0ac7148ce60334d248aba (diff)
downloadgenpass-b92dd0a4c59287b661759d3cdcd6f62e1afcd815.tar.gz
genpass-b92dd0a4c59287b661759d3cdcd6f62e1afcd815.tar.bz2
genpass-b92dd0a4c59287b661759d3cdcd6f62e1afcd815.zip
feat: Add test to generate function
Add testing for `generate` rust function. That function is pretty much the whole bussiness logic of the application and as far as I can see the only one worth testing.
Diffstat (limited to 'tests')
-rw-r--r--tests/web.rs55
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))
+ }
+ }
}