rusty-diceware

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit a492e5e63d172c464f2957a9e32751ffc82f33b2
parent f89aeae2b26aa16aae6f55f5391648ae25855b33
Author: Yuval Langer <yuvallangerontheroad@gmail.com>
Date:   Thu, 20 Oct 2022 20:56:51 +0300

Add tests, bump diceware_wordlists version, update lock file, and add to the CHANGELOG.

Diffstat:
MCargo.lock | 2+-
Mdiceware_wordlists/CHANGELOG.md | 4++++
Mdiceware_wordlists/Cargo.toml | 2+-
Mdiceware_wordlists/src/lib.rs | 198+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 204 insertions(+), 2 deletions(-)

diff --git a/Cargo.lock b/Cargo.lock @@ -19,7 +19,7 @@ dependencies = [ [[package]] name = "diceware_wordlists" -version = "1.0.0" +version = "1.1.0" dependencies = [ "serde", ] diff --git a/diceware_wordlists/CHANGELOG.md b/diceware_wordlists/CHANGELOG.md @@ -1,3 +1,7 @@ +## v1.1.0 + +Add tests. + ## v1.0.0 No change, just bumping due to a fairly stable looking API. diff --git a/diceware_wordlists/Cargo.toml b/diceware_wordlists/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "diceware_wordlists" -version = "1.0.0" +version = "1.1.0" authors = ["Yuval Langer <yuvallangerontheroad@gmail.com>"] license = "MIT OR Apache-2.0" repository = "https://gitlab.com/yuvallanger/rusty-diceware" diff --git a/diceware_wordlists/src/lib.rs b/diceware_wordlists/src/lib.rs @@ -47,3 +47,201 @@ impl Default for Wordlist { Self::EffLong } } + +macro_rules! create_test { + ( + $wordlist_name: ident, + $test_name: ident, + $expected_indices: expr, + $expected_values: expr, + ) => { + #[test] + fn $test_name() { + use crate::$wordlist_name; + + let wanted: Vec<&str> = $expected_values.into_iter().collect(); + + let got: Vec<&str> = $expected_indices + .into_iter() + .map(|i| $wordlist_name[i]) + .collect(); + + assert_eq!(got, wanted); + } + }; +} + +create_test!( + BEALE_WORDLIST, + beale_test, + vec![ + 0, + BEALE_WORDLIST.len() - 1, + 490, + 811, + 970, + 1187, + 1726, + 2158, + 2492, + 3005, + 3713, + 4143, + 4289, + ], + vec![ + "a", "@", "balls", "boor", "bunts", "cherub", "dime", "ezra", "fuzzy", "hire", "leeway", + "mills", "ms", + ], +); + +create_test!( + REINHOLD_WORDLIST, + reinhold_test, + vec![ + 0, + REINHOLD_WORDLIST.len() - 1, + 490, + 811, + 970, + 1187, + 1726, + 2158, + 2492, + 3005, + 3713, + 4143, + 4289, + ], + vec![ + "a", "@", "balk", "bony", "bum", "charm", "dice", "excess", "fuchs", "hg", "le", "mercy", + "morsel", + ], +); + +create_test!( + MINILOCK_WORDLIST, + minilock_test, + vec![ + 0, + MINILOCK_WORDLIST.len() - 1, + 7625, + 9287, + 18137, + 26351, + 27726, + 32096, + 37667, + 38151, + 46685, + 47351, + 52997, + ], + vec![ + "aardvark", + "zulus", + "censer", + "colonels", + "exonerate", + "infringe", + "jaunts", + "miserliness", + "platitudes", + "pontoon", + "skua", + "snuggles", + "tributes", + ], +); + +create_test!( + EFF_LONG_WORDLIST, + eff_long_test, + vec![ + 0, + EFF_LONG_WORDLIST.len() - 1, + 490, + 811, + 970, + 1187, + 1726, + 2158, + 2492, + 3005, + 3713, + 4143, + 4289, + ], + vec![ + "abacus", + "zoom", + "barbecue", + "candle", + "charbroil", + "commodity", + "deserving", + "eleven", + "fame", + "grew", + "limpness", + "nifty", + "outer", + ], +); +create_test!( + EFF_SHORT_WORDLIST_1, + eff_short_1_test, + vec![ + 0, + EFF_SHORT_WORDLIST_1.len() - 1, + 201, + 250, + 371, + 400, + 565, + 606, + 826, + 890, + 909, + 922, + 966, + ], + vec![ + "acid", "zoom", "clerk", "crook", "elbow", "faced", "hut", "kilt", "putt", "rover", + "sandy", "scary", "shove", + ], +); +create_test!( + EFF_SHORT_WORDLIST_2_0, + eff_short_2_0_test, + vec![ + 0, + EFF_SHORT_WORDLIST_2_0.len() - 1, + 201, + 250, + 371, + 400, + 565, + 606, + 826, + 890, + 909, + 922, + 966, + ], + vec![ + "aardvark", + "zucchini", + "circle", + "cytoplasm", + "enforcer", + "etiquette", + "hybrid", + "jamboree", + "omnivorous", + "plywood", + "pry", + "puzzle", + "riches", + ], +);