aboutsummaryrefslogtreecommitdiff
path: root/src/util/serialization.rs
blob: 189a41acf3781c3a7ac9d1bb8b5ce0571f80f18a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
pub fn line_to_words(line: &str) -> Vec<String> {
    line.split('|')
        .map(|w| w.trim().to_string())
        .filter(|w| !w.is_empty())
        .collect()
}

pub fn words_to_line(words: &[String]) -> String {
    words.join(" | ")
}

#[cfg(test)]
mod tests {

    use super::*;

    #[test]
    fn test_line_to_words() {
        assert_eq!(line_to_words("a"), vec!("a"));
        assert_eq!(line_to_words("a | b | c"), vec!("a", "b", "c"));
    }

    #[test]
    fn test_words_to_line() {
        assert_eq!(words_to_line(&["a".to_string()]), "a");
        assert_eq!(words_to_line(&["a".to_string(), "b".to_string(), "c".to_string()]), "a | b | c");
    }
}