commit ad798de416108404d58bf5f8b56cc369107c6857
parent a025437fc654155dcf41ff6f8b907c269d24a6cd
Author: Yuval Langer <yuvallangerontheroad@gmail.com>
Date: Sun, 18 Sep 2022 18:38:26 +0300
Move tests into `/src/main.rs`. Bump version.
Diffstat:
4 files changed, 64 insertions(+), 72 deletions(-)
diff --git a/Cargo.lock b/Cargo.lock
@@ -10,7 +10,7 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "diceware"
-version = "0.5.1"
+version = "0.5.2"
dependencies = [
"getopts",
"rand",
diff --git a/Cargo.toml b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "diceware"
-version = "0.5.1"
+version = "0.5.2"
authors = ["Yuval Langer <yuvallangerontheroad@gmail.com>"]
license = "AGPL-3.0"
repository = "https://gitlab.com/yuvallanger/rusty-diceware"
diff --git a/src/main.rs b/src/main.rs
@@ -283,3 +283,65 @@ fn main() {
};
};
}
+
+macro_rules! create_test {
+ ( $wordlist_name: ident, $test_name: ident, $expected: expr ) => {
+ #[test]
+ fn $test_name() {
+ use crate::wordlists::$wordlist_name;
+ use rand::prelude::SeedableRng;
+ use rand::prelude::StdRng;
+
+ fn make_vektor<'a>() -> Vec<&'a str> {
+ let seed: [u8; 32] = [0; 32];
+ let mut rng: StdRng = SeedableRng::from_seed(seed);
+
+ let mut vector: Vec<&str> = vec![];
+ for _ in 0..4 {
+ let word: &str = $wordlist_name.choose(&mut rng).unwrap();
+ vector.push(word);
+ }
+ vector
+ }
+ let wanted: Vec<&str> = $expected.into_iter().collect();
+
+ let got = make_vektor();
+
+ assert_eq!(got, wanted);
+ }
+ };
+}
+
+create_test!(
+ BEALE_WORDLIST,
+ beale_rng_test,
+ vec!["io", "gavel", "beam", "time"]
+);
+
+create_test!(
+ REINHOLD_WORDLIST,
+ reinhold_rng_test,
+ vec!["india", "gamma", "bcd", "theme"]
+);
+
+create_test!(
+ MINILOCK_WORDLIST,
+ minilock_rng_test,
+ vec!["hoed", "femininity", "bedsit", "stabbings"]
+);
+
+create_test!(
+ EFF_LONG_WORDLIST,
+ eff_long_rng_test,
+ vec!["helpless", "fever", "blooming", "sublease"]
+);
+create_test!(
+ EFF_SHORT_WORDLIST_1,
+ eff_short_1_rng_test,
+ vec!["five", "boat", "shape", "bony"]
+);
+create_test!(
+ EFF_SHORT_WORDLIST_2_0,
+ eff_short_2_0_rng_test,
+ vec!["family", "aseptic", "renovator", "atlas"]
+);
diff --git a/tests/tests.rs b/tests/tests.rs
@@ -1,70 +0,0 @@
-extern crate rand;
-
-use rand::rngs::StdRng;
-use rand::seq::SliceRandom;
-use rand::SeedableRng;
-
-use diceware::wordlists::BEALE_WORDLIST;
-use diceware::wordlists::EFF_LONG_WORDLIST;
-use diceware::wordlists::EFF_SHORT_WORDLIST_1;
-use diceware::wordlists::EFF_SHORT_WORDLIST_2_0;
-use diceware::wordlists::MINILOCK_WORDLIST;
-use diceware::wordlists::REINHOLD_WORDLIST;
-
-macro_rules! create_test {
- ( $wordlist_name: path, $test_name: ident, $expected: expr ) => {
- #[test]
- fn $test_name() {
- fn make_vektor<'a>() -> Vec<&'a str> {
- let seed: [u8; 32] = [0; 32];
- let mut rng: StdRng = SeedableRng::from_seed(seed);
-
- let mut vector: Vec<&str> = vec![];
- for _ in 0..4 {
- let word: &str = $wordlist_name.choose(&mut rng).unwrap();
- vector.push(word);
- }
- vector
- }
- let wanted: Vec<&str> = $expected.into_iter().collect();
-
- let got = make_vektor();
-
- assert_eq!(got, wanted);
- }
- };
-}
-
-create_test!(
- BEALE_WORDLIST,
- beale_rng_test,
- vec!["io", "gavel", "beam", "time"]
-);
-
-create_test!(
- REINHOLD_WORDLIST,
- reinhold_rng_test,
- vec!["india", "gamma", "bcd", "theme"]
-);
-
-create_test!(
- MINILOCK_WORDLIST,
- minilock_rng_test,
- vec!["hoed", "femininity", "bedsit", "stabbings"]
-);
-
-create_test!(
- EFF_LONG_WORDLIST,
- eff_long_rng_test,
- vec!["helpless", "fever", "blooming", "sublease"]
-);
-create_test!(
- EFF_SHORT_WORDLIST_1,
- eff_short_1_rng_test,
- vec!["five", "boat", "shape", "bony"]
-);
-create_test!(
- EFF_SHORT_WORDLIST_2_0,
- eff_short_2_0_rng_test,
- vec!["family", "aseptic", "renovator", "atlas"]
-);