pub fn normalize_mnemonic(input: &str) -> String {
input
.split(|c: char| c.is_whitespace() || c == ',')
.filter(|part| !part.is_empty())
.collect::<Vec<_>>()
.join(" ")
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_normalize_mnemonic_spaces() {
let input = "word1 word2 word3";
assert_eq!(normalize_mnemonic(input), "word1 word2 word3");
}
#[test]
fn test_normalize_mnemonic_commas() {
let input = "word1,word2,word3";
assert_eq!(normalize_mnemonic(input), "word1 word2 word3");
}
#[test]
fn test_normalize_mnemonic_mixed() {
let input = "word1, word2 word3\tword4";
assert_eq!(normalize_mnemonic(input), "word1 word2 word3 word4");
}
#[test]
fn test_normalize_mnemonic_already_normalized() {
let input = "word1 word2 word3";
assert_eq!(normalize_mnemonic(input), "word1 word2 word3");
}
}