1pub fn normalize_mnemonic(input: &str) -> String {
18 input
19 .split(|c: char| c.is_whitespace() || c == ',')
20 .filter(|part| !part.is_empty())
21 .collect::<Vec<_>>()
22 .join(" ")
23}
24
25#[cfg(test)]
26mod tests {
27 use super::*;
28
29 #[test]
30 fn test_normalize_mnemonic_spaces() {
31 let input = "word1 word2 word3";
32 assert_eq!(normalize_mnemonic(input), "word1 word2 word3");
33 }
34
35 #[test]
36 fn test_normalize_mnemonic_commas() {
37 let input = "word1,word2,word3";
38 assert_eq!(normalize_mnemonic(input), "word1 word2 word3");
39 }
40
41 #[test]
42 fn test_normalize_mnemonic_mixed() {
43 let input = "word1, word2 word3\tword4";
44 assert_eq!(normalize_mnemonic(input), "word1 word2 word3 word4");
45 }
46
47 #[test]
48 fn test_normalize_mnemonic_already_normalized() {
49 let input = "word1 word2 word3";
50 assert_eq!(normalize_mnemonic(input), "word1 word2 word3");
51 }
52}