Fixing phrases generated on windows (#3614)

This commit is contained in:
Tomasz Drwięga 2016-11-25 12:59:15 +01:00 committed by Arkadiy Paronyan
parent 686978fa97
commit 0e2cd1d080

View File

@ -47,7 +47,7 @@ impl Random for [u8; 32] {
pub fn random_phrase(words: usize) -> String { pub fn random_phrase(words: usize) -> String {
lazy_static! { lazy_static! {
static ref WORDS: Vec<String> = String::from_utf8_lossy(include_bytes!("../res/wordlist.txt")) static ref WORDS: Vec<String> = String::from_utf8_lossy(include_bytes!("../res/wordlist.txt"))
.split("\n") .lines()
.map(|s| s.to_owned()) .map(|s| s.to_owned())
.collect(); .collect();
} }
@ -55,8 +55,19 @@ pub fn random_phrase(words: usize) -> String {
(0..words).map(|_| rng.choose(&WORDS).unwrap()).join(" ") (0..words).map(|_| rng.choose(&WORDS).unwrap()).join(" ")
} }
#[test] #[cfg(test)]
fn should_produce_right_number_of_words() { mod tests {
let p = random_phrase(10); use super::random_phrase;
assert_eq!(p.split(" ").count(), 10);
} #[test]
fn should_produce_right_number_of_words() {
let p = random_phrase(10);
assert_eq!(p.split(" ").count(), 10);
}
#[test]
fn should_not_include_carriage_return() {
let p = random_phrase(10);
assert!(!p.contains('\r'), "Carriage return should be trimmed.");
}
}