From a56df30933fe622dd90718fb702782e7c1c4ee9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Fri, 25 Nov 2016 12:15:08 +0100 Subject: [PATCH] Fixing phrases generated on windows --- ethstore/src/random.rs | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/ethstore/src/random.rs b/ethstore/src/random.rs index 1d050e4221f..954ec500f98 100644 --- a/ethstore/src/random.rs +++ b/ethstore/src/random.rs @@ -47,7 +47,7 @@ impl Random for [u8; 32] { pub fn random_phrase(words: usize) -> String { lazy_static! { static ref WORDS: Vec = String::from_utf8_lossy(include_bytes!("../res/wordlist.txt")) - .split("\n") + .lines() .map(|s| s.to_owned()) .collect(); } @@ -55,8 +55,19 @@ pub fn random_phrase(words: usize) -> String { (0..words).map(|_| rng.choose(&WORDS).unwrap()).join(" ") } -#[test] -fn should_produce_right_number_of_words() { - let p = random_phrase(10); - assert_eq!(p.split(" ").count(), 10); -} \ No newline at end of file +#[cfg(test)] +mod tests { + use super::random_phrase; + + #[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."); + } +}